Search in sources :

Example 1 with IXMLReader

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

the class WXmlLocalizedStrings method readXmlResource.

private void readXmlResource(String bundleName) {
    WApplication app = WApplication.getInstance();
    InputStream stream = null;
    for (String path : StringUtils.expandLocales(bundleName, app.getLocale().toString())) {
        try {
            stream = FileUtils.getResourceAsStream(path + ".xml");
        } catch (IOException e) {
        }
        if (stream != null)
            break;
    }
    if (stream == null) {
        logger.warn("Could not find resource \"" + bundleName + "\"");
        return;
    }
    try {
        XmlMessageParser xmlParser = new XmlMessageParser();
        IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
        parser.setBuilder(xmlParser);
        parser.setResolver(xmlParser);
        IXMLReader reader = new StdXMLReader(stream);
        parser.setReader(reader);
        parser.parse();
        keyValues.putAll(xmlParser.getKeyValues());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XMLException e) {
        e.printStackTrace();
    }
}
Also used : XMLException(net.n3.nanoxml.XMLException) IXMLReader(net.n3.nanoxml.IXMLReader) InputStream(java.io.InputStream) IXMLParser(net.n3.nanoxml.IXMLParser) StdXMLReader(net.n3.nanoxml.StdXMLReader) IOException(java.io.IOException)

Example 2 with IXMLReader

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

the class XSSFilter method removeScript.

static boolean removeScript(CharSequence text) {
    try {
        WString wText = WString.toWString(text);
        XSSFilter filter = new XSSFilter();
        IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
        parser.setBuilder(filter);
        parser.setResolver(filter);
        IXMLReader reader = StdXMLReader.stringReader("<span>" + wText.getValue() + "</span>");
        parser.setReader(reader);
        parser.parse();
        String filtered = filter.result();
        // 6 and 7 correct for respectively <span> and </span>
        wText.set(filtered.substring(6, filtered.length() - 7));
        return true;
    } 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() + ": line " + e.getLineNr() + " in '" + text + "'");
    }
    return false;
}
Also used : XMLException(net.n3.nanoxml.XMLException) IXMLReader(net.n3.nanoxml.IXMLReader) IXMLParser(net.n3.nanoxml.IXMLParser)

Example 3 with IXMLReader

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

the class XMLParser method processElementContent.

@Override
protected void processElementContent(final String defaultNamespace, final Properties namespaces, final String fullName, final String name, final String prefix) throws IOException, XMLParseException, Exception {
    if (skipNextElementContent) {
        boolean inComment = false;
        final TreeXmlReader builder = (TreeXmlReader) getBuilder();
        final StringBuilder waitingBuf = new StringBuilder();
        int level = 1;
        for (; ; ) {
            final IXMLReader reader = getReader();
            char ch = reader.read();
            if (inComment) {
                waitingBuf.append(ch);
                if (ch != '-') {
                    continue;
                }
                ch = reader.read();
                waitingBuf.append(ch);
                if (ch != '-') {
                    continue;
                }
                ch = reader.read();
                waitingBuf.append(ch);
                if (ch != '>') {
                    continue;
                }
                inComment = false;
                continue;
            }
            if (ch == '<') {
                ch = reader.read();
                if (ch == '/') {
                    level--;
                    if (level == 0) {
                        break;
                    }
                } else if (ch == '!') {
                    final char read1 = reader.read();
                    final char read2 = reader.read();
                    if (read1 != '-' || read2 != '-') {
                        throw new XMLParseException(reader.getSystemID(), reader.getLineNr(), "Invalid input: <!" + read1 + read2);
                    }
                    inComment = true;
                    waitingBuf.append("<!--");
                    continue;
                } else {
                    level++;
                }
                waitingBuf.append('<');
            } else if (ch == '/') {
                ch = reader.read();
                if (ch == '>') {
                    level--;
                    if (level == 0) {
                        throw new XMLParseException(reader.getSystemID(), reader.getLineNr(), "Invalid input: />");
                    }
                } else if (ch == '<') {
                    waitingBuf.append('/');
                    reader.unread(ch);
                    continue;
                }
                waitingBuf.append('/');
            }
            waitingBuf.append(ch);
        }
        builder.setElementContent(waitingBuf.toString());
        return;
    }
    super.processElementContent(defaultNamespace, namespaces, fullName, name, prefix);
}
Also used : IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) XMLParseException(org.freeplane.n3.nanoxml.XMLParseException)

Example 4 with IXMLReader

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

the class TreeXmlReader method load.

/*
	 * (non-Javadoc)
	 * @see freeplane.persistence.Reader#load()
	 */
public void load(final Reader reader) throws XMLException {
    parser = new XMLParser();
    final IXMLReader nanoxmlReader = new StdXMLReader(reader);
    parser.setReader(nanoxmlReader);
    parser.setBuilder(this);
    parser.setValidator(new NonValidator());
    parser.parse();
}
Also used : NonValidator(org.freeplane.n3.nanoxml.NonValidator) IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) StdXMLReader(org.freeplane.n3.nanoxml.StdXMLReader)

Example 5 with IXMLReader

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

the class FilterController method loadConditions.

void loadConditions(final DefaultComboBoxModel filterConditionModel, final String pathToFilterFile, final boolean showPopupOnError) throws IOException {
    try {
        final IXMLParser parser = XMLLocalParserFactory.createLocalXMLParser();
        File filterFile = new File(pathToFilterFile);
        final IXMLReader reader = new StdXMLReader(new BufferedInputStream(new FileInputStream(filterFile)));
        parser.setReader(reader);
        reader.setSystemID(filterFile.toURL().toString());
        final XMLElement loader = (XMLElement) parser.parse();
        final Vector<XMLElement> conditions = loader.getChildren();
        for (int i = 0; i < conditions.size(); i++) {
            final ASelectableCondition condition = getConditionFactory().loadCondition(conditions.get(i));
            if (condition != null) {
                filterConditionModel.addElement(condition);
            }
        }
    } catch (final FileNotFoundException e) {
    } catch (final AccessControlException e) {
    } catch (final Exception e) {
        LogUtils.warn(e);
        if (showPopupOnError) {
            UITools.errorMessage(TextUtils.getText("filters_not_loaded"));
        }
    }
}
Also used : IXMLReader(org.freeplane.n3.nanoxml.IXMLReader) FileNotFoundException(java.io.FileNotFoundException) AccessControlException(java.security.AccessControlException) XMLElement(org.freeplane.n3.nanoxml.XMLElement) FileInputStream(java.io.FileInputStream) ASelectableCondition(org.freeplane.features.filter.condition.ASelectableCondition) FileNotFoundException(java.io.FileNotFoundException) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) 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 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