Search in sources :

Example 6 with XMLException

use of org.freeplane.n3.nanoxml.XMLException in project jwt by emweb.

the class RefEncoder method EncodeRefs.

static WString EncodeRefs(CharSequence text, EnumSet<RefEncoderOption> options) {
    WString wText = WString.toWString(text);
    try {
        RefEncoder encoder = new RefEncoder(options);
        IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
        parser.setBuilder(encoder);
        parser.setResolver(encoder);
        IXMLReader reader = StdXMLReader.stringReader("<span>" + wText.toXhtml() + "</span>");
        parser.setReader(reader);
        parser.parse();
        String filtered = encoder.result();
        // 6 and 7 correct for respectively <span> and </span>
        return new WString(filtered.substring(6, filtered.length() - 7));
    } catch (ClassNotFoundException e) {
        logger.error("ClassNotFoundException", e);
    } catch (InstantiationException e) {
        logger.error("InstantiationException", e);
    } catch (IllegalAccessException e) {
        logger.error("IllegalAccessException", e);
    } catch (XMLException e) {
        logger.error("Error reading XHTML string: " + e.getMessage());
    }
    return wText;
}
Also used : XMLException(net.n3.nanoxml.XMLException) IXMLReader(net.n3.nanoxml.IXMLReader) IXMLParser(net.n3.nanoxml.IXMLParser)

Example 7 with XMLException

use of org.freeplane.n3.nanoxml.XMLException in project jwt by emweb.

the class RenderUtils method parseXHTML.

// private static void printXmlTree(XMLElement e, int level) {
// for (Object o : e.getChildren()) {
// XMLElement c = ((XMLElement)o);
// for (int i = 0; i < level; ++i)
// System.err.print("\t");
// System.err.print(c.getName() + " : " + c.getContent());
// System.err.print("\n");
// 
// if (c.getChildren().size() > 0)
// printXmlTree(c, level + 1);
// }
// }
static XMLElement parseXHTML(String xhtml) {
    IXMLParser parser;
    try {
        xhtml = "<div>" + xhtml + "</div>";
        parser = XMLParserFactory.createDefaultXMLParser();
        IXMLReader reader = StdXMLReader.stringReader(xhtml);
        parser.setReader(reader);
        parser.setResolver(new XHtmlFilter(true));
        XMLElement xml = (XMLElement) parser.parse();
        extractTextNodes(xml);
        return xml;
    } catch (ClassNotFoundException e) {
        logger.info("Exception while parsing xhtml", e);
        logger.trace("xhtml was: {}", xhtml);
    } catch (InstantiationException e) {
        logger.info("Exception while parsing xhtml", e);
        logger.trace("xhtml was: {}", xhtml);
    } catch (IllegalAccessException e) {
        logger.info("Exception while parsing xhtml", e);
        logger.trace("xhtml was: {}", xhtml);
    } catch (XMLException e) {
        logger.info("Exception while parsing xhtml: {}", e.toString(), e);
        logger.trace("xhtml was: {}", xhtml);
    }
    return null;
}
Also used : XMLException(net.n3.nanoxml.XMLException) IXMLReader(net.n3.nanoxml.IXMLReader) IXMLParser(net.n3.nanoxml.IXMLParser) XMLElement(net.n3.nanoxml.XMLElement) IXMLElement(net.n3.nanoxml.IXMLElement) XHtmlFilter(eu.webtoolkit.jwt.XHtmlFilter)

Aggregations

IXMLParser (net.n3.nanoxml.IXMLParser)4 IXMLReader (net.n3.nanoxml.IXMLReader)4 XMLException (net.n3.nanoxml.XMLException)4 IOException (java.io.IOException)2 IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)2 StdXMLReader (org.freeplane.n3.nanoxml.StdXMLReader)2 XMLException (org.freeplane.n3.nanoxml.XMLException)2 XHtmlFilter (eu.webtoolkit.jwt.XHtmlFilter)1 HeadlessException (java.awt.HeadlessException)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 IXMLElement (net.n3.nanoxml.IXMLElement)1 StdXMLReader (net.n3.nanoxml.StdXMLReader)1 XMLElement (net.n3.nanoxml.XMLElement)1 IXMLParser (org.freeplane.n3.nanoxml.IXMLParser)1 NonValidator (org.freeplane.n3.nanoxml.NonValidator)1