Example usage for javax.xml.stream XMLInputFactory IS_VALIDATING

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

Introduction

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

Prototype

String IS_VALIDATING

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

Click Source Link

Document

The property used to turn on/off implementation specific validation

Usage

From source file:Main.java

private static void createXMLInputFactory() {
    // Create the factory
    xmlInputFactory = XMLInputFactory.newInstance();
    xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
}

From source file:eu.arthepsy.sonar.plugins.scapegoat.util.XmlUtils.java

public static SMInputFactory createFactory() {
    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
    xmlFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
    xmlFactory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
    SMInputFactory inputFactory = new SMInputFactory(xmlFactory);
    return inputFactory;
}

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

@After
public void tearDown() {
    System.clearProperty(XMLInputFactory.IS_NAMESPACE_AWARE);
    System.clearProperty(XMLInputFactory.IS_VALIDATING);
    System.clearProperty(XMLInputFactory.IS_COALESCING);
    System.clearProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES);
    System.clearProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
    System.clearProperty(XMLInputFactory.SUPPORT_DTD);
}

From source file:com.msopentech.odatajclient.testservice.utils.XMLEventReaderWrapper.java

public XMLEventReaderWrapper(final InputStream stream) throws Exception {
    final XMLInputFactory factory = XMLInputFactory.newInstance();
    factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);

    this.wrapped = factory.createXMLEventReader(new ByteArrayInputStream(
            (XMLEventReaderWrapper.CONTENT_STAG + IOUtils.toString(stream) + XMLEventReaderWrapper.CONTENT_ETAG)
                    .getBytes()));/*  w  w w. ja  v a 2 s.  com*/

    init(wrapped);
}

From source file:com.lucidworks.hadoop.ingest.util.EmptyEntityResolver.java

/**
 * Configures the given {@link XMLInputFactory} to not parse external entities.
 * No further configuration on is needed, all required entity resolvers are configured.
 *//* w ww .ja  v a2 s.  c  o m*/
public static void configureXMLInputFactory(XMLInputFactory inputFactory) {
    // don't enable validation of DTDs:
    trySetStAXProperty(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
    // enable this to *not* produce parsing failure on external entities:
    trySetStAXProperty(inputFactory, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
    inputFactory.setXMLResolver(EmptyEntityResolver.STAX_INSTANCE);
}

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>/*from   w  w w. ja  v  a  2 s. co 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.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
 */// www. j a  v a2 s.  c  o m
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:com.autonomy.aci.client.services.impl.AbstractStAXProcessorTest.java

@Test
public void testXMLInputFactorySystemProperties() throws NoSuchFieldException, IllegalAccessException {
    AbstractStAXProcessor<?> abstractStAXProcessor = spy(AbstractStAXProcessor.class);
    final XMLInputFactory mockXmlInputFactory = mock(XMLInputFactory.class);

    final Field field = ReflectionTestUtils.getAccessibleField(AbstractStAXProcessor.class, "xmlInputFactory");
    field.set(abstractStAXProcessor, mockXmlInputFactory);

    // Check the defaults...
    abstractStAXProcessor.process(when(mock(AciResponseInputStream.class).getContentType())
            .thenReturn("text/xml").<AciResponseInputStream>getMock());
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_VALIDATING, false);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_COALESCING, false);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.SUPPORT_DTD, true);

    // Set different values via system properties...
    System.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, "true");
    System.setProperty(XMLInputFactory.IS_VALIDATING, "true");
    System.setProperty(XMLInputFactory.IS_COALESCING, "true");
    System.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, "false");
    System.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, "true");
    System.setProperty(XMLInputFactory.SUPPORT_DTD, "false");

    // Create a new spy...
    abstractStAXProcessor = spy(AbstractStAXProcessor.class);
    field.set(abstractStAXProcessor, mockXmlInputFactory);

    // Check the values have changed when set...
    abstractStAXProcessor.process(when(mock(AciResponseInputStream.class).getContentType())
            .thenReturn("text/xml").<AciResponseInputStream>getMock());
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_VALIDATING, true);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_COALESCING, true);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true);
    verify(mockXmlInputFactory).setProperty(XMLInputFactory.SUPPORT_DTD, false);
}

From source file:org.callimachusproject.rdfa.test.RDFaGenerationTest.java

public void setUp() throws Exception {
    xmlInputFactory = XMLInputFactory.newInstance();
    xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    xmlInputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
    xmlInputFactory.setProperty("http://java.sun.com/xml/stream/properties/ignore-external-dtd", true);
    xmlInputFactory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", true);

    // XPath//ww w .  j  a v a  2s  .  com
    xPathFactory = XPathFactory.newInstance();

    // initialize an in-memory store
    sourceRepository = new SailRepository(new MemoryStore());
    sourceRepository.initialize();
    source = sourceRepository.getConnection();
    expectedRepository = new SailRepository(new MemoryStore());
    expectedRepository.initialize();
    expected = expectedRepository.getConnection();
    actualRepository = new SailRepository(new MemoryStore());
    actualRepository.initialize();
    actual = actualRepository.getConnection();
    initialize();
}