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

Java Entities类代码示例

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

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



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

示例1: supplyOutputSettings

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Test public void supplyOutputSettings() {
    // test that one can override the default document output settings
    Document.OutputSettings os = new Document.OutputSettings();
    os.prettyPrint(false);
    os.escapeMode(Entities.EscapeMode.extended);
    os.charset("ascii");

    String html = "<div><p>&bernou;</p></div>";
    String customOut = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed(), os);
    String defaultOut = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed());
    assertNotSame(defaultOut, customOut);

    assertEquals("<div><p>&bernou;</p></div>", customOut);
    assertEquals("<div>\n" +
        " <p>ℬ</p>\n" +
        "</div>", defaultOut);

    os.charset("ASCII");
    os.escapeMode(Entities.EscapeMode.base);
    String customOut2 = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed(), os);
    assertEquals("<div><p>&#x212c;</p></div>", customOut2);
}
 
开发者ID:cpusoft,项目名称:common,代码行数:23,代码来源:CleanerTest.java


示例2: assertSpecification

import org.jsoup.nodes.Entities; //导入依赖的package包/类
private void assertSpecification( String expectedSpec, Document actualDoc)
  {
      assertNotNull( actualDoc );
      StringWriter buffer = new StringWriter();
      actualDoc.print( new PrintWriter( buffer ) );

org.jsoup.nodes.Document expectedDoc = Jsoup.parse(expectedSpec);
expectedDoc.outputSettings().escapeMode(Entities.EscapeMode.xhtml).prettyPrint(false);

Element expected = expectedDoc.body();

org.jsoup.nodes.Document resultDoc = Jsoup.parse(buffer.toString());
Element result = resultDoc.body();
result.select("style:first-of-type").remove();
resultDoc.outputSettings().escapeMode(Entities.EscapeMode.xhtml).prettyPrint(false);

assertEquals( expected.outerHtml(), result.outerHtml() );
  }
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:19,代码来源:GreenPepperRepositoryTest.java


示例3: assertSpecification

import org.jsoup.nodes.Entities; //导入依赖的package包/类
private void assertSpecification( Document doc )
{
    assertNotNull( doc );
    StringWriter buffer = new StringWriter();
    doc.print( new PrintWriter( buffer ) );
    org.jsoup.nodes.Document expectedDoc = Jsoup.parse(specification());
    expectedDoc.outputSettings().escapeMode(Entities.EscapeMode.xhtml).prettyPrint(false);

    Element expected = expectedDoc.body();

    org.jsoup.nodes.Document resultDoc = Jsoup.parse(buffer.toString());
    Element result = resultDoc.body();
    result.select("style:first-of-type").remove();
    resultDoc.outputSettings().escapeMode(Entities.EscapeMode.xhtml).prettyPrint(false);

    Assert.assertEquals( expected.outerHtml(), result.outerHtml() );
}
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:18,代码来源:AtlassianRepositoryTest.java


示例4: supplyOutputSettings

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Test public void supplyOutputSettings() {
    // test that one can override the default document output settings
    Document.OutputSettings os = new Document.OutputSettings();
    os.prettyPrint(false);
    os.escapeMode(Entities.EscapeMode.extended);
    os.charset("ascii");

    String html = "<div><p>&bernou;</p></div>";
    String customOut = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed(), os);
    String defaultOut = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed());
    assertNotSame(defaultOut, customOut);

    assertEquals("<div><p>&Bscr;</p></div>", customOut); // entities now prefers shorted names if aliased
    assertEquals("<div>\n" +
        " <p>ℬ</p>\n" +
        "</div>", defaultOut);

    os.charset("ASCII");
    os.escapeMode(Entities.EscapeMode.base);
    String customOut2 = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed(), os);
    assertEquals("<div><p>&#x212c;</p></div>", customOut2);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:CleanerTest.java


