Example usage for javax.xml.stream XMLInputFactory SUPPORT_DTD

List of usage examples for javax.xml.stream XMLInputFactory SUPPORT_DTD

Introduction

In this page you can find the example usage for javax.xml.stream XMLInputFactory SUPPORT_DTD.

Prototype

String SUPPORT_DTD

To view the source code for javax.xml.stream XMLInputFactory SUPPORT_DTD.

Click Source Link

Document

The property that requires the parser to support DTDs

Usage

From source file:org.owasp.webgoat.plugin.XXE.java

private SearchForm parseXml(String xml) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(SearchForm.class);

    XMLInputFactory xif = XMLInputFactory.newFactory();
    xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true);
    xif.setProperty(XMLInputFactory.SUPPORT_DTD, true);
    XMLStreamReader xsr = xif.createXMLStreamReader(new StringReader(xml));

    Unmarshaller unmarshaller = jc.createUnmarshaller();
    return (SearchForm) unmarshaller.unmarshal(xsr);
}

From source file:com.ikanow.aleph2.analytics.hadoop.services.BeXmlParser.java

public BeXmlParser(final BeFileInputConfigBean.XML xml) {
    _xml = xml;/*from ww  w .  j a v  a  2  s  . c  o m*/

    // If any of the fields contain ":" then it's in "prefix mode", which means the prefixes are used to lookup root and ignore fields (but are still discarded from the JSON)
    _prefix_mode = Stream.concat(xml.root_fields().stream(), xml.ignore_fields().stream())
            .anyMatch(s -> s.contains(":"));

    _factory.setProperty(XMLInputFactory.IS_COALESCING, true);
    _factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
}

From source file:com.ikanow.infinit.e.data_model.custom.InfiniteFileInputXmlParser.java

@Override
public InfiniteFileInputParser initialize(InputStream inStream, SourceFileConfigPojo fileConfig)
        throws IOException {

    // Processing logic

    levelOneFields = new ArrayList<String>();
    ignoreFields = new ArrayList<String>();
    if (null != fileConfig.XmlPreserveCase) {
        this.bPreserveCase = fileConfig.XmlPreserveCase;
    }/*  w w w  .j a  va 2 s. c  om*/
    XmlSourceName = fileConfig.XmlSourceName;
    PKElement = fileConfig.XmlPrimaryKey;
    setLevelOneField(fileConfig.XmlRootLevelValues);
    setIgnoreField(fileConfig.XmlIgnoreValues);
    AttributePrefix = fileConfig.XmlAttributePrefix;

    _sb = new StringBuffer();

    // Input stream -> reader

    XMLInputFactory factory = XMLInputFactory.newInstance();
    factory.setProperty(XMLInputFactory.IS_COALESCING, true);
    factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    try {
        _xmlStreamReader = factory.createXMLStreamReader(inStream);
    } catch (XMLStreamException e) {
        throw new IOException(e);
    }

    return this;
}

From source file:microsoft.exchange.webservices.data.core.EwsXmlReader.java

/**
 * Initializes the XML reader.//from  ww w .j  a v a2 s  . c  o m
 *
 * @param stream the stream
 * @return An XML reader to use.
 * @throws Exception on error
 */
protected XMLEventReader initializeXmlReader(InputStream stream) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);

    return inputFactory.createXMLEventReader(stream);
}

From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java

/**
 * This constructor gets a new {@link XMLInputFactory} instance that is reused every time
 * {@link #process(com.autonomy.aci.client.transport.AciResponseInputStream)} is called, this
 * should be faster than creating a new instance every time this method is called.
 * <p>/*ww w .  j  a  va2 s .  c  o  m*/
 * The properties are set to the following defaults if they are not specified as system properties:
 * <table summary="">
 * <tr><th>Property</th><th>Default</th></tr>
 * <tr><td>XMLInputFactory.IS_NAMESPACE_AWARE</td><td><tt>false</tt></td></tr>
 * <tr><td>XMLInputFactory.IS_VALIDATING<tt>false</tt></td></tr>
 * <tr><td>XMLInputFactory.IS_COALESCING<tt>false</tt></td></tr>
 * <tr><td>XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES<tt>true</tt></td></tr>
 * <tr><td>XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES<tt>false</tt></td></tr>
 * <tr><td>XMLInputFactory.SUPPORT_DTD<tt>true</tt></td></tr>
 * </table>
 */
