Search in sources :

Example 16 with IXMLReader

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

IXMLReader (org.freeplane.n3.nanoxml.IXMLReader)9 StdXMLReader (org.freeplane.n3.nanoxml.StdXMLReader)8 IOException (java.io.IOException)7 IXMLParser (net.n3.nanoxml.IXMLParser)7 IXMLReader (net.n3.nanoxml.IXMLReader)7 IXMLParser (org.freeplane.n3.nanoxml.IXMLParser)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