本文整理汇总了Java中org.ccil.cowan.tagsoup.Parser.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.setProperty方法的具体用法?Java Parser.setProperty怎么用?Java Parser.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ccil.cowan.tagsoup.Parser
的用法示例。
在下文中一共展示了Parser.setProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromHtml
import org.ccil.cowan.tagsoup.Parser; //导入方法依赖的package包/类
/**
* Returns displayable styled text from the provided HTML string. Any <img> tags in the
* HTML will use the specified ImageGetter to request a representation of the image (use null
* if you don't want this) and the specified TagHandler to handle unknown tags (specify null if
* you don't want this).
* <p>
* <p>This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
*/
public static Spanned fromHtml(@NonNull Context context, @NonNull String source, int flags,
@Nullable ImageGetter imageGetter, @Nullable TagHandler tagHandler,
@Nullable SpanCallback spanCallback) {
if (source == null) {
return null;
}
Parser parser = new Parser();
try {
parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
} catch (org.xml.sax.SAXNotRecognizedException | org.xml.sax.SAXNotSupportedException e) {
// Should not happen.
throw new RuntimeException(e);
}
HtmlToSpannedConverter converter =
new HtmlToSpannedConverter(context, source, imageGetter, tagHandler, spanCallback, parser, flags);
return converter.convert();
}
示例2: parse
import org.ccil.cowan.tagsoup.Parser; //导入方法依赖的package包/类
public String parse(String html) {
Parser p = new Parser();
p.setContentHandler(this);
p.setErrorHandler(this);
try {
p.setFeature(Parser.defaultAttributesFeature, false); //or else some default attributes get added to <br>
p.setFeature(Parser.ignorableWhitespaceFeature, false);
p.setProperty(Parser.lexicalHandlerProperty, this);
InputSource inputSource = new InputSource(new StringReader(html));
p.parse(inputSource);
} catch (Exception e) {
// TODO Auto-generated catch block
}
return rebuiltHtml.toString();
}
示例3: fromHtml
import org.ccil.cowan.tagsoup.Parser; //导入方法依赖的package包/类
/**
* Returns displayable styled text from the provided HTML string.
* Any <img> tags in the HTML will use the specified ImageGetter
* to request a representation of the image (use null if you don't
* want this) and the specified TagHandler to handle unknown tags
* (specify null if you don't want this).
*
* <p>This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
*/
public static SpannableStringBuilder fromHtml(String source, ImageGetter imageGetter,
TagHandler tagHandler) {
Parser parser = new Parser();
try {
parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
} catch (org.xml.sax.SAXNotRecognizedException | org.xml.sax.SAXNotSupportedException e) {
// Should not happen.
throw new RuntimeException(e);
}
HtmlToSpannedConverter converter =
new HtmlToSpannedConverter(source, imageGetter, tagHandler,
parser);
return converter.convert();
}
示例4: parse
import org.ccil.cowan.tagsoup.Parser; //导入方法依赖的package包/类
/**
* @see org.apache.sling.commons.html.HtmlParser#parse(java.lang.String, java.io.InputStream, java.lang.String)
*/
public Document parse(String systemId, InputStream stream, String encoding) throws IOException {
final Parser parser = new Parser();
final DOMBuilder builder = new DOMBuilder();
final InputSource source = new InputSource(stream);
source.setEncoding(encoding);
source.setSystemId(systemId);
try {
parser.setProperty("http://xml.org/sax/properties/lexical-handler", builder);
parser.setContentHandler(builder);
parser.parse(source);
} catch (SAXException se) {
if ( se.getCause() instanceof IOException ) {
throw (IOException) se.getCause();
}
throw (IOException) new IOException("Unable to parse xml.").initCause(se);
}
return builder.getDocument();
}
示例5: fromHtml
import org.ccil.cowan.tagsoup.Parser; //导入方法依赖的package包/类
public static Spanned fromHtml(String text, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)
{
Parser parser = new Parser();
try {
parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
} catch (org.xml.sax.SAXNotRecognizedException | SAXNotSupportedException e) {
throw new RuntimeException(e);
}
HtmlToSpannedConverter converter = new HtmlToSpannedConverter(text, imageGetter, tagHandler, parser);
return converter.convert();
}
示例6: fromHtml
import org.ccil.cowan.tagsoup.Parser; //导入方法依赖的package包/类
/**
* Returns displayable styled text from the provided HTML string.
* Any <img> tags in the HTML will use the specified ImageGetter
* to request a representation of the image (use null if you don't
* want this) and the specified TagHandler to handle unknown tags
* (specify null if you don't want this).
*
* <p>This uses TagSoup to handle real HTML, including all of the brokenness found in the wild.
*/
public static Spanned fromHtml(String source, ImageGetter imageGetter) {
Parser parser = new Parser();
try {
parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
} catch (org.xml.sax.SAXNotRecognizedException | org.xml.sax.SAXNotSupportedException e) {
// Should not happen.
throw new RuntimeException(e);
}
HtmlToSpannedConverter converter =
new HtmlToSpannedConverter(source, imageGetter, parser);
return converter.convert();
}