List of usage examples for org.dom4j.io SAXReader setIncludeExternalDTDDeclarations
public void setIncludeExternalDTDDeclarations(boolean include)
From source file:com.cladonia.xml.XMLUtilities.java
License:Open Source License
/** * Creates a new SAXReader.// w ww. j a v a2s. c o m * * @param validate when true the reader validates the input. * * @return the reader. */ public static SAXReader createReader(boolean validate, boolean loadExternalDTD) { SAXReader reader = new SAXReader(XDocumentFactory.getInstance(), validate); reader.setStripWhitespaceText(false); reader.setMergeAdjacentText(true); // reader.setMergeAdjacentText( true); if (!validate) { reader.setIncludeExternalDTDDeclarations(false); reader.setIncludeInternalDTDDeclarations(true); try { if (loadExternalDTD) { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", true); // System.out.println( "http://apache.org/xml/features/nonvalidating/load-external-dtd = "+reader.getXMLReader().getFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd")); reader.setEntityResolver(getCatalogResolver()); } else { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } } catch (Exception e) { e.printStackTrace(); } } else { try { reader.getXMLReader().setFeature("http://apache.org/xml/features/validation/schema", true); } catch (Exception e) { e.printStackTrace(); } } return reader; }
From source file:com.cladonia.xml.XMLUtilities.java
License:Open Source License
/** * Creates a new SAXReader.//from w w w . j a v a 2s . c om * * @param validate when true the reader validates the input. * * @return the reader. */ public static SAXReader createReader(boolean validate, boolean loadExternalDTD, boolean stripWhiteSpace) { SAXReader reader = new SAXReader(XDocumentFactory.getInstance(), validate); reader.setStripWhitespaceText(stripWhiteSpace); reader.setMergeAdjacentText(true); // reader.setMergeAdjacentText( true); if (!validate) { reader.setIncludeExternalDTDDeclarations(false); reader.setIncludeInternalDTDDeclarations(true); try { if (loadExternalDTD) { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", true); // System.out.println( "http://apache.org/xml/features/nonvalidating/load-external-dtd = "+reader.getXMLReader().getFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd")); reader.setEntityResolver(getCatalogResolver()); } else { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } } catch (Exception e) { e.printStackTrace(); } } else { try { reader.getXMLReader().setFeature("http://apache.org/xml/features/validation/schema", true); } catch (Exception e) { e.printStackTrace(); } } return reader; }
From source file:de.innovationgate.webgate.api.auth.FileAuthenticationModule.java
License:Open Source License
/** * @param _file/*from w ww.j ava2 s . c o m*/ */ private synchronized void update(File _file) { try { // Parse doc SAXReader reader = new SAXReader(); reader.setIncludeExternalDTDDeclarations(false); reader.setIncludeInternalDTDDeclarations(false); reader.setValidation(false); Document doc = reader.read(_file); // Flags _allowAnonymous = Boolean.valueOf(doc.getRootElement().attributeValue("allowanonymous")).booleanValue(); // Read users Map users = new HashMap(); Iterator userNodes = doc.selectNodes("/users/user").iterator(); Element userNode; while (userNodes.hasNext()) { userNode = (Element) userNodes.next(); String name = userNode.attributeValue("name"); String password = userNode.attributeValue("password"); String mail = userNode.attributeValue("mail"); String aliasesStr = userNode.attributeValue("aliases"); Set aliases = new HashSet(); if (aliasesStr != null) { aliases.addAll(WGUtils.deserializeCollection(aliasesStr, ",", true)); } users.put(name, new User(name, password, mail, aliases)); } _users = users; // Read Groups Map groups = new HashMap(); Iterator groupNodes = doc.selectNodes("/users/group").iterator(); Element groupNode; while (groupNodes.hasNext()) { groupNode = (Element) groupNodes.next(); String name = groupNode.attributeValue("name"); List members = WGUtils.deserializeCollection(groupNode.attributeValue("members"), ",", true); Group group = new Group(name, members); groups.put(name, group); notifyMembers(group); } // Call listeners synchronized (_authenticationSourceListeners) { Iterator listeners = _authenticationSourceListeners.iterator(); while (listeners.hasNext()) { ((AuthenticationSourceListener) listeners.next()).authenticationDataChanged(); } } } catch (DocumentException e) { WGFactory.getLogger().error("Error parsing authentication file '" + getAuthenticationSource() + "': Error in XML: " + e.getMessage()); } }
From source file:de.innovationgate.wga.common.beans.hdbmodel.ModelDefinition.java
License:Open Source License
public static ModelDefinition read(InputStream in) throws Exception { // First read XML manually and validate against the DTD provided in this OpenWGA distribution (to prevent it being loaded from the internet, which might not work, see #00003612) SAXReader reader = new SAXReader(); reader.setIncludeExternalDTDDeclarations(true); reader.setIncludeInternalDTDDeclarations(true); reader.setEntityResolver(new EntityResolver() { @Override/*www.ja v a2 s. com*/ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId.equals("http://doc.openwga.com/hdb-model-definition-6.0.dtd")) { return new InputSource(ModelDefinition.class.getClassLoader().getResourceAsStream( WGUtils.getPackagePath(ModelDefinition.class) + "/hdb-model-definition-6.0.dtd")); } else { // use the default behaviour return null; } } }); org.dom4j.Document domDoc = reader.read(in); // Remove doctype (we already have validated) and provide the resulting XML to the serializer domDoc.setDocType(null); StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out); writer.write(domDoc); String xml = out.toString(); return _serializer.read(ModelDefinition.class, new StringReader(xml)); }
From source file:de.jwic.base.JWicRuntime.java
License:Apache License
/** * Setup the JWicRuntime from the jwic-setup.xml file. The setup * defines the available renderer and global settings. * @param in/* ww w. j a va 2 s . c o m*/ */ public void setupRuntime(InputStream stream) { try { SAXReader reader = new SAXReader(); reader.setEntityResolver(new DTDEntityResolver(DTD_PUBLICID, DTD_SYSTEMID, DTD_RESOURCEPATH)); reader.setIncludeExternalDTDDeclarations(false); Document document = reader.read(stream); readDocument(document); sessionManager = new SessionManager(getSavePath()); sessionManager.setStoreTime(sessionStoreTime); } catch (NoClassDefFoundError ncdfe) { if (ncdfe.getMessage().indexOf("dom4j") != -1) { log.error("Can not read jwic-setup.xml: the dom4j library is not in the classpath."); throw new RuntimeException( "Can not read jwic-setup.xml: the dom4j library is not in the classpath.", ncdfe); } log.error("Error reading jwic-setup.xml.", ncdfe); throw new RuntimeException("Error reading jwic-setup.xml: " + ncdfe, ncdfe); } catch (Exception e) { throw new RuntimeException("Error reading jwic-setup.xml: " + e, e); } }
From source file:de.jwic.base.XmlApplicationSetup.java
License:Apache License
/** * Create an ApplicationSetup from the specified file. * @param filename/*from w w w . java 2 s.c om*/ */ public XmlApplicationSetup(String filename) { try { SAXReader reader = new SAXReader(); reader.setEntityResolver(new DTDEntityResolver(PUBLICID, SYSTEMID, DTD_RESOURCEPATH)); reader.setIncludeExternalDTDDeclarations(false); Document document = reader.read(new File(filename)); readDocument(document); } catch (Exception e1) { throw new RuntimeException("Error reading applicationSetup: " + e1, e1); } }
From source file:de.jwic.base.XmlApplicationSetup.java
License:Apache License
/** * Create an ApplicationSetup from the specified stream. * @param filename/*ww w . j ava 2s. c o m*/ */ public XmlApplicationSetup(InputStream stream) { try { SAXReader reader = new SAXReader(); reader.setEntityResolver(new DTDEntityResolver(PUBLICID, SYSTEMID, DTD_RESOURCEPATH)); reader.setIncludeExternalDTDDeclarations(false); Document document = reader.read(stream); readDocument(document); } catch (Exception e1) { throw new RuntimeException("Error reading applicationSetup: " + e1, e1); } }
From source file:de.jwic.base.XmlApplicationSetup.java
License:Apache License
/** * @param source/*from ww w . j ava 2s . co m*/ * @throws IOException */ public XmlApplicationSetup(InputSource source) { try { SAXReader reader = new SAXReader(); reader.setEntityResolver(new DTDEntityResolver(PUBLICID, SYSTEMID, DTD_RESOURCEPATH)); reader.setIncludeExternalDTDDeclarations(false); Document document = reader.read(source); readDocument(document); } catch (Exception e1) { throw new RuntimeException("Error reading applicationSetup: " + e1, e1); } }
From source file:mondrian.util.XmlParserFactoryProducer.java
License:Open Source License
public static SAXReader getSAXReader(final EntityResolver resolver) { SAXReader reader = new SAXReader(); if (resolver != null) { reader.setEntityResolver(resolver); }// w ww . jav a2s . co m try { reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); reader.setFeature("http://xml.org/sax/features/external-general-entities", false); reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } catch (SAXException e) { logger.error("Some parser properties are not supported."); } reader.setIncludeExternalDTDDeclarations(false); reader.setIncludeInternalDTDDeclarations(false); return reader; }
From source file:nl.tue.gale.common.GaleUtil.java
License:Open Source License
public static SAXReader createSAXReader(boolean validation, boolean loaddtd) { SAXReader result = new SAXReader(); result.setValidation(validation);//w ww .j a v a 2 s .co m result.setIncludeExternalDTDDeclarations(loaddtd); result.setIncludeInternalDTDDeclarations(loaddtd); return result; }