Search in sources :

Example 1 with XMLException

use of org.freeplane.n3.nanoxml.XMLException 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 XMLException

use of org.freeplane.n3.nanoxml.XMLException 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 XMLException

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

the class UrlManager method loadCatchExceptions.

/**
 *@deprecated -- use {@link MapIO#loadCatchExceptions(URL url, MapModel map)}
 */
@Deprecated
public boolean loadCatchExceptions(final URL url, final MapModel map) {
    InputStreamReader urlStreamReader = null;
    try {
        urlStreamReader = load(url, map);
        return true;
    } catch (final XMLException ex) {
        LogUtils.warn(ex);
    } catch (final IOException ex) {
        LogUtils.warn(ex);
    } catch (final RuntimeException ex) {
        try {
            final String urlString = url.toString();
            LogUtils.severe("Can not load url " + urlString, ex);
        } catch (Exception e) {
            LogUtils.severe("Can not load url", ex);
        }
    } finally {
        FileUtils.silentlyClose(urlStreamReader);
    }
    UITools.errorMessage(TextUtils.format("url_open_error", url.toString()));
    return false;
}
Also used : XMLException(org.freeplane.n3.nanoxml.XMLException) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) XMLParseException(org.freeplane.n3.nanoxml.XMLParseException) XMLException(org.freeplane.n3.nanoxml.XMLException) URISyntaxException(java.net.URISyntaxException) HeadlessException(java.awt.HeadlessException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with XMLException

use of org.freeplane.n3.nanoxml.XMLException 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 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.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)

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