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));
}
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;
}
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));
}
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));
}
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;
}
Aggregations