List of usage examples for org.jdom2.input SAXBuilder setEntityResolver
public void setEntityResolver(final EntityResolver entityResolver)
Builder
. From source file:org.mycore.common.xml.MCRURIResolver.java
License:Open Source License
/** * Reads xml from an InputStream and returns the parsed root element. * * @param in//from www . java 2 s. c om * the InputStream that contains the XML document * @return the root element of the parsed input stream */ protected Element parseStream(InputStream in) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING); builder.setEntityResolver(MCREntityResolver.instance()); return builder.build(in).getRootElement(); }
From source file:org.xwiki.resource.internal.entity.DefaultEntityResourceActionLister.java
License:Open Source License
@Override public void initialize() throws InitializationException { // Parse the Struts config file (struts-config.xml) to extract all available actions List<String> actionNames = new ArrayList<>(); SAXBuilder builder = new SAXBuilder(); // Make sure we don't require an Internet Connection to parse the Struts config file! builder.setEntityResolver(new EntityResolver() { @Override/*from w w w .j av a 2s .c om*/ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); // Step 1: Get a stream on the Struts config file if it exists InputStream strutsConfigStream = this.environment.getResourceAsStream(getStrutsConfigResource()); if (strutsConfigStream != null) { // Step 2: Parse the Strust config file, looking for action names Document document; try { document = builder.build(strutsConfigStream); } catch (JDOMException | IOException e) { throw new InitializationException( String.format("Failed to parse Struts Config file [%s]", getStrutsConfigResource()), e); } Element mappingElement = document.getRootElement().getChild("action-mappings"); for (Element element : mappingElement.getChildren("action")) { // We extract the action name from the path mapping. Note that we cannot use the "name" attribute since // it's not reliable (it's not unique) and for example the sanveandcontinue action uses "save" as its // "name" element value. actionNames.add(StringUtils.strip(element.getAttributeValue("path"), "/")); } } this.strutsActionNames = actionNames; }
From source file:site.util.EvXmlUtil.java
License:BSD License
public static Document readXML(Reader c) throws Exception { @SuppressWarnings("deprecation") SAXBuilder saxBuilder = new SAXBuilder(false); //No validation //saxBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); //xerxes only saxBuilder.setEntityResolver(new NoOpEntityResolver()); //http://www.jdom.org/docs/faq.html#a0350 Document document = saxBuilder.build(c); return document; }