org.springframework.util.xml.StaxUtils Java Examples
The following examples show how to use
org.springframework.util.xml.StaxUtils.
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: Jaxb2Marshaller.java From spring-analysis-note with MIT License | 6 votes |
@Override public void marshal(Object graph, Result result, @Nullable MimeContainer mimeContainer) throws XmlMappingException { try { Marshaller marshaller = createMarshaller(); if (this.mtomEnabled && mimeContainer != null) { marshaller.setAttachmentMarshaller(new Jaxb2AttachmentMarshaller(mimeContainer)); } if (StaxUtils.isStaxResult(result)) { marshalStaxResult(marshaller, graph, result); } else { marshaller.marshal(graph, result); } } catch (JAXBException ex) { throw convertJaxbException(ex); } }
Example #2
Source File: AbstractMarshaller.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Template method for handling {@code StaxResult}s. * <p>This implementation delegates to {@code marshalXMLSteamWriter} or * {@code marshalXMLEventConsumer}, depending on what is contained in the * {@code StaxResult}. * @param graph the root of the object graph to marshal * @param staxResult a JAXP 1.4 {@link StAXSource} * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if the {@code domResult} is empty * @see #marshalDomNode(Object, org.w3c.dom.Node) */ protected void marshalStaxResult(Object graph, Result staxResult) throws XmlMappingException { XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(staxResult); if (streamWriter != null) { marshalXmlStreamWriter(graph, streamWriter); } else { XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(staxResult); if (eventWriter != null) { marshalXmlEventWriter(graph, eventWriter); } else { throw new IllegalArgumentException("StaxResult contains neither XMLStreamWriter nor XMLEventConsumer"); } } }
Example #3
Source File: AbstractMarshaller.java From java-technology-stack with MIT License | 6 votes |
/** * Marshals the object graph with the given root into the provided {@code javax.xml.transform.Result}. * <p>This implementation inspects the given result, and calls {@code marshalDomResult}, * {@code marshalSaxResult}, or {@code marshalStreamResult}. * @param graph the root of the object graph to marshal * @param result the result to marshal to * @throws IOException if an I/O exception occurs * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if {@code result} if neither a {@code DOMResult}, * a {@code SAXResult}, nor a {@code StreamResult} * @see #marshalDomResult(Object, javax.xml.transform.dom.DOMResult) * @see #marshalSaxResult(Object, javax.xml.transform.sax.SAXResult) * @see #marshalStreamResult(Object, javax.xml.transform.stream.StreamResult) */ @Override public final void marshal(Object graph, Result result) throws IOException, XmlMappingException { if (result instanceof DOMResult) { marshalDomResult(graph, (DOMResult) result); } else if (StaxUtils.isStaxResult(result)) { marshalStaxResult(graph, result); } else if (result instanceof SAXResult) { marshalSaxResult(graph, (SAXResult) result); } else if (result instanceof StreamResult) { marshalStreamResult(graph, (StreamResult) result); } else { throw new IllegalArgumentException("Unknown Result type: " + result.getClass()); } }
Example #4
Source File: AbstractMarshaller.java From java-technology-stack with MIT License | 6 votes |
/** * Template method for handling {@code StaxResult}s. * <p>This implementation delegates to {@code marshalXMLSteamWriter} or * {@code marshalXMLEventConsumer}, depending on what is contained in the * {@code StaxResult}. * @param graph the root of the object graph to marshal * @param staxResult a JAXP 1.4 {@link StAXSource} * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if the {@code domResult} is empty * @see #marshalDomNode(Object, org.w3c.dom.Node) */ protected void marshalStaxResult(Object graph, Result staxResult) throws XmlMappingException { XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(staxResult); if (streamWriter != null) { marshalXmlStreamWriter(graph, streamWriter); } else { XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(staxResult); if (eventWriter != null) { marshalXmlEventWriter(graph, eventWriter); } else { throw new IllegalArgumentException("StaxResult contains neither XMLStreamWriter nor XMLEventConsumer"); } } }
Example #5
Source File: AbstractMarshaller.java From java-technology-stack with MIT License | 6 votes |
/** * Unmarshals the given provided {@code javax.xml.transform.Source} into an object graph. * <p>This implementation inspects the given result, and calls {@code unmarshalDomSource}, * {@code unmarshalSaxSource}, or {@code unmarshalStreamSource}. * @param source the source to marshal from * @return the object graph * @throws IOException if an I/O Exception occurs * @throws XmlMappingException if the given source cannot be mapped to an object * @throws IllegalArgumentException if {@code source} is neither a {@code DOMSource}, * a {@code SAXSource}, nor a {@code StreamSource} * @see #unmarshalDomSource(javax.xml.transform.dom.DOMSource) * @see #unmarshalSaxSource(javax.xml.transform.sax.SAXSource) * @see #unmarshalStreamSource(javax.xml.transform.stream.StreamSource) */ @Override public final Object unmarshal(Source source) throws IOException, XmlMappingException { if (source instanceof DOMSource) { return unmarshalDomSource((DOMSource) source); } else if (StaxUtils.isStaxSource(source)) { return unmarshalStaxSource(source); } else if (source instanceof SAXSource) { return unmarshalSaxSource((SAXSource) source); } else if (source instanceof StreamSource) { return unmarshalStreamSource((StreamSource) source); } else { throw new IllegalArgumentException("Unknown Source type: " + source.getClass()); } }
Example #6
Source File: AbstractMarshaller.java From java-technology-stack with MIT License | 6 votes |
/** * Template method for handling {@code StaxSource}s. * <p>This implementation delegates to {@code unmarshalXmlStreamReader} or * {@code unmarshalXmlEventReader}. * @param staxSource the {@code StaxSource} * @return the object graph * @throws XmlMappingException if the given source cannot be mapped to an object */ protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException { XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource); if (streamReader != null) { return unmarshalXmlStreamReader(streamReader); } else { XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource); if (eventReader != null) { return unmarshalXmlEventReader(eventReader); } else { throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader"); } } }
Example #7
Source File: Jaxb2Marshaller.java From java-technology-stack with MIT License | 6 votes |
@Override public void marshal(Object graph, Result result, @Nullable MimeContainer mimeContainer) throws XmlMappingException { try { Marshaller marshaller = createMarshaller(); if (this.mtomEnabled && mimeContainer != null) { marshaller.setAttachmentMarshaller(new Jaxb2AttachmentMarshaller(mimeContainer)); } if (StaxUtils.isStaxResult(result)) { marshalStaxResult(marshaller, graph, result); } else { marshaller.marshal(graph, result); } } catch (JAXBException ex) { throw convertJaxbException(ex); } }
Example #8
Source File: Jaxb2Marshaller.java From spring4-understanding with Apache License 2.0 | 6 votes |
protected Object unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSource) throws JAXBException { XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource); if (streamReader != null) { return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(streamReader, this.mappedClass).getValue() : jaxbUnmarshaller.unmarshal(streamReader)); } else { XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource); if (eventReader != null) { return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(eventReader, this.mappedClass).getValue() : jaxbUnmarshaller.unmarshal(eventReader)); } else { throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader"); } } }
Example #9
Source File: Jaxb2Marshaller.java From spring-analysis-note with MIT License | 6 votes |
protected Object unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSource) throws JAXBException { XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource); if (streamReader != null) { return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(streamReader, this.mappedClass).getValue() : jaxbUnmarshaller.unmarshal(streamReader)); } else { XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource); if (eventReader != null) { return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(eventReader, this.mappedClass).getValue() : jaxbUnmarshaller.unmarshal(eventReader)); } else { throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader"); } } }
Example #10
Source File: Jaxb2Marshaller.java From java-technology-stack with MIT License | 6 votes |
protected Object unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSource) throws JAXBException { XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource); if (streamReader != null) { return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(streamReader, this.mappedClass).getValue() : jaxbUnmarshaller.unmarshal(streamReader)); } else { XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource); if (eventReader != null) { return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(eventReader, this.mappedClass).getValue() : jaxbUnmarshaller.unmarshal(eventReader)); } else { throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader"); } } }
Example #11
Source File: AbstractMarshaller.java From spring-analysis-note with MIT License | 6 votes |
/** * Template method for handling {@code StaxSource}s. * <p>This implementation delegates to {@code unmarshalXmlStreamReader} or * {@code unmarshalXmlEventReader}. * @param staxSource the {@code StaxSource} * @return the object graph * @throws XmlMappingException if the given source cannot be mapped to an object */ protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException { XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource); if (streamReader != null) { return unmarshalXmlStreamReader(streamReader); } else { XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource); if (eventReader != null) { return unmarshalXmlEventReader(eventReader); } else { throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader"); } } }
Example #12
Source File: AbstractMarshaller.java From spring-analysis-note with MIT License | 6 votes |
/** * Unmarshals the given provided {@code javax.xml.transform.Source} into an object graph. * <p>This implementation inspects the given result, and calls {@code unmarshalDomSource}, * {@code unmarshalSaxSource}, or {@code unmarshalStreamSource}. * @param source the source to marshal from * @return the object graph * @throws IOException if an I/O Exception occurs * @throws XmlMappingException if the given source cannot be mapped to an object * @throws IllegalArgumentException if {@code source} is neither a {@code DOMSource}, * a {@code SAXSource}, nor a {@code StreamSource} * @see #unmarshalDomSource(javax.xml.transform.dom.DOMSource) * @see #unmarshalSaxSource(javax.xml.transform.sax.SAXSource) * @see #unmarshalStreamSource(javax.xml.transform.stream.StreamSource) */ @Override public final Object unmarshal(Source source) throws IOException, XmlMappingException { if (source instanceof DOMSource) { return unmarshalDomSource((DOMSource) source); } else if (StaxUtils.isStaxSource(source)) { return unmarshalStaxSource(source); } else if (source instanceof SAXSource) { return unmarshalSaxSource((SAXSource) source); } else if (source instanceof StreamSource) { return unmarshalStreamSource((StreamSource) source); } else { throw new IllegalArgumentException("Unknown Source type: " + source.getClass()); } }
Example #13
Source File: AbstractMarshaller.java From spring-analysis-note with MIT License | 6 votes |
/** * Template method for handling {@code StaxResult}s. * <p>This implementation delegates to {@code marshalXMLSteamWriter} or * {@code marshalXMLEventConsumer}, depending on what is contained in the * {@code StaxResult}. * @param graph the root of the object graph to marshal * @param staxResult a JAXP 1.4 {@link StAXSource} * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if the {@code domResult} is empty * @see #marshalDomNode(Object, org.w3c.dom.Node) */ protected void marshalStaxResult(Object graph, Result staxResult) throws XmlMappingException { XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(staxResult); if (streamWriter != null) { marshalXmlStreamWriter(graph, streamWriter); } else { XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(staxResult); if (eventWriter != null) { marshalXmlEventWriter(graph, eventWriter); } else { throw new IllegalArgumentException("StaxResult contains neither XMLStreamWriter nor XMLEventConsumer"); } } }
Example #14
Source File: AbstractMarshaller.java From spring-analysis-note with MIT License | 6 votes |
/** * Marshals the object graph with the given root into the provided {@code javax.xml.transform.Result}. * <p>This implementation inspects the given result, and calls {@code marshalDomResult}, * {@code marshalSaxResult}, or {@code marshalStreamResult}. * @param graph the root of the object graph to marshal * @param result the result to marshal to * @throws IOException if an I/O exception occurs * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if {@code result} if neither a {@code DOMResult}, * a {@code SAXResult}, nor a {@code StreamResult} * @see #marshalDomResult(Object, javax.xml.transform.dom.DOMResult) * @see #marshalSaxResult(Object, javax.xml.transform.sax.SAXResult) * @see #marshalStreamResult(Object, javax.xml.transform.stream.StreamResult) */ @Override public final void marshal(Object graph, Result result) throws IOException, XmlMappingException { if (result instanceof DOMResult) { marshalDomResult(graph, (DOMResult) result); } else if (StaxUtils.isStaxResult(result)) { marshalStaxResult(graph, result); } else if (result instanceof SAXResult) { marshalSaxResult(graph, (SAXResult) result); } else if (result instanceof StreamResult) { marshalStreamResult(graph, (StreamResult) result); } else { throw new IllegalArgumentException("Unknown Result type: " + result.getClass()); } }
Example #15
Source File: AbstractMarshaller.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Marshals the object graph with the given root into the provided {@code javax.xml.transform.Result}. * <p>This implementation inspects the given result, and calls {@code marshalDomResult}, * {@code marshalSaxResult}, or {@code marshalStreamResult}. * @param graph the root of the object graph to marshal * @param result the result to marshal to * @throws IOException if an I/O exception occurs * @throws XmlMappingException if the given object cannot be marshalled to the result * @throws IllegalArgumentException if {@code result} if neither a {@code DOMResult}, * a {@code SAXResult}, nor a {@code StreamResult} * @see #marshalDomResult(Object, javax.xml.transform.dom.DOMResult) * @see #marshalSaxResult(Object, javax.xml.transform.sax.SAXResult) * @see #marshalStreamResult(Object, javax.xml.transform.stream.StreamResult) */ @Override public final void marshal(Object graph, Result result) throws IOException, XmlMappingException { if (result instanceof DOMResult) { marshalDomResult(graph, (DOMResult) result); } else if (StaxUtils.isStaxResult(result)) { marshalStaxResult(graph, result); } else if (result instanceof SAXResult) { marshalSaxResult(graph, (SAXResult) result); } else if (result instanceof StreamResult) { marshalStreamResult(graph, (StreamResult) result); } else { throw new IllegalArgumentException("Unknown Result type: " + result.getClass()); } }
Example #16
Source File: Jaxb2Marshaller.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void marshal(Object graph, Result result, MimeContainer mimeContainer) throws XmlMappingException { try { Marshaller marshaller = createMarshaller(); if (this.mtomEnabled && mimeContainer != null) { marshaller.setAttachmentMarshaller(new Jaxb2AttachmentMarshaller(mimeContainer)); } if (StaxUtils.isStaxResult(result)) { marshalStaxResult(marshaller, graph, result); } else { marshaller.marshal(graph, result); } } catch (JAXBException ex) { throw convertJaxbException(ex); } }
Example #17
Source File: AbstractMarshaller.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Template method for handling {@code StaxSource}s. * <p>This implementation delegates to {@code unmarshalXmlStreamReader} or * {@code unmarshalXmlEventReader}. * @param staxSource the {@code StaxSource} * @return the object graph * @throws XmlMappingException if the given source cannot be mapped to an object */ protected Object unmarshalStaxSource(Source staxSource) throws XmlMappingException { XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource); if (streamReader != null) { return unmarshalXmlStreamReader(streamReader); } else { XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource); if (eventReader != null) { return unmarshalXmlEventReader(eventReader); } else { throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader"); } } }
Example #18
Source File: AbstractMarshaller.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Unmarshals the given provided {@code javax.xml.transform.Source} into an object graph. * <p>This implementation inspects the given result, and calls {@code unmarshalDomSource}, * {@code unmarshalSaxSource}, or {@code unmarshalStreamSource}. * @param source the source to marshal from * @return the object graph * @throws IOException if an I/O Exception occurs * @throws XmlMappingException if the given source cannot be mapped to an object * @throws IllegalArgumentException if {@code source} is neither a {@code DOMSource}, * a {@code SAXSource}, nor a {@code StreamSource} * @see #unmarshalDomSource(javax.xml.transform.dom.DOMSource) * @see #unmarshalSaxSource(javax.xml.transform.sax.SAXSource) * @see #unmarshalStreamSource(javax.xml.transform.stream.StreamSource) */ @Override public final Object unmarshal(Source source) throws IOException, XmlMappingException { if (source instanceof DOMSource) { return unmarshalDomSource((DOMSource) source); } else if (StaxUtils.isStaxSource(source)) { return unmarshalStaxSource(source); } else if (source instanceof SAXSource) { return unmarshalSaxSource((SAXSource) source); } else if (source instanceof StreamSource) { return unmarshalStreamSource((StreamSource) source); } else { throw new IllegalArgumentException("Unknown Source type: " + source.getClass()); } }
Example #19
Source File: XmlBeansUnmarshallerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test @Override public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); streamReader.nextTag(); // skip to flights assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"), streamReader.getName()); streamReader.nextTag(); // skip to flight assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"), streamReader.getName()); Source source = StaxUtils.createStaxSource(streamReader); Object flight = unmarshaller.unmarshal(source); testFlight(flight); }
Example #20
Source File: Jaxb2UnmarshallerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test @Override @SuppressWarnings("unchecked") public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); streamReader.nextTag(); // skip to flights streamReader.nextTag(); // skip to flight Source source = StaxUtils.createStaxSource(streamReader); JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source); FlightType flight = element.getValue(); testFlight(flight); }
Example #21
Source File: XStreamMarshallerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void marshalStaxResultXMLStreamWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); Result result = StaxUtils.createStaxResult(streamWriter); marshaller.marshal(flight, result); assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString()); }
Example #22
Source File: XStreamMarshallerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void marshalStaxResultXMLEventWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer); Result result = StaxUtils.createStaxResult(eventWriter); marshaller.marshal(flight, result); assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString()); }
Example #23
Source File: XStreamUnmarshallerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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); }
Example #24
Source File: XStreamMarshallerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void marshalStaxResultXMLStreamWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); Result result = StaxUtils.createStaxResult(streamWriter); marshaller.marshal(flight, result); assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING)); }
Example #25
Source File: JibxMarshaller.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected Object unmarshalXmlEventReader(XMLEventReader eventReader) { try { XMLStreamReader streamReader = StaxUtils.createEventStreamReader(eventReader); return unmarshalXmlStreamReader(streamReader); } catch (XMLStreamException ex) { return new UnmarshallingFailureException("JiBX unmarshalling exception", ex); } }
Example #26
Source File: AbstractMarshallerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void marshalStaxResultEventWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer); Result result = StaxUtils.createStaxResult(eventWriter); marshaller.marshal(flights, result); assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING)); }
Example #27
Source File: AbstractMarshallerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void marshalStaxResultStreamWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); Result result = StaxUtils.createStaxResult(streamWriter); marshaller.marshal(flights, result); assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING)); }
Example #28
Source File: XStreamUnmarshallerTests.java From java-technology-stack with MIT License | 5 votes |
@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); }
Example #29
Source File: XStreamMarshallerTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void marshalStaxResultXMLEventWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer); Result result = StaxUtils.createStaxResult(eventWriter); marshaller.marshal(flight, result); assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING)); }
Example #30
Source File: Jaxb2Marshaller.java From java-technology-stack with MIT License | 5 votes |
private void marshalStaxResult(Marshaller jaxbMarshaller, Object graph, Result staxResult) throws JAXBException { XMLStreamWriter streamWriter = StaxUtils.getXMLStreamWriter(staxResult); if (streamWriter != null) { jaxbMarshaller.marshal(graph, streamWriter); } else { XMLEventWriter eventWriter = StaxUtils.getXMLEventWriter(staxResult); if (eventWriter != null) { jaxbMarshaller.marshal(graph, eventWriter); } else { throw new IllegalArgumentException("StAX Result contains neither XMLStreamWriter nor XMLEventConsumer"); } } }