Search in sources :

Example 11 with IXMLParser

use of net.n3.nanoxml.IXMLParser 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)

Example 12 with IXMLParser

use of net.n3.nanoxml.IXMLParser in project freeplane by freeplane.

the class WindowConfigurationStorage method unmarschall.

protected XMLElement unmarschall(final String marshalled, final JDialog dialog) {
    if (marshalled != null) {
        final IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
        final IXMLReader xmlReader = new StdXMLReader(new StringReader(marshalled));
        parser.setReader(xmlReader);
        try {
            final XMLElement storage = (XMLElement) parser.parse();
            if (storage != null) {
                x = Integer.parseInt(storage.getAttribute("x", "-1"));
                y = Integer.parseInt(storage.getAttribute("y", "-1"));
                width = Integer.parseInt(storage.getAttribute("width", "-1"));
                height = Integer.parseInt(storage.getAttribute("height", "-1"));
                UITools.setBounds(dialog, x, y, width, height);
                return storage;
            }
        } catch (final NumberFormatException e) {
            LogUtils.severe(e);
        } catch (final XMLException e) {
            LogUtils.severe(e);
        }
    }
    final Frame rootFrame = JOptionPane.getFrameForComponent(dialog);
    final Dimension prefSize = rootFrame.getSize();
    prefSize.width = prefSize.width * 3 / 4;
    prefSize.height = prefSize.height * 3 / 4;
    dialog.setSize(prefSize);
    return null;
}
Also used : XMLException(org.freeplane.n3.nanoxml.XMLException) Frame(java.awt.Frame) IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StringReader(java.io.StringReader) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) Dimension(java.awt.Dimension) XMLElement(org.freeplane.n3.nanoxml.XMLElement)

Example 13 with IXMLParser

use of net.n3.nanoxml.IXMLParser in project freeplane by freeplane.

the class AddOnsController method registerPlugins.

private void registerPlugins() {
    final File addOnsDir = getAddOnsDir();
    // in applets the addOnsDir will be null
    if (addOnsDir == null)
        return;
    File[] addonXmlFiles = addOnsDir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return name.endsWith(".plugin.xml");
        }
    });
    final IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
    for (File file : addonXmlFiles) {
        BufferedInputStream inputStream = null;
        try {
            inputStream = new BufferedInputStream(new FileInputStream(file));
            final IXMLReader reader = new StdXMLReader(inputStream);
            parser.setReader(reader);
            registerInstalledAddOn(new AddOnProperties(AddOnType.PLUGIN, (XMLElement) parser.parse()));
        } catch (final Exception e) {
            LogUtils.warn("error parsing " + file, e);
        } finally {
            FileUtils.silentlyClose(inputStream);
        }
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) BufferedInputStream(java.io.BufferedInputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) XMLElement(org.freeplane.n3.nanoxml.XMLElement) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 14 with IXMLParser

use of net.n3.nanoxml.IXMLParser in project freeplane by freeplane.

the class ScannerController method loadScanners.

void loadScanners() throws Exception {
    final File configXml = new File(pathToFile);
    if (!configXml.exists()) {
        LogUtils.info(pathToFile + " does not exist yet");
        return;
    }
    try {
        final IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
        final IXMLReader reader = new StdXMLReader(new BufferedInputStream(new FileInputStream(configXml)));
        parser.setReader(reader);
        final XMLElement loader = (XMLElement) parser.parse();
        final Vector<XMLElement> scannerElements = loader.getChildren();
        for (XMLElement elem : scannerElements) {
            scanners.add(parseScanner(elem));
        }
        boolean haveDefault = false;
        for (Scanner scanner : scanners) {
            if (scanner.isDefault()) {
                if (haveDefault)
                    LogUtils.warn(configXml + ": multiple scanners are marked as default - fix that!");
                else
                    haveDefault = true;
            }
        }
        if (!haveDefault)
            LogUtils.warn(configXml + ": no scanner is marked as default - fix that!");
    } catch (final IOException e) {
        LogUtils.warn("error parsing " + configXml, e);
    }
}
Also used : IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) BufferedInputStream(java.io.BufferedInputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) IOException(java.io.IOException) XMLElement(org.freeplane.n3.nanoxml.XMLElement) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 15 with IXMLParser

use of net.n3.nanoxml.IXMLParser in project freeplane by freeplane.

the class FormatController method loadFormats.

private void loadFormats() throws Exception {
    BufferedInputStream inputStream = null;
    final File configXml = new File(pathToFile);
    if (!configXml.exists()) {
        LogUtils.info(pathToFile + " does not exist yet");
        return;
    }
    try {
        final IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
        inputStream = new BufferedInputStream(new FileInputStream(configXml));
        final IXMLReader reader = new StdXMLReader(inputStream);
        parser.setReader(reader);
        final XMLElement loader = (XMLElement) parser.parse();
        final Vector<XMLElement> formats = loader.getChildren();
        for (XMLElement elem : formats) {
            final String type = elem.getAttribute("type", null);
            final String style = elem.getAttribute("style", null);
            final String name = elem.getAttribute("name", null);
            final String locale = elem.getAttribute("locale", null);
            final String content = elem.getContent();
            if (StringUtils.isEmpty(type) || StringUtils.isEmpty(style) || StringUtils.isEmpty(content)) {
                throw new RuntimeException("wrong format in " + configXml + ": none of the following must be empty: type=" + type + ", style=" + style + ", element content=" + content);
            } else {
                final PatternFormat format = createFormat(content, style, type, name, (locale == null ? null : new Locale(locale)));
                if (type.equals(IFormattedObject.TYPE_DATE)) {
                    dateFormats.add(format);
                } else if (type.equals(IFormattedObject.TYPE_NUMBER)) {
                    numberFormats.add(format);
                } else if (type.equals(IFormattedObject.TYPE_STRING)) {
                    stringFormats.add(format);
                } else if (type.equals(PatternFormat.TYPE_STANDARD)) {
                // ignore this pattern that crept in in some 1.2 beta version
                } else {
                    throw new RuntimeException("unknown type in " + configXml + ": type=" + type + ", style=" + style + ", element content=" + content);
                }
            }
        }
    } catch (final IOException e) {
        LogUtils.warn("error parsing " + configXml, e);
    } finally {
        FileUtils.silentlyClose(inputStream);
    }
}
Also used : Locale(java.util.Locale) IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) IOException(java.io.IOException) XMLElement(org.freeplane.n3.nanoxml.XMLElement) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) IXMLParser(org.freeplane.n3.nanoxml.IXMLParser) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader) File(java.io.File)

Aggregations

IXMLParser (org.freeplane.n3.nanoxml.IXMLParser)8 IOException (java.io.IOException)7 IXMLParser (net.n3.nanoxml.IXMLParser)7 IXMLReader (net.n3.nanoxml.IXMLReader)7 IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)7 StdXMLReader (org.freeplane.n3.nanoxml.StdXMLReader)7 XMLElement (org.freeplane.n3.nanoxml.XMLElement)6 BufferedInputStream (java.io.BufferedInputStream)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 XMLException (net.n3.nanoxml.XMLException)4 FileNotFoundException (java.io.FileNotFoundException)3 FilenameFilter (java.io.FilenameFilter)2 InputStream (java.io.InputStream)2 StdXMLReader (net.n3.nanoxml.StdXMLReader)2 XHtmlFilter (eu.webtoolkit.jwt.XHtmlFilter)1 Dimension (java.awt.Dimension)1 Frame (java.awt.Frame)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1