示例5: parsing

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Override
public String parsing() {
    String output="";

    try {
        Document doc=Jsoup.connect(super.getURL()).get();
        Elements lyr=doc.select("p.text");
        doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
        try {
            output=lyr.first().html();
        } catch(NullPointerException npe) { System.err.println(npe);}
        output=Library.replacing(output);
    } catch(IOException ioe) { System.err.println(ioe); }
    
    if(output.isEmpty()) { output+="Error: There are no lyrics for this artist and song in the database."; }
    return output;
}
 
开发者ID:hermajan,项目名称:lyrics,代码行数:18,代码来源:KaraokeTexty.java


示例6: parsing

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Override
 public String parsing() {
     String output="";
     try {
         Document doc=Jsoup.connect(super.getURL()).get();
         doc.select(".rtMatcher").remove(); doc.select(".lyricsBreak").remove(); 
doc.select("script").remove(); Library.removeComments(doc);
         Elements lyr=doc.select(".lyricbox");
         doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
         output=lyr.html();
         output=Library.replacing(output);
     } catch(IOException ioe) { System.err.println(ioe); }
     
     if(output.contains("<span") && output.contains("title=\"Instrumental\"")) {
         output="This is an instrumental song with no lyrics.";
     }
     if(output.isEmpty()) { output+="Error: There are no lyrics for this artist and song in the database."; }
     return output;
 }
 
开发者ID:hermajan,项目名称:lyrics,代码行数:20,代码来源:LyricWiki.java


示例7: supplyOutputSettings

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Test public void supplyOutputSettings() {
    // test that one can override the default document output settings
    Document.OutputSettings os = new Document.OutputSettings();
    os.prettyPrint(false);
    os.escapeMode(Entities.EscapeMode.extended);

    String html = "<div><p>&bernou;</p></div>";
    String customOut = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed(), os);
    String defaultOut = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed());
    assertNotSame(defaultOut, customOut);

    assertEquals("<div><p>&bernou;</p></div>", customOut);
    assertEquals("<div>\n" +
        " <p>ℬ</p>\n" +
        "</div>", defaultOut);

    os.charset("ASCII");
    os.escapeMode(Entities.EscapeMode.base);
    String customOut2 = Jsoup.clean(html, "http://foo.com/", Whitelist.relaxed(), os);
    assertEquals("<div><p>&#x212c;</p></div>", customOut2);
}
 
开发者ID:code4craft,项目名称:jsoup-learning,代码行数:22,代码来源:CleanerTest.java


示例8: getText

import org.jsoup.nodes.Entities; //导入依赖的package包/类
protected <T extends XmlObject> String getText(T att) {
    if(att == null) return "";

    Document doc = Jsoup.parse(att.xmlText());
    doc.outputSettings().syntax(Document.OutputSettings.Syntax.html);
    doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);

    List<Node> childNodes = doc.body().childNodes();

    if ( childNodes.size() == 1 && "#text".equals(childNodes.get(0).nodeName())) {
        // only text, parse as plaintext.
        XmlCursor cursor = att.newCursor();
        String value = cursor.getTextValue();
        cursor.dispose();
        return value == null ? "" : value;
    } else {
        StringBuilder sb = new StringBuilder();
        for (Node child : childNodes) {
            child.traverse(new DDIReadNodeVisitor());
            child.html(sb);
        }
        return sb.toString();
    }
}
 
开发者ID:Tietoarkisto,项目名称:metka,代码行数:25,代码来源:DDIReadSectionBase.java


示例9: handle

