• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Segment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.htmlparser.jericho.Segment的典型用法代码示例。如果您正苦于以下问题:Java Segment类的具体用法?Java Segment怎么用?Java Segment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Segment类属于net.htmlparser.jericho包,在下文中一共展示了Segment类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: compileExpr

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
private TypedPlan compileExpr(Segment segment, Expr expr, GenericClass type) {
    boolean hasErrors = false;
    Compiler compiler = new Compiler(classRepository, classResolver, new TemplateScope());
    TypedPlan result = compiler.compileLambda(expr, type);
    PlanOffsetVisitor offsetVisitor = new PlanOffsetVisitor(segment.getBegin());
    result.getPlan().acceptVisitor(offsetVisitor);
    int offset = segment.getBegin();
    for (Diagnostic diagnostic : compiler.getDiagnostics()) {
        diagnostic = new Diagnostic(offset + diagnostic.getStart(), offset + diagnostic.getEnd(),
                diagnostic.getMessage());
        diagnostics.add(diagnostic);
        hasErrors = true;
    }

    if (hasErrors) {
        return null;
    }
    return result;
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:20,代码来源:Parser.java


示例2: printHTMLPage

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
public void printHTMLPage(Source source)
        throws UnsupportedEncodingException, IOException {
    List<StartTag> list = source.getAllStartTags(HTMLElementName.STYLE);
    Iterator<StartTag> iterator = list.iterator();
    String text = "";
    while (iterator.hasNext()) {
        final StartTag tag = iterator.next();
        final Segment s = new Segment(source, tag.getEnd(), tag
                .getElement().getEndTag().getBegin());
        text += s.toString();
    }
    Vector<ReplaceRight> rights = Style.getStyles(text, styles, counter);

    // генерація сторінки з оновленими стилями.

    list = source.getAllStartTags();
    iterator = list.iterator();
    StartTag startTag = null;
    while (iterator.hasNext()) {
        final StartTag st = iterator.next();
        if (HTMLElementName.BODY.equals(st.getName())) {
            startTag = st;
            break;
        }
    }
    if (startTag == null)
        return;

    final StartTag body = startTag;
    final OutputDocument document = new OutputDocument(source);
    while (iterator.hasNext()) {
        startTag = iterator.next();
        replaceAttrs(startTag, document, rights);
    }

    OutputStreamWriter writer = new OutputStreamWriter(this.out, "UTF-8");
    document.writeTo(writer, body.getEnd(), body.getElement().getEndTag()
            .getBegin());
    writer.flush();
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:41,代码来源:Out.java


示例3: main

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
public static void main(final String[] args) {
    try {
        final FileInputStream is = new FileInputStream("d:/test.html");
        final FileOutputStream o = new FileOutputStream("d:/res1.txt");
        final Source source = new Source(is);
        final List<StartTag> list = source
                .getAllStartTags(HTMLElementName.STYLE);
        final Iterator<StartTag> iterator = list.iterator();
        String text = "";
        final PrintStream out = new PrintStream(o);
        while (iterator.hasNext()) {
            final StartTag tag = iterator.next();
            final Segment s = new Segment(source, tag.getEnd(), tag
                    .getElement().getEndTag().getBegin());
            text += s.toString();
            // out.println(text);
            // out.println("---------------");
        }
        is.close();
        final Vector<Style> styles = new Vector<Style>();
        getStyles(text, styles, createCounter());
        for (int i = 0; i < styles.size(); i++) {
            out.println(styles.get(i));
        }
        o.close();
    } catch (final IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:30,代码来源:Style.java


示例4: findSetter

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
private GenericMethod findSetter(Segment segment, GenericClass cls, String name) {
    String methodName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
    GenericMethod[] candidates = typeNavigator.findMethods(cls, methodName, 1);
    if (candidates.length == 0) {
        diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), "Setter not found for key: "
                + name));
        return null;
    } else if (candidates.length > 1) {
        diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), "Ambiguous key: "  + name));
        return null;
    } else {
        return candidates[0];
    }
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:15,代码来源:Parser.java


