use of net.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();
}
}
use of net.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) {
logger.error("ClassNotFoundException", e);
} catch (InstantiationException e) {
logger.error("InstantiationException", e);
} catch (IllegalAccessException e) {
logger.error("IllegalAccessException", e);
} catch (XMLException e) {
logger.error("Error reading XHTML string: " + e.getMessage() + ": line " + e.getLineNr() + " in '" + text + "'", e);
}
return false;
}
use of net.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) {
LogUtils.severe(ex);
} finally {
FileUtils.silentlyClose(urlStreamReader);
}
UITools.errorMessage(TextUtils.format("url_open_error", url.toString()));
return false;
}
use of net.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.toXhtml() + "</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) {
logger.error("ClassNotFoundException", e);
} catch (InstantiationException e) {
logger.error("InstantiationException", e);
} catch (IllegalAccessException e) {
logger.error("IllegalAccessException", e);
} catch (XMLException e) {
logger.error("Error reading XHTML string: " + e.getMessage());
}
return wText;
}
use of net.n3.nanoxml.XMLException 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;
}
Aggregations