import org.jsoup.nodes.Entities; //导入依赖的package包/类
public static WordprocessingMLPackage handle(WordprocessingMLPackage wmlPackage, Document doc,boolean fragment,boolean altChunk) throws IOException, Docx4JException {
	//设置转换模式
	doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml);  //转为 xhtml 格式
	
	if(altChunk){
		//Document对象
		MainDocumentPart document = wmlPackage.getMainDocumentPart();
		//获取Jsoup参数
		String charsetName = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_JSOUP_PARSE_CHARSETNAME, Docx4jConstants.DEFAULT_CHARSETNAME );
		//设置转换模式
		doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml);  //转为 xhtml 格式
		//创建html导入对象
		//XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);
		document.addAltChunk(AltChunkType.Xhtml, (fragment ? doc.body().html() : doc.html()) .getBytes(Charset.forName(charsetName)));
		//document.addAltChunk(type, bytes, attachmentPoint)
		//document.addAltChunk(type, is)
		//document.addAltChunk(type, is, attachmentPoint)
		WordprocessingMLPackage tempPackage = document.convertAltChunks();
		
		//返回处理后的WordprocessingMLPackage对象
		return tempPackage;
	}
	
	//创建html导入对象
	XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wmlPackage);
	//将xhtml转换为wmlPackage可用的对象
	List<Object> list = xhtmlImporter.convert((fragment ? doc.body().html() : doc.html()), doc.baseUri());
	//导入转换后的内容对象
	wmlPackage.getMainDocumentPart().getContent().addAll(list);
	//返回原WordprocessingMLPackage对象
	return wmlPackage;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:33,代码来源:XHTMLImporterUtils.java


示例10: url2xhtml

import org.jsoup.nodes.Entities; //导入依赖的package包/类
/**
 * 将页面转为{@link org.jsoup.nodes.Document}对象,xhtml 格式
 *
 * @param url
 * @return
 * @throws Exception
 */
protected Document url2xhtml(String url) throws Exception {
    Document doc = Jsoup.connect(url).get(); //获得

    if (logger.isDebugEnabled()) {
        logger.debug("baseUri: {}", doc.baseUri());
    }

    for (Element script : doc.getElementsByTag("script")) { //除去所有 script
        script.remove();
    }

    for (Element a : doc.getElementsByTag("a")) { //除去 a 的 onclick,href 属性
        a.removeAttr("onclick");
        a.removeAttr("href");
    }

    Elements links = doc.getElementsByTag("link"); //将link中的地址替换为绝对地址
    for (Element element : links) {
        String href = element.absUrl("href");

        if (logger.isDebugEnabled()) {
            logger.debug("href: {} -> {}", element.attr("href"), href);
        }

        element.attr("href", href);
    }

    doc.outputSettings()
            .syntax(Document.OutputSettings.Syntax.xml)
            .escapeMode(Entities.EscapeMode.xhtml);  //转为 xhtml 格式

    if (logger.isDebugEnabled()) {
        String[] split = doc.html().split("\n");
        for (int c = 0; c < split.length; c++) {
            logger.debug("line {}:\t{}", c + 1, split[c]);
        }
    }
    return doc;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:47,代码来源:HtmlConverter.java


示例11: convertToWmlObject

import org.jsoup.nodes.Entities; //导入依赖的package包/类
private static List<Object> convertToWmlObject(
		WordprocessingMLPackage wordMLPackage, String content)
		throws Docx4JException, JAXBException {
	MainDocumentPart document = wordMLPackage.getMainDocumentPart();
	//获取Jsoup参数
	String charsetName = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_CONVERT_OUT_WMLTEMPLATE_CHARSETNAME, Docx4jConstants.DEFAULT_CHARSETNAME );
	
	List<Object> wmlObjList = null;
	String templateString = XmlUtils.marshaltoString(document.getContents().getBody());
	System.out.println(templateString);
	Body templateBody = document.getContents().getBody();
	try {
		document.getContents().setBody(XmlUtils.deepCopy(templateBody));
		document.getContent().clear();
		Document doc = Jsoup.parse(content);
		doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml);
		//XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);
		
		AlternativeFormatInputPart  part = document.addAltChunk(AltChunkType.Xhtml,doc.html().getBytes(Charset.forName(charsetName)));
		
		WordprocessingMLPackage tempPackage = document.convertAltChunks();
		File file = new File("d://temp.docx");
		tempPackage.save(file);
		wmlObjList = document.getContent();
		//part.getOwningRelationshipPart().getSourceP().get
		//wmlObjList = xhtmlImporter.convert(doc.html(), doc.baseUri());
	} finally {
		document.getContents().setBody(templateBody);
	}
	return wmlObjList;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:32,代码来源:HtmlToDOCDemo.java


示例12: disableJsoupHtmlEntityEscape

import org.jsoup.nodes.Entities; //导入依赖的package包/类
private void disableJsoupHtmlEntityEscape() {
    if (DISABLE_HTML_ENTITY_ESCAPE && !INITED) {
        Entities.EscapeMode.base.getMap().clear();
        Entities.EscapeMode.extended.getMap().clear();
        Entities.EscapeMode.xhtml.getMap().clear();
        INITED = true;
    }
}
 
开发者ID:doubleview,项目名称:fastcrawler,代码行数:9,代码来源:HtmlData.java


示例13: formatContent

import org.jsoup.nodes.Entities; //导入依赖的package包/类
/**
 * Method to handle the formatting of the news article's body. In here Jsoup is used to remove
 * the web article header, as well as regex overrides for "-Read-More-" and "-End-" tags, and an
 * override to adjust text size per the users currently set text size.
 *
 * @param html Unformatted HTML String, usually straight from the parser or Volley's cache
 * @return Formatted String, ready to be placed within NewsDetailActivity's WebView, or other
 */
public static String formatContent(String html) {

    Document resultD = Jsoup.parse(html);

    resultD.outputSettings().charset("ASCII");
    resultD.outputSettings().escapeMode(Entities.EscapeMode.extended);
    resultD.outputSettings().prettyPrint(false);

    // Select only the content, removing the web header
    String result = resultD.getElementsByTag("table").last()
            .getElementsByTag("tr").get(1)
            .getElementsByTag("td").get(1)
            .html();

    // Removing the -End- and -Read-More- tags created by fccms.psdr3.org
    result = result.replaceFirst("<div.+-End-.+<\\/div>", "");
    result = result.replaceFirst("<div.+-Read-More-.+<\\/div>", "");

    // Overriding the text size. Hard coded "15" can be changed as the scalar quantity.
    int fontScale = (int) (15 * Resources.getSystem().getConfiguration().fontScale);
    result = result.replaceAll("font-size:\\d+pt;", "font-size:" + fontScale + "px;");

    // Add an extra line to the HTML to make the content pad well at the bottom of the WebView
    result = result.concat("<br>");

    return result;
}
 
开发者ID:Pattonville-App-Development-Team,项目名称:Android-App,代码行数:36,代码来源:NewsArticle.java


示例14: disableJsoupHtmlEntityEscape

import org.jsoup.nodes.Entities; //导入依赖的package包/类
/**
 * Disable jsoup html entity escape. It is a hack way only for jsoup 1.7.2.
 */
private void disableJsoupHtmlEntityEscape() {
	if (DISABLE_HTML_ENTITY_ESCAPE && !INITED) {
		Entities.EscapeMode.base.getMap().clear();
		Entities.EscapeMode.extended.getMap().clear();
		INITED = true;
	}
}
 
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:11,代码来源:Html.java


示例15: stripHtml

import org.jsoup.nodes.Entities; //导入依赖的package包/类
/**
 * Strips HTML tags from a given input String, allows some tags to be retained via a whitelist
 *
 * @param fragment the specified String
 * @param whitelistTags the specified whitelist tags
 *
 * @return cleaned String with allowed tags
 */