示例5: reencodeTextSegment

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
private static void reencodeTextSegment(Source source, OutputDocument outputDocument, int begin, int end, boolean formatWhiteSpace) {
  if (begin>=end) return;
  Segment textSegment=new Segment(source,begin,end);
	String decodedText=CharacterReference.decode(textSegment);
	String encodedText=formatWhiteSpace ? CharacterReference.encodeWithWhiteSpaceFormatting(decodedText) : CharacterReference.encode(decodedText);
   outputDocument.replace(textSegment,encodedText);
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:8,代码来源:HTMLSanitiser.java


示例6: reencodeTextSegment

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
private void reencodeTextSegment(Source source, OutputDocument output, int begin, int end) {
	if (begin >= end)
		return;
	Segment textSegment = new Segment(source, begin, end);
	String decodedText = CharacterReference.decode(textSegment);
	String encodedText = CharacterReference.encode(decodedText);
	output.replace(textSegment, encodedText);
}
 
开发者ID:camaradosdeputadosoficial,项目名称:edemocracia,代码行数:9,代码来源:HtmlStripper.java


示例7: reencodeTextSegment

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
private void reencodeTextSegment(Source source, OutputDocument output,
		int begin, int end) {
	if (begin >= end)
		return;
	Segment textSegment = new Segment(source, begin, end);
	String decodedText = CharacterReference.decode(textSegment);
	String encodedText = CharacterReference.encode(decodedText);
	output.replace(textSegment, encodedText);
}
 
开发者ID:camaradosdeputadosoficial,项目名称:edemocracia,代码行数:10,代码来源:HtmlStripper.java


示例8: htmlToText

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
/**
 * Gets the content from html/text as plain text.
 */
public static synchronized String htmlToText(String html) {
  LOG.info("extractFromHTML ... ");

  // Adds line breaks to keep structure
  html = html.replaceAll("<li>", "<li>, ");
  html = html.replaceAll("</li>", ", </li>");
  html = html.replaceAll("<dd>", "<dd>, ");
  html = html.replaceAll("</dd>", ", </dd>");

  final Source src = new Source(html);
  return new TextExtractor(new Segment(src, src.getBegin(), src.getEnd()))
      .setConvertNonBreakingSpaces(true).toString();
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:17,代码来源:FoxTextUtil.java


示例9: ComponentParser

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
ComponentParser(ClassDescriberRepository classRepository, List<Diagnostic> diagnostics, Segment segment) {
    this.classRepository = classRepository;
    this.diagnostics = diagnostics;
    this.segment = segment;
    this.typeNavigator = new GenericTypeNavigator(classRepository);
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:7,代码来源:ComponentParser.java


示例10: compileSettingsObject

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
private TypedPlan compileSettingsObject(Segment segment, ObjectExpr expr, GenericClass type) {
    boolean hasErrors = false;
    Compiler compiler = new Compiler(classRepository, classResolver, new TemplateScope());

    GenericMethod sam = typeNavigator.findSingleAbstractMethod(type);
    if (sam.getActualParameterTypes().length != 0 || !(sam.getActualReturnType() instanceof GenericClass)) {
        diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), "Wrong target lambda type"));
        return null;
    }

    GenericClass objectType = (GenericClass) sam.getActualReturnType();
    ObjectPlan objectPlan = new ObjectPlan(objectType.getName());
    Set<String> requiredFields = collectRequiredFields(objectType.getName());
    for (ObjectEntry entry : expr.getEntries()) {
        GenericMethod setter = findSetter(segment, objectType, entry.getKey());
        if (setter != null) {
            requiredFields.remove(entry.getKey());
            TypedPlan valuePlan = compiler.compile(entry.getValue(), setter.getActualParameterTypes()[0]);
            ObjectPlanEntry planEntry = new ObjectPlanEntry(setter.getDescriber().getName(),
                    CompilerCommons.methodToDesc(setter.getDescriber()), valuePlan.getPlan());
            objectPlan.getEntries().add(planEntry);
        }
    }

    LambdaPlan plan = new LambdaPlan(objectPlan, type.getName(), sam.getDescriber().getName(),
            CompilerCommons.methodToDesc(sam.getDescriber()), Collections.emptyList());

    TypedPlan result = new TypedPlan(plan, type);

    if (!requiredFields.isEmpty()) {
        diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), "Required field not set: "
                + requiredFields.iterator().next()));
    }

    PlanOffsetVisitor offsetVisitor = new PlanOffsetVisitor(segment.getBegin());
    plan.acceptVisitor(offsetVisitor);
    int offset = segment.getBegin();
    for (Diagnostic diagnostic : compiler.getDiagnostics()) {
        diagnostic = new Diagnostic(offset + diagnostic.getStart(), offset + diagnostic.getEnd(),
                diagnostic.getMessage());
        diagnostics.add(diagnostic);
        hasErrors = true;
    }

    if (hasErrors) {
        return null;
    }
    return result;
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:50,代码来源:Parser.java