protected AbstractStAXProcessor() {
    // See if the various XMLInputFactory properties are set as system properties...
    namespaceAware = BooleanUtils.toBoolean(
            StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE), "false"));
    validating = BooleanUtils
            .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_VALIDATING), "false"));
    coalescing = BooleanUtils
            .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.IS_COALESCING), "false"));
    replacingEntityReferences = BooleanUtils.toBoolean(StringUtils
            .defaultString(System.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES), "true"));
    supportingExternalEntities = BooleanUtils.toBoolean(StringUtils
            .defaultString(System.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES), "false"));
    supportDtd = BooleanUtils
            .toBoolean(StringUtils.defaultString(System.getProperty(XMLInputFactory.SUPPORT_DTD), "true"));

    // Create the XMLStreamReader factory...
    xmlInputFactory = XMLInputFactory.newInstance();
}

From source file:com.googlesource.gerrit.plugins.supermanifest.JiriManifestParser.java

private static JiriManifest parseManifest(Repository repo, String ref, String file)
        throws JAXBException, IOException, XMLStreamException {
    byte[] b = Utils.readBlob(repo, ref + ":" + file);
    JAXBContext jc = JAXBContext.newInstance(JiriManifest.class);

    XMLInputFactory inf = XMLInputFactory.newFactory();
    inf.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
    inf.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    XMLStreamReader sr = inf.createXMLStreamReader(new StreamSource(new ByteArrayInputStream(b)));

    return (JiriManifest) jc.createUnmarshaller().unmarshal(sr);
}

From source file:com.streamsets.pipeline.stage.origin.salesforce.ForceSource.java

public ForceSource(ForceSourceConfigBean conf) {
    this.conf = conf;

    xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
    xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
    xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
}

From source file:com.autonomy.aci.client.services.impl.AbstractStAXProcessor.java

/**
 * This method firstly checks that the content type of the response is text based and can be parsed. If so, it
 * converts the <tt>AciResponseInputStream</tt> into a StAX <tt>XMLStreamReader</tt> and calls the the {@link
 * #process(javax.xml.stream.XMLStreamReader)} method that should be implemented in a subclass to do all the work.
 * @param aciResponseInputStream The ACI response to process
 * @return An object of type <tt>T</tt>
 * @throws AciErrorException  If the ACI response was an error response
 * @throws ProcessorException If an error occurred during the processing of the IDOL response
 *//*from w w  w .  j  av  a2 s.  c  om*/
public T process(final AciResponseInputStream aciResponseInputStream) {
    LOGGER.trace("process() called...");

    if (!"text/xml".equalsIgnoreCase(aciResponseInputStream.getContentType())) {
        throw new ProcessorException(
                "This processor is unable to process non-text ACI responses. The content type for this response is "
                        + aciResponseInputStream.getContentType());
    }

    // Define this here so we can make sure it's closed when the processor is finished...
    XMLStreamReader xmlStreamReader = null;

    try {
        // Update the factory with the various properties as they might have changed since the last run...
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, namespaceAware);
        xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, validating);
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, coalescing);
        xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, replacingEntityReferences);
        xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
                supportingExternalEntities);
        xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, supportDtd);

        // Convert the input stream..
        xmlStreamReader = xmlInputFactory.createXMLStreamReader(aciResponseInputStream);
        return process(xmlStreamReader);
    } catch (final XMLStreamException xmlse) {
        throw new ProcessorException("Unable to convert the InputStream to a XMLStreamReader", xmlse);
    } finally {
        if (xmlStreamReader != null) {
            try {
                // This does NOT close the underlying AciResponseInputStream
                xmlStreamReader.close();
            } catch (final XMLStreamException xmlse) {
                LOGGER.error("Unable to close the XMLStreamReader.", xmlse);
            }
        }
    }
}

From source file:demo.SourceHttpMessageConverter.java

private Source readStAXSource(InputStream body) {
    try {/* w  ww. j  a  v a2  s .co m*/
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, isSupportDtd());
        inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, isProcessExternalEntities());
        if (!isProcessExternalEntities()) {
            inputFactory.setXMLResolver(NO_OP_XML_RESOLVER);
        }
        XMLStreamReader streamReader = inputFactory.createXMLStreamReader(body);
        return new StAXSource(streamReader);
    } catch (XMLStreamException ex) {
        throw new HttpMessageNotReadableException("Could not parse document: " + ex.getMessage(), ex);
    }
}