Search in sources :

Example 16 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project spring-framework by spring-projects.

the class StaxEventXMLReaderTests method partial.

@Test
public void partial() throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
    // skip to root
    eventReader.nextTag();
    StaxEventXMLReader xmlReader = new StaxEventXMLReader(eventReader);
    ContentHandler contentHandler = mock(ContentHandler.class);
    xmlReader.setContentHandler(contentHandler);
    xmlReader.parse(new InputSource());
    verify(contentHandler).startDocument();
    verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class));
    verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child");
    verify(contentHandler).endDocument();
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) Attributes(org.xml.sax.Attributes) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory) ContentHandler(org.xml.sax.ContentHandler) Test(org.junit.Test)

Example 17 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project spring-framework by spring-projects.

the class StaxStreamXMLReaderTests method partial.

@Test
public void partial() throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT));
    // skip to root
    streamReader.nextTag();
    assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "root"), streamReader.getName());
    // skip to child
    streamReader.nextTag();
    assertEquals("Invalid element", new QName("http://springframework.org/spring-ws", "child"), streamReader.getName());
    StaxStreamXMLReader xmlReader = new StaxStreamXMLReader(streamReader);
    ContentHandler contentHandler = mock(ContentHandler.class);
    xmlReader.setContentHandler(contentHandler);
    xmlReader.parse(new InputSource());
    verify(contentHandler).setDocumentLocator(any(Locator.class));
    verify(contentHandler).startDocument();
    verify(contentHandler).startElement(eq("http://springframework.org/spring-ws"), eq("child"), eq("child"), any(Attributes.class));
    verify(contentHandler).endElement("http://springframework.org/spring-ws", "child", "child");
    verify(contentHandler).endDocument();
}
Also used : InputSource(org.xml.sax.InputSource) Locator(org.xml.sax.Locator) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StringReader(java.io.StringReader) Attributes(org.xml.sax.Attributes) XMLInputFactory(javax.xml.stream.XMLInputFactory) ContentHandler(org.xml.sax.ContentHandler) Test(org.junit.Test)

Example 18 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project spring-framework by spring-projects.

the class StaxUtilsTests method isStaxSource.

@Test
public void isStaxSource() throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    String expected = "<element/>";
    XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(expected));
    Source source = StaxUtils.createCustomStaxSource(streamReader);
    assertTrue("Not a StAX Source", StaxUtils.isStaxSource(source));
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) XMLInputFactory(javax.xml.stream.XMLInputFactory) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) StAXSource(javax.xml.transform.stax.StAXSource) Test(org.junit.Test)

Example 19 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project spring-framework by spring-projects.

the class AbstractUnmarshallerTests method unmarshalJaxp14StaxSourceXmlStreamReader.

@Test
public void unmarshalJaxp14StaxSourceXmlStreamReader() throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
    StAXSource source = new StAXSource(streamReader);
    Object flights = unmarshaller.unmarshal(source);
    testFlights(flights);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) StAXSource(javax.xml.transform.stax.StAXSource) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 20 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project spring-framework by spring-projects.

the class XStreamUnmarshallerTests method unmarshalStaxSourceXmlStreamReader.

@Test
public void unmarshalStaxSourceXmlStreamReader() throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
    Source source = StaxUtils.createStaxSource(streamReader);
    Object flights = unmarshaller.unmarshal(source);
    testFlight(flights);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) XMLInputFactory(javax.xml.stream.XMLInputFactory) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

XMLInputFactory (javax.xml.stream.XMLInputFactory)154 XMLStreamReader (javax.xml.stream.XMLStreamReader)98 XMLStreamException (javax.xml.stream.XMLStreamException)63 StringReader (java.io.StringReader)43 InputStream (java.io.InputStream)41 IOException (java.io.IOException)33 XMLEventReader (javax.xml.stream.XMLEventReader)30 Test (org.junit.Test)22 ByteArrayInputStream (java.io.ByteArrayInputStream)19 InputStreamReader (java.io.InputStreamReader)14 JAXBException (javax.xml.bind.JAXBException)14 StAXSource (javax.xml.transform.stax.StAXSource)14 StreamSource (javax.xml.transform.stream.StreamSource)14 Unmarshaller (javax.xml.bind.Unmarshaller)13 ArrayList (java.util.ArrayList)12 XMLEvent (javax.xml.stream.events.XMLEvent)12 DOMSource (javax.xml.transform.dom.DOMSource)11 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)10 JAXBContext (javax.xml.bind.JAXBContext)9 HashMap (java.util.HashMap)8