示例11: use

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
private void use(Segment segment, String prefix, String packageName) {
    String resourceName = "META-INF/flavour/component-packages/" + packageName;
    try (InputStream input = resourceProvider.openResource(resourceName)) {
        if (input == null) {
            error(segment, "Component package was not found: " + packageName);
            return;
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        List<ElementComponentMetadata> componentList = new ArrayList<>();
        List<AttributeComponentMetadata> attributeComponentList = new ArrayList<>();
        while (true) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }
            line = line.trim();
            if (line.isEmpty() || line.startsWith("#")) {
                continue;
            }
            String className = packageName + "." + line;

            ClassDescriber cls = classRepository.describe(className);
            if (cls == null) {
                error(segment, "Class " + className + " declared by component package was not found");
                continue;
            }

            ComponentParser componentParser = new ComponentParser(classRepository, diagnostics, segment);
            Object componentMetadata = componentParser.parse(cls);
            if (componentMetadata instanceof ElementComponentMetadata) {
                ElementComponentMetadata elemComponentMeta = (ElementComponentMetadata) componentMetadata;
                componentList.add(elemComponentMeta);
            } else if (componentMetadata instanceof AttributeComponentMetadata) {
                AttributeComponentMetadata attrComponentMeta = (AttributeComponentMetadata) componentMetadata;
                attributeComponentList.add(attrComponentMeta);
            }
        }
        avaliableComponents.put(prefix, componentList);
        avaliableAttrComponents.put(prefix, attributeComponentList);
    } catch (IOException e) {
        throw new RuntimeException("IO exception occurred parsing HTML input", e);
    }
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:44,代码来源:Parser.java


示例12: error

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
private void error(Segment segment, String message) {
    diagnostics.add(new Diagnostic(segment.getBegin(), segment.getEnd(), message));
}
 
开发者ID:konsoletyper,项目名称:teavm-flavour,代码行数:4,代码来源:Parser.java


示例13: removeNotAllowedTags

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
/**
    * Serduszko dla Bartka od Kasi <3
    * @param htmlFragment
    * @param docUri
    * @return
    */
   private String removeNotAllowedTags(String htmlFragment, URI docUri) {
       Source source = new Source(htmlFragment);
       OutputDocument outputDocument = new OutputDocument(source);
       List<Element> elements = source.getAllElements();


    for (Element element : elements) {
    	Attributes attrs = element.getAttributes();
    	Map<String, String> attrsUpdate = outputDocument.replace(attrs, true);
    	if (!element.getName().contains("a")) {
			attrsUpdate.clear();
		} else {
    		if (attrsUpdate.get("href")!=null) {
	    		String link = attrsUpdate.get("href");
	    		if (!link.contains("http")) {
		    		URI documentUri = docUri;

		    		URI anchorUri;
					try {
						anchorUri = new URI(link);
						URI result = documentUri.resolve(anchorUri);

						attrsUpdate.put("href",	result.toString());
					} catch (URISyntaxException e) {
						outputDocument.remove(element);
					}
	    		}
    		}
    	}

    	if (NOT_ALLOWED_HTML_TAGS.contains(element.getName())) {
    		Segment content = element.getContent();
    		if (element.getName() == "script"
    				|| element.getName() == "style"
    				|| element.getName() == "form") {
    			outputDocument.remove(content);
    		}
            outputDocument.remove(element.getStartTag());

            if (!element.getStartTag().isSyntacticalEmptyElementTag()) {
                outputDocument.remove(element.getEndTag());
            }
        }
    }

    String out = outputDocument.toString();
    out = out.replaceAll("\\n", "");
    out = out.replaceAll("\\t", "");

    return out;
}
 
开发者ID:BartoszJarocki,项目名称:android-boilerpipe,代码行数:58,代码来源:HtmlArticleExtractor.java


示例14: removeHtml

import net.htmlparser.jericho.Segment; //导入依赖的package包/类
/**
 * Removes all HTML tags/markup present in the source string. Strings with
 * no HTML will be returned unchanged.
 *
 * @param sourceString
 *            The string to strip HTML from.
 * @return A string with all HTML stripped from it.
 * @since 1.0.0
 */
public static String removeHtml(final String sourceString) {
	if (StringUtils.isNotBlank(sourceString)) {
		final TextExtractor extractor = new TextExtractor(
				new Segment(new Source(sourceString), 0, sourceString.length()));
		return extractor.toString();
	}
	return sourceString;
}
 
开发者ID:stevensimmons,项目名称:restalm,代码行数:18,代码来源:ConversionUtils.java



注:本文中的net.htmlparser.jericho.Segment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BsonValueCodecProvider类代码示例发布时间:2022-05-22
下一篇:
Java VisualizationModel类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap