public static Document asDocument( File webXML ) throws DocumentException { // Make the reader non-validating so that it doesn't try to resolve external DTD's. Trying to resolve // external DTD's can break on some firewall configurations. SAXReader saxReader = new SAXReader( false); try { saxReader.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false ); } catch (SAXException e) { Log.warn("Error setting SAXReader feature", e); } return saxReader.read( webXML ); }
public static SAXReader getSAXReader( final EntityResolver resolver ) { SAXReader reader = new SAXReader(); if ( resolver != null ) { reader.setEntityResolver( resolver ); } 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; } }
/** * Create and initialize the SAX reader. * * @return the SAX reader instance. * @throws DocumentException if DOCTYPE processing cannot be disabled * @since 1.4.9 */ protected SAXReader createReader() throws DocumentException { final SAXReader reader = new SAXReader(); try { reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); } catch (SAXException e) { throw new DocumentException("Cannot disable DOCTYPE processing", e); } return reader; } }
reader.setFeature( "http://apache.org/xml/features/validation/schema", true ); } else {
reader.setFeature( "http://apache.org/xml/features/validation/schema", true ); } else {
reader.setFeature( "http://apache.org/xml/features/validation/schema", true ); } else {
public static SAXReader getSAXReader(final EntityResolver resolver) { SAXReader reader = new SAXReader(); if (resolver != null) { reader.setEntityResolver(resolver); } 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; } }
SAXReader reader = new SAXReader(); try { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); reader.setFeature("http://xml.org/sax/features/external-general-entities", false); reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false); } catch (SAXException e) {
private void setValidationFor(SAXReader saxReader, String xsd) { try { saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true ); //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true ); //set the default schema locators saxReader.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation", "http://java.sun.com/xml/ns/persistence/orm " + xsd ); } catch ( SAXException e ) { saxReader.setValidation( false ); } }
private static void setFeatureQuietly(SAXReader reader, String feature, boolean value) { try { reader.setFeature(feature, value); } catch (SAXException ignored) { // ignore and continue in case the feature cannot be changed } }
public static Document getDocumentFromInputStream(InputStream inputStream) throws DocumentException, SAXException { SAXReader saxReader = new SAXReader(); saxReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); saxReader.setFeature("http://xml.org/sax/features/external-general-entities", false); saxReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false); return saxReader.read(inputStream); }
private static void setFeature(final SAXReader xmlReader, final String name, final boolean value) { try { xmlReader.setFeature(name, value); } catch (SAXException e) { privateLog.warn("Unable to set " + name + " to " + value); } } }
public static Map<String, String> toJdMap(String body, String charset) throws Exception { SAXReader reader = new SAXReader(false); reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); reader.setFeature("http://xml.org/sax/features/external-general-entities", false); reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false); InputSource source = new InputSource(new ByteArrayInputStream(body.getBytes("UTF-8"))); source.setEncoding(charset); Document doc = reader.read(source); Map<String, String> params = XmlUtils.toJdMap(doc.getRootElement()); return params; } public static Map<String, String> toJdMap(Element element) {
public static SAXReader createSAXReader() { SAXReader reader = new SAXReader(); reader.setEntityResolver((publicId, systemId) -> new InputSource(new ByteArrayInputStream(new byte[0]))); try { reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); } catch (SAXException e) { log.debug(e.getMessage(), e); } return reader; } }
public static MathML read(Reader reader) throws SAXException, DocumentException { SAXReader sax = new SAXReader(false); sax.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document document = sax.read(reader); return new MathML(document.getRootElement()); }
private static Document getConfigDocument() throws Exception { SAXReader reader = new SAXReader(); reader.setEncoding("UTF-8"); reader.setValidation(false); reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document document = reader.read(SchedulerUtil.class.getResourceAsStream(xmlFile)); return document; }
protected CompiledSQL loadCSFromStream(String id, InputStream is) throws Exception { SAXReader reader = null; Document document = null; reader = new SAXReader(); reader.setValidation(false); // http://apache.org/xml/features/nonvalidating/load-external-dtd" reader.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.LOAD_EXTERNAL_DTD_FEATURE, false); InputStreamReader isr = new InputStreamReader(is, encoding); document = reader.read(isr); final Element root = document.getRootElement(); CompiledSQL cs = loadCompiledSQL(id, root); return cs; }
public ClassificationItem parse(Reader reader) throws PatentReaderException { try { SAXReader sax = new SAXReader(false); sax.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document document = sax.read(reader); return parse(document); } catch (SAXException e) { throw new PatentReaderException(e); } catch (DocumentException e) { throw new PatentReaderException(e); } }
private void setValidationFor(SAXReader saxReader, String xsd) { try { saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true ); //saxReader.setFeature( "http://apache.org/xml/features/validation/dynamic", true ); //set the default schema locators saxReader.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation", "http://java.sun.com/xml/ns/persistence/orm " + xsd ); } catch ( SAXException e ) { saxReader.setValidation( false ); } }
/** Constructor */ public SafeSAXReader() { reader = new SAXReader(new SafeSAXParser()); reader.setValidation(false); try { reader.setFeature(feature, false); } catch (SAXException ex) { // Do we care? } }