Search in sources :

Example 6 with IXMLReader

use of org.freeplane.n3.nanoxml.IXMLReader in project freeplane by freeplane.

the class ExportController method createXSLTExportActions.

private void createXSLTExportActions(final String xmlDescriptorFile) {
    InputStream xmlDescriptorStream = null;
    try {
        final IXMLParser parser = XMLLocalParserFactory.createLocalXMLParser();
        final URL resource = ResourceController.getResourceController().getResource(xmlDescriptorFile);
        xmlDescriptorStream = resource.openStream();
        final IXMLReader reader = new StdXMLReader(xmlDescriptorStream);
        parser.setReader(reader);
        final XMLElement xml = (XMLElement) parser.parse();
        final Enumeration<XMLElement> actionDescriptors = xml.enumerateChildren();
        while (actionDescriptors.hasMoreElements()) {
            final XMLElement descriptor = actionDescriptors.nextElement();
            final String name = descriptor.getAttribute("name", null);
            final XMLElement xmlProperties = descriptor.getFirstChildNamed("properties");
            final Properties properties = xmlProperties.getAttributes();
            final ExportWithXSLT action = new ExportWithXSLT(name, properties);
            addExportEngine(action.getFileFilter(), action);
        }
    } catch (final Exception e) {
        LogUtils.severe(e);
    } finally {
        FileUtils.silentlyClose(xmlDescriptorStream);
    }
}
Also used : IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) InputStream(java.io.InputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) XMLElement(org.freeplane.n3.nanoxml.XMLElement) Properties(java.util.Properties) URL(java.net.URL)

Example 7 with IXMLReader

use of org.freeplane.n3.nanoxml.IXMLReader in project freeplane by freeplane.

the class ScriptingRegistration method registerScriptAddOns.

private void registerScriptAddOns() {
    File[] addonXmlFiles = AddOnsController.getController().getAddOnsDir().listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".script.xml");
        }
    });
    final IXMLParser parser = XMLLocalParserFactory.createLocalXMLParser();
    for (File file : addonXmlFiles) {
        BufferedInputStream inputStream = null;
        try {
            inputStream = new BufferedInputStream(new FileInputStream(file));
            final IXMLReader reader = new StdXMLReader(inputStream);
            parser.setReader(reader);
            final ScriptAddOnProperties addOn = new ScriptAddOnProperties((XMLElement) parser.parse());
            addOn.setAddOnPropertiesFile(file);
            AddOnsController.getController().registerInstalledAddOn(addOn);
        } catch (final Exception e) {
            LogUtils.warn("error parsing " + file, e);
        } finally {
            FileUtils.silentlyClose(inputStream);
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) ScriptAddOnProperties(org.freeplane.plugin.script.addons.ScriptAddOnProperties) IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) BufferedInputStream(java.io.BufferedInputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with IXMLReader

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

the class WStdLocalizedStrings method checkForValidXml.

private String checkForValidXml(String s) {
    /* FIXME, we should do this only once for every key ... */
    if (containsXML) {
        try {
            IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
            IXMLReader reader = StdXMLReader.stringReader("<span>" + s + "</span>");
            parser.setReader(reader);
            parser.parse();
            return s;
        } catch (Exception e) {
            throw new RuntimeException("WStdLocalizedStrings: no valid xml: \"" + s + "\"");
        }
    } else
        return s;
}
Also used : IXMLReader(net.n3.nanoxml.IXMLReader) IXMLParser(net.n3.nanoxml.IXMLParser) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 9 with IXMLReader

use of org.freeplane.n3.nanoxml.IXMLReader 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.getValue() + "</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) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } 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 10 with IXMLReader

use of org.freeplane.n3.nanoxml.IXMLReader 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) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (XMLException e) {
        e.printStackTrace();
    }
    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

IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)9 StdXMLReader (org.freeplane.n3.nanoxml.StdXMLReader)8 IXMLParser (org.freeplane.n3.nanoxml.IXMLParser)7 IOException (java.io.IOException)6 XMLElement (org.freeplane.n3.nanoxml.XMLElement)6 BufferedInputStream (java.io.BufferedInputStream)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 IXMLParser (net.n3.nanoxml.IXMLParser)5 IXMLReader (net.n3.nanoxml.IXMLReader)5 XMLException (net.n3.nanoxml.XMLException)4 FileNotFoundException (java.io.FileNotFoundException)2 FilenameFilter (java.io.FilenameFilter)2 InputStream (java.io.InputStream)2 XHtmlFilter (eu.webtoolkit.jwt.XHtmlFilter)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 AccessControlException (java.security.AccessControlException)1 Locale (java.util.Locale)1 Properties (java.util.Properties)1