Search in sources :

Example 1 with StAXResult

use of javax.xml.transform.stax.StAXResult in project spring-framework by spring-projects.

the class StaxUtilsTests method isStaxResultJaxp14.

@Test
public void isStaxResultJaxp14() throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
    StAXResult result = new StAXResult(streamWriter);
    assertTrue("Not a StAX Result", StaxUtils.isStaxResult(result));
}
Also used : StAXResult(javax.xml.transform.stax.StAXResult) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Test(org.junit.Test)

Example 2 with StAXResult

use of javax.xml.transform.stax.StAXResult in project voltdb by VoltDB.

the class JDBCSQLXML method createStAXResult.

/**
     *  Retrieves a new DOMResult for setting the XML value designated by this
     *  SQLXML instance.
     *
     *  @param resultClass The class of the result, or null.
     *  @throws java.sql.SQLException if there is an error processing the XML
     *          value
     *  @return for setting the XML value designated by this SQLXML instance.
     */
@SuppressWarnings("unchecked")
protected <T extends Result> T createStAXResult(Class<T> resultClass) throws SQLException {
    StAXResult result = null;
    OutputStream outputStream = this.setBinaryStreamImpl();
    Constructor ctor;
    XMLOutputFactory factory;
    XMLStreamWriter xmlStreamWriter;
    try {
        factory = XMLOutputFactory.newInstance();
        xmlStreamWriter = factory.createXMLStreamWriter(outputStream);
        if (resultClass == null) {
            result = new StAXResult(xmlStreamWriter);
        } else {
            ctor = resultClass.getConstructor(XMLStreamWriter.class);
            result = (StAXResult) ctor.newInstance(xmlStreamWriter);
        }
    } catch (SecurityException ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (IllegalArgumentException ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (IllegalAccessException ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (InvocationTargetException ex) {
        throw Exceptions.resultInstantiation(ex.getTargetException());
    } catch (FactoryConfigurationError ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (InstantiationException ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (NoSuchMethodException ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (XMLStreamException ex) {
        throw Exceptions.resultInstantiation(ex);
    }
    return (T) result;
}
Also used : StAXResult(javax.xml.transform.stax.StAXResult) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) Constructor(java.lang.reflect.Constructor) GZIPOutputStream(java.util.zip.GZIPOutputStream) ClosableByteArrayOutputStream(org.hsqldb_voltpatches.lib.ClosableByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError)

Example 3 with StAXResult

use of javax.xml.transform.stax.StAXResult in project spring-framework by spring-projects.

the class AbstractMarshallerTests method marshalJaxp14StaxResultStreamWriter.

@Test
public void marshalJaxp14StaxResultStreamWriter() throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    StringWriter writer = new StringWriter();
    XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
    StAXResult result = new StAXResult(streamWriter);
    marshaller.marshal(flights, result);
    assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
Also used : StAXResult(javax.xml.transform.stax.StAXResult) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Test(org.junit.Test)

Example 4 with StAXResult

use of javax.xml.transform.stax.StAXResult in project spring-framework by spring-projects.

the class AbstractMarshallerTests method marshalJaxp14StaxResultEventWriter.

@Test
public void marshalJaxp14StaxResultEventWriter() throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    StringWriter writer = new StringWriter();
    XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
    StAXResult result = new StAXResult(eventWriter);
    marshaller.marshal(flights, result);
    assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
Also used : StAXResult(javax.xml.transform.stax.StAXResult) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLEventWriter(javax.xml.stream.XMLEventWriter) Test(org.junit.Test)

Example 5 with StAXResult

use of javax.xml.transform.stax.StAXResult in project voltdb by VoltDB.

the class JDBCSQLXML method createSAXResult.

/**
     *  Retrieves a new SAXResult for setting the XML value designated by this
     *  SQLXML instance.
     *
     *  @param resultClass The class of the result, or null.
     *  @throws java.sql.SQLException if there is an error processing the XML
     *          value
     *  @return for setting the XML value designated by this SQLXML instance.
     */
@SuppressWarnings("unchecked")
protected <T extends Result> T createSAXResult(Class<T> resultClass) throws SQLException {
    SAXResult result = null;
    try {
        result = (resultClass == null) ? new SAXResult() : (SAXResult) resultClass.newInstance();
    } catch (SecurityException ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (InstantiationException ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (IllegalAccessException ex) {
        throw Exceptions.resultInstantiation(ex);
    } catch (ClassCastException ex) {
        throw Exceptions.resultInstantiation(ex);
    }
    StAXResult staxResult = createStAXResult(null);
    XMLStreamWriter xmlWriter = staxResult.getXMLStreamWriter();
    SAX2XMLStreamWriter handler = new SAX2XMLStreamWriter(xmlWriter);
    result.setHandler(handler);
    return (T) result;
}
Also used : StAXResult(javax.xml.transform.stax.StAXResult) SAXResult(javax.xml.transform.sax.SAXResult) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Aggregations

StAXResult (javax.xml.transform.stax.StAXResult)5 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)4 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)4 StringWriter (java.io.StringWriter)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 FactoryConfigurationError (javax.xml.parsers.FactoryConfigurationError)1 XMLEventWriter (javax.xml.stream.XMLEventWriter)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 SAXResult (javax.xml.transform.sax.SAXResult)1 ClosableByteArrayOutputStream (org.hsqldb_voltpatches.lib.ClosableByteArrayOutputStream)1