Search in sources :

Example 6 with Parser

use of org.ccil.cowan.tagsoup.Parser in project android_frameworks_base by crdroidandroid.

the class HtmlToSpannedConverter method fromHtml.

/**
     * 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, int flags, ImageGetter imageGetter, TagHandler tagHandler) {
    Parser parser = new Parser();
    try {
        parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
    } catch (org.xml.sax.SAXNotRecognizedException e) {
        // Should not happen.
        throw new RuntimeException(e);
    } catch (org.xml.sax.SAXNotSupportedException e) {
        // Should not happen.
        throw new RuntimeException(e);
    }
    HtmlToSpannedConverter converter = new HtmlToSpannedConverter(source, imageGetter, tagHandler, parser, flags);
    return converter.convert();
}
Also used : Parser(org.ccil.cowan.tagsoup.Parser)

Example 7 with Parser

use of org.ccil.cowan.tagsoup.Parser in project sling by apache.

the class HtmlParserImpl method parse.

/**
     * @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);
        for (String feature : features.keySet()) {
            parser.setProperty(feature, features.get(feature));
        }
        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();
}
Also used : InputSource(org.xml.sax.InputSource) IOException(java.io.IOException) HtmlParser(org.apache.sling.commons.html.HtmlParser) Parser(org.ccil.cowan.tagsoup.Parser) SAXException(org.xml.sax.SAXException)

Example 8 with Parser

use of org.ccil.cowan.tagsoup.Parser in project android_frameworks_base by AOSPA.

the class HtmlToSpannedConverter method fromHtml.

/**
     * Returns displayable styled text from the provided HTML string. Any &lt;img&gt; 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, int flags, ImageGetter imageGetter, TagHandler tagHandler) {
    Parser parser = new Parser();
    try {
        parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
    } catch (org.xml.sax.SAXNotRecognizedException e) {
        // Should not happen.
        throw new RuntimeException(e);
    } catch (org.xml.sax.SAXNotSupportedException e) {
        // Should not happen.
        throw new RuntimeException(e);
    }
    HtmlToSpannedConverter converter = new HtmlToSpannedConverter(source, imageGetter, tagHandler, parser, flags);
    return converter.convert();
}
Also used : Parser(org.ccil.cowan.tagsoup.Parser)

Example 9 with Parser

use of org.ccil.cowan.tagsoup.Parser in project EhViewer by seven332.

the class HtmlToSpannedConverter method fromHtml.

/**
 * Returns displayable styled text from the provided HTML string.
 * Any &lt;img&gt; 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 e) {
        // Should not happen.
        throw new RuntimeException(e);
    } catch (org.xml.sax.SAXNotSupportedException e) {
        // Should not happen.
        throw new RuntimeException(e);
    }
    HtmlToSpannedConverter converter = new HtmlToSpannedConverter(source, imageGetter, tagHandler, parser);
    return converter.convert();
}
Also used : Parser(org.ccil.cowan.tagsoup.Parser)

Example 10 with Parser

use of org.ccil.cowan.tagsoup.Parser in project Android-Rich-text-Editor by chinalwb.

the class HtmlToSpannedConverter method fromHtml.

/**
 * Returns displayable styled text from the provided HTML string. Any &lt;img&gt; 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, int flags, ImageGetter imageGetter, TagHandler tagHandler) {
    Parser parser = new Parser();
    try {
        parser.setProperty(Parser.schemaProperty, HtmlParser.schema);
    } catch (org.xml.sax.SAXNotRecognizedException e) {
        // Should not happen.
        throw new RuntimeException(e);
    } catch (org.xml.sax.SAXNotSupportedException e) {
        // Should not happen.
        throw new RuntimeException(e);
    }
    HtmlToSpannedConverter converter = new HtmlToSpannedConverter(source, imageGetter, tagHandler, parser, flags);
    return converter.convert();
}
Also used : Parser(org.ccil.cowan.tagsoup.Parser)

Aggregations

Parser (org.ccil.cowan.tagsoup.Parser)18 InputSource (org.xml.sax.InputSource)5 IOException (java.io.IOException)4 SAXException (org.xml.sax.SAXException)4 XMLReader (org.xml.sax.XMLReader)4 HtmlParser (org.apache.sling.commons.html.HtmlParser)3 HttpURLConnection (java.net.HttpURLConnection)2 Transformer (javax.xml.transform.Transformer)2 DOMResult (javax.xml.transform.dom.DOMResult)2 SAXSource (javax.xml.transform.sax.SAXSource)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 XPath (javax.xml.xpath.XPath)1