Java Code Examples for org.jdom.input.SAXBuilder#setFeature()
The following examples show how to use
org.jdom.input.SAXBuilder#setFeature() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 6 votes |
public static Element parseDocument(final URL docUrl) { try { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); builder.setValidation(false); final Document doc = builder.build(docUrl); if (doc == null) { return null; } final Element root = doc.getRootElement(); return root; } catch (final IOException ioe) { LOGGER.warn("parse error", ioe); return null; } catch (final JDOMException jdome) { LOGGER.warn("parse error", jdome); return null; } }
Example 2
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 6 votes |
public static Element parseDocument(final File f) { try { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final Document doc = builder.build(f); if (doc == null) { return null; } final Element root = doc.getRootElement(); return root; } catch (final IOException ioe) { LOGGER.warn("parse error", ioe); return null; } catch (final JDOMException jdome) { LOGGER.warn("parse error", jdome); return null; } }
Example 3
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 6 votes |
public static Element parseDocument(final InputStream is) { try { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final Document doc = builder.build(is); if (doc == null) { return null; } final Element root = doc.getRootElement(); return root; } catch (final IOException ioe) { LOGGER.warn("parse error", ioe); return null; } catch (final JDOMException jdome) { LOGGER.warn("parse error", jdome); return null; } }
Example 4
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 6 votes |
public static Element parseDocument(final InputSource is) { try { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final Document doc = builder.build(is); if (doc == null) { return null; } final Element root = doc.getRootElement(); return root; } catch (final IOException ioe) { LOGGER.warn("parse error", ioe); return null; } catch (final JDOMException jdome) { LOGGER.warn("parse error", jdome); return null; } }
Example 5
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 6 votes |
public static Element readElementFromString(final String xmlData) { try { final StringReader sr = new StringReader(xmlData); final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final Document doc = builder.build(sr); if (doc == null) { return null; } final Element root = doc.getRootElement(); return root; } catch (final IOException ioe) { LOGGER.info("read error", ioe); return null; } catch (final JDOMException jdome) { LOGGER.info("read error", jdome); return null; } }
Example 6
Source File: XmlUtilities.java From ghidra with Apache License 2.0 | 5 votes |
/** * Create a {@link SAXBuilder} that is not susceptible to XXE. * * This configures the builder to ignore external entities. * * @param validate indicates whether validation should occur * @param needsDTD false to disable doctype declarations altogether * @return the configured builder */ public static SAXBuilder createSecureSAXBuilder(boolean validate, boolean needsDTD) { final String IMPLNAME = "com.sun.org.apache.xerces.internal.parsers.SAXParser"; SAXBuilder sax = new SAXBuilder(IMPLNAME, validate); sax.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); // XML Program Import uses DTD if (!needsDTD) { sax.setFeature(FEATURE_DISALLOW_DTD, true); } sax.setFeature(FEATURE_EXTERNAL_GENERAL_ENTITIES, false); sax.setFeature(FEATURE_EXTERNAL_PARAMETER_ENTITIES, false); return sax; }
Example 7
Source File: AbstractSamlObjectBuilder.java From springboot-shiro-cas-mybatis with MIT License | 5 votes |
/** * Construct document from xml string. * * @param xmlString the xml string * @return the document */ public static Document constructDocumentFromXml(final String xmlString) { try { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://xml.org/sax/features/external-general-entities", false); builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); return builder .build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset()))); } catch (final Exception e) { return null; } }
Example 8
Source File: SamlUtils.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
public static Document constructDocumentFromXmlString(final String xmlString) { try { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://xml.org/sax/features/external-general-entities", false); builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); return builder .build(new ByteArrayInputStream(xmlString.getBytes())); } catch (final Exception e) { return null; } }
Example 9
Source File: KbCsvMojo.java From Asqatasun with GNU Affero General Public License v3.0 | 5 votes |
private List<String> getUrls(String url) throws JDOMException, JaxenException, IOException { SAXBuilder builder = new SAXBuilder(); EntityResolver resolver = new XhtmlEntityResolver(); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); builder.setEntityResolver(resolver); Document document = builder.build(new URL(url)); XPath xpath = new JDOMXPath("//*[@id='resultat']//*[@href]/@href"); List<Attribute> results = xpath.selectNodes(document); List<String> urls = new ArrayList<String>(); for (Attribute attr : results) { urls.add(attr.getValue()); } return urls; }
Example 10
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static Document readDocumentFromString(final String xmlData) { try { final StringReader sr = new StringReader(xmlData); final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); final Document doc = builder.build(sr); return doc; } catch (final IOException ioe) { LOGGER.info("read error", ioe); return null; } catch (final JDOMException jdome) { LOGGER.info("read error", jdome); return null; } }
Example 11
Source File: JDomDriver.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Create and initialize the SAX builder. * * @return the SAX builder instance. * @since 1.4.9 */ protected SAXBuilder createBuilder() { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); return builder; }