List of usage examples for org.jdom2.input.sax SAXHandlerFactory SAXHandlerFactory
SAXHandlerFactory
From source file:com.ardor3d.extension.model.collada.jdom.ColladaImporter.java
License:Open Source License
/** * Reads the whole Collada DOM tree from the given resource and returns its root element. Exceptions may be thrown * by underlying tools; these will be wrapped in a RuntimeException and rethrown. * /* w w w .jav a 2s . c o m*/ * @param resource * the ResourceSource to read the resource from * @return the Collada root element */ private Element readCollada(final ResourceSource resource, final DataCache dataCache) { try { final JDOMFactory jdomFac = new ArdorFactory(dataCache); final SAXBuilder builder = new SAXBuilder(null, new SAXHandlerFactory() { @Override public SAXHandler createSAXHandler(final JDOMFactory factory) { return new SAXHandler(jdomFac) { @Override public void startPrefixMapping(final String prefix, final String uri) throws SAXException { // Just kill what's usually done here... } }; } }, jdomFac); final Document doc = builder.build(resource.openStream()); final Element collada = doc.getRootElement(); // ColladaDOMUtil.stripNamespace(collada); return collada; } catch (final Exception e) { throw new RuntimeException("Unable to load collada resource from source: " + resource, e); } }
From source file:com.googlesource.gerrit.plugins.manifest.ManifestXml.java
License:Apache License
public ManifestXml(String xml) throws IOException, ParserConfigurationException, SAXException, JDOMException { // Insert a unique identifier for entity definitions to prevent them from // getting expanded during the parse genReplacementText(xml);/*from w ww .j a va2 s .com*/ xml = xml.replaceAll("&([^;]*);", replacementText + "$1;"); SAXBuilder builder = new SAXBuilder(); builder.setSAXHandlerFactory(new SAXHandlerFactory() { @Override public SAXHandler createSAXHandler(JDOMFactory jdomFactory) { return new SAXHandler() { @Override public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) { dtdAttributes.add(new DTDAttribute(eName, aName, type, valueDefault, value)); super.attributeDecl(eName, aName, type, valueDefault, value); } }; } }); builder.setExpandEntities(false); doc = builder.build(new InputSource(new StringReader(xml))); }