use of net.n3.nanoxml.IXMLParser in project freeplane by freeplane.
the class ScriptingRegistration method registerScriptAddOns.
private void registerScriptAddOns() {
File[] addonXmlFiles = AddOnsController.getController().getAddOnsDir().listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".script.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);
final ScriptAddOnProperties addOn = new ScriptAddOnProperties((XMLElement) parser.parse());
addOn.setAddOnPropertiesFile(file);
AddOnsController.getController().registerInstalledAddOn(addOn);
} catch (final Exception e) {
LogUtils.warn("error parsing " + file, e);
} finally {
FileUtils.silentlyClose(inputStream);
}
}
}
use of net.n3.nanoxml.IXMLParser in project freeplane by freeplane.
the class XMLLocalParserFactory method createLocalXMLParser.
public static IXMLParser createLocalXMLParser() {
IXMLParser parser = org.freeplane.n3.nanoxml.XMLParserFactory.createDefaultXMLParser();
parser.setResolver(new LocalEntityResolver());
return parser;
}
use of net.n3.nanoxml.IXMLParser in project jwt by emweb.
the class WStdLocalizedStrings method checkForValidXml.
private String checkForValidXml(String s) {
/* FIXME, we should do this only once for every key ... */
if (containsXML) {
try {
IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
IXMLReader reader = StdXMLReader.stringReader("<span>" + s + "</span>");
parser.setReader(reader);
parser.parse();
return s;
} catch (Exception e) {
throw new RuntimeException("WStdLocalizedStrings: no valid xml: \"" + s + "\"");
}
} else
return s;
}
use of net.n3.nanoxml.IXMLParser 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.IXMLParser in project jwt by emweb.
the class XmlMessageParserTest method readXml.
public Result readXml(InputStream stream) throws Exception {
XmlMessageParser xmlParser = new XmlMessageParser();
IXMLParser parser = XMLParserFactory.createDefaultXMLParser();
parser.setBuilder(xmlParser);
parser.setResolver(xmlParser);
IXMLReader reader = new StdXMLReader(stream);
parser.setReader(reader);
parser.parse();
Result result = new Result();
result.map.putAll(xmlParser.getKeyValues());
result.pluralCount = xmlParser.getPluralCount();
result.pluralExpression = xmlParser.getPluralExpression();
return result;
}
Aggregations