本文整理汇总了Java中org.jsoup.nodes.Entities类的典型用法代码示例。如果您正苦于以下问题:Java Entities类的具体用法?Java Entities怎么用?Java Entities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Entities类属于org.jsoup.nodes包,在下文中一共展示了Entities类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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>ℬ</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>ℬ</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>ℬ</p></div>", customOut2);
}
示例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() );
}
示例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() );
}
示例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>ℬ</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>ℬ</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>ℬ</p></div>", customOut2);
}
示例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;
}
示例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;
}
示例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>ℬ</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>ℬ</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>ℬ</p></div>", customOut2);
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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();
}