Search in sources :

Example 91 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.

the class EventSpecificTestCase method runTest.

protected final void runTest() throws Throwable {
    XMLInputFactory factory = staxImpl.getDialect().enableCDataReporting(staxImpl.newNormalizedXMLInputFactory());
    factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
    InputStream in = IllegalStateExceptionTestCase.class.getResourceAsStream("alleventtypes.xml");
    try {
        XMLStreamReader reader = factory.createXMLStreamReader(in);
        while (true) {
            if (reader.getEventType() == event) {
                break;
            } else if (reader.hasNext()) {
                reader.next();
            } else {
                fail("Internal error: didn't encounter event " + event);
            }
        }
        runTest(reader);
    } finally {
        in.close();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 92 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.

the class XMLFragmentStreamReaderTest method test.

/**
     * Test comparing the output of {@link XMLFragmentStreamReader} with that
     * of a native StAX parser. In particular this tests the behavior for START_DOCUMENT
     * and END_DOCUMENT events.
     * 
     * @throws Exception
     */
public void test() throws Exception {
    String xml = "<ns:a xmlns:ns='urn:ns'>test</ns:a>";
    XMLStreamReader expected = StAXUtils.createXMLStreamReader(new StringReader(xml));
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader(xml));
    reader.nextTag();
    XMLStreamReader actual = new XMLFragmentStreamReader(reader);
    new XMLStreamReaderComparator(expected, actual).compare();
    assertEquals(XMLStreamReader.END_DOCUMENT, reader.getEventType());
    expected.close();
    reader.close();
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamReaderComparator(org.apache.axiom.testutils.stax.XMLStreamReaderComparator) StringReader(java.io.StringReader)

Example 93 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.

the class XMLStreamReaderUtilsTest method testGetDataHandlerFromElementWithUnexpectedContent.

private void testGetDataHandlerFromElementWithUnexpectedContent(boolean useDHR) throws Exception {
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test>\n<child/>\n</test>"));
    if (useDHR) {
        reader = new XMLStreamReaderWithDataHandlerReader(reader);
    }
    try {
        reader.next();
        // Check precondition
        assertTrue(reader.isStartElement());
        try {
            XMLStreamReaderUtils.getDataHandlerFromElement(reader);
            fail("Expected XMLStreamException");
        } catch (XMLStreamException ex) {
        // Expected
        }
    } finally {
        reader.close();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader)

Example 94 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.

the class XMLStreamReaderUtilsTest method testGetDataHandlerFromElementWithZeroLength.

private void testGetDataHandlerFromElementWithZeroLength(boolean useDHR) throws Exception {
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test/>"));
    if (useDHR) {
        reader = new XMLStreamReaderWithDataHandlerReader(reader);
    }
    try {
        reader.next();
        // Check precondition
        assertTrue(reader.isStartElement());
        DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader);
        // Check postcondition
        assertTrue(reader.isEndElement());
        assertEquals(-1, dh.getInputStream().read());
    } finally {
        reader.close();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) DataHandler(javax.activation.DataHandler)

Example 95 with XMLStreamReader

use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.

the class XMLStreamReaderUtilsTest method testGetElementTextAsStreamWithAllowedNonTextChildren.

public void testGetElementTextAsStreamWithAllowedNonTextChildren() throws Exception {
    XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<a>xxx<b>yyy</b>zzz</a>"));
    reader.next();
    Reader in = XMLStreamReaderUtils.getElementTextAsStream(reader, true);
    assertEquals("xxxzzz", IOUtils.toString(in));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) XMLStreamReader(javax.xml.stream.XMLStreamReader)

Aggregations

XMLStreamReader (javax.xml.stream.XMLStreamReader)243 XMLInputFactory (javax.xml.stream.XMLInputFactory)98 StringReader (java.io.StringReader)85 XMLStreamException (javax.xml.stream.XMLStreamException)78 InputStream (java.io.InputStream)61 IOException (java.io.IOException)43 OMElement (org.apache.axiom.om.OMElement)37 ByteArrayInputStream (java.io.ByteArrayInputStream)27 Test (org.junit.Test)25 JAXBException (javax.xml.bind.JAXBException)16 QName (javax.xml.namespace.QName)16 StAXSource (javax.xml.transform.stax.StAXSource)16 StreamSource (javax.xml.transform.stream.StreamSource)16 FileInputStream (java.io.FileInputStream)14 OMFactory (org.apache.axiom.om.OMFactory)14 Unmarshaller (javax.xml.bind.Unmarshaller)13 InputStreamReader (java.io.InputStreamReader)12 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)12 Source (javax.xml.transform.Source)11 InputSource (org.xml.sax.InputSource)11