public static String stripHtml(String fragment, String... whitelistTags)
{

    // Parse out html tags except those from a given list of whitelist tags
    Document dirty = Jsoup.parseBodyFragment(fragment);

    Whitelist whitelist = new Whitelist();

    for (String whitelistTag : whitelistTags)
    {
        // Get the actual tag name from the whitelist tag
        // this is vulnerable in general to complex tags but will suffice for our simple needs
        whitelistTag = StringUtils.removePattern(whitelistTag, "[^\\{IsAlphabetic}]");

        // Add all specified tags to the whitelist while preserving inline css
        whitelist.addTags(whitelistTag).addAttributes(whitelistTag, "class");
    }

    Cleaner cleaner = new Cleaner(whitelist);
    Document clean = cleaner.clean(dirty);
    // Set character encoding to UTF-8 and make sure no line-breaks are added
    clean.outputSettings().escapeMode(Entities.EscapeMode.base).charset(StandardCharsets.UTF_8).prettyPrint(false);

    // return 'cleaned' html body
    return clean.body().html();
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:35,代码来源:HerdStringUtils.java


示例16: relaxedBaseEntityMatchAndStrictExtendedMatch

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Test public void relaxedBaseEntityMatchAndStrictExtendedMatch() {
    // extended entities need a ; at the end to match, base does not
    String html = "&amp &quot &reg &icy &hopf &icy; &hopf;";
    Document doc = Jsoup.parse(html);
    doc.outputSettings().escapeMode(Entities.EscapeMode.extended).charset("ascii"); // modifies output only to clarify test
    assertEquals("&amp; \" &reg; &amp;icy &amp;hopf &icy; &hopf;", doc.body().html());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:HtmlParserTest.java


示例17: makeURL

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Override
public void makeURL() {
    String query=super.getArtist()+" - "+super.getSong();
    String searchURL="";
    
    try {
        URI uri=new URI("http","www.karaoketexty.cz","/search","q="+super.getSong(),null);
        searchURL=uri.toASCIIString().replace("&","%26");
    } catch(URISyntaxException use) { System.err.println(use); }
    
    try {
        Document doc=Jsoup.connect(searchURL).get();
        Elements links=doc.select("#search > ul.title > li > a");
        doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
        
        for(Element link:links) {
            String resultText=Library.replacing(link.text());
            if(resultText.equalsIgnoreCase(query)) {
                super.setURL("http://www.karaoketexty.cz"+link.attr("href"));
                return;
            }
            else if(resultText.contains(query)) {
                super.setURL("http://www.karaoketexty.cz"+link.attr("href"));
                return;
            }
        }
        super.setURL("http://www.karaoketexty.cz/search?q="+query);
    } catch(IOException ioe) { System.err.println(ioe); }
}
 
开发者ID:hermajan,项目名称:lyrics,代码行数:30,代码来源:KaraokeTexty.java


示例18: parsing

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Override
public String parsing() {
    String output="";
    try {
        Document doc=Jsoup.connect(super.getURL()).get();
        Elements lyr=doc.select("#lyrics-body-text");
        doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
        output=lyr.html().replace("<p class=\"verse\">","");
        output=output.replace("</p>","<br/><br/>");
        output=Library.replacing(output);
    } catch(IOException ioe) { System.err.println(ioe); }
    
    if(output.isEmpty()) { output+="Error: There are no lyrics for this artist and song in the database."; }
    return output;
}
 
开发者ID:hermajan,项目名称:lyrics,代码行数:16,代码来源:MetroLyrics.java


示例19: obtainInformation

import org.jsoup.nodes.Entities; //导入依赖的package包/类
/**
   * Obtains information.
* @param method Method which is needed to call.
* @param info Information which is needed to obtain.
   * @return Information.
   */
  public String obtainInformation(String method,String info) {
      String url=createAPIrequestURL(method);
      String output="";
      try {
          Document doc=Jsoup.connect(url).get();
          Elements lyr=doc.select(info);
          doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
          output=lyr.first().html();
          output=Library.replacing(output);
      } catch(IOException ioe) { System.err.println(ioe); }
      
      return output;
  }
 
开发者ID:hermajan,项目名称:lyrics,代码行数:20,代码来源:Lastfm.java


示例20: body

import org.jsoup.nodes.Entities; //导入依赖的package包/类
@Override
public String body() {
    final Document html = Jsoup.parse(super.body());
    html.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
    html.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
    return html.html();
}
 
开发者ID:jcabi,项目名称:jcabi-http,代码行数:8,代码来源:JsoupResponse.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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