use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class TestSerialize method runTest.
@Override
protected void runTest() throws Throwable {
OMProcessingInstruction pi = metaFactory.getOMFactory().createOMProcessingInstruction(null, "target", "data");
XMLStreamWriter writer = mock(XMLStreamWriter.class);
pi.serialize(writer);
verify(writer).writeProcessingInstruction(pi.getTarget() + " ", pi.getValue());
verify(writer, atMost(1)).flush();
verifyNoMoreInteractions(writer);
}
use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class TestSerialize method runTest.
@Override
protected void runTest() throws Throwable {
OMComment comment = metaFactory.getOMFactory().createOMComment(null, "test");
XMLStreamWriter writer = mock(XMLStreamWriter.class);
comment.serialize(writer);
verify(writer).writeComment(comment.getValue());
verify(writer, atMost(1)).flush();
verifyNoMoreInteractions(writer);
}
use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class SerializeToXMLStreamWriter method serialize.
@Override
public XML serialize(OMContainer container) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String encoding = null;
// the output encoding so that it will match the encoding in the XML declaration.
if (container instanceof OMDocument) {
encoding = ((OMDocument) container).getXMLEncoding();
}
if (encoding == null) {
encoding = "UTF-8";
}
XMLStreamWriter writer = StAX.createXMLStreamWriter(baos, encoding);
if (cache) {
container.serialize(writer);
} else {
container.serializeAndConsume(writer);
}
writer.close();
return new XMLAsByteArray(baos.toByteArray());
}
use of javax.xml.stream.XMLStreamWriter in project webservices-axiom by apache.
the class FirstElementNameWithParserTestCase method runTest.
@Override
protected final void runTest() throws Throwable {
SOAPEnvelope orgEnvelope = soapFactory.getDefaultEnvelope();
orgEnvelope.getBody().addChild(soapFactory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(), qname.getPrefix()));
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(metaFactory, new StringReader(orgEnvelope.toString()));
SOAPBody body = builder.getSOAPEnvelope().getBody();
runTest(body);
if (supportsOptimization) {
// The expectation is that even after looking at the payload element name, registering
// a custom builder still transforms the element.
((CustomBuilderSupport) builder).registerCustomBuilder(CustomBuilder.Selector.PAYLOAD, new CustomBuilder() {
@Override
public OMDataSource create(OMElement element) throws OMException {
try {
element.getXMLStreamReaderWithoutCaching().close();
} catch (XMLStreamException ex) {
throw new OMException(ex);
}
return new AbstractPushOMDataSource() {
@Override
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
xmlWriter.writeEmptyElement(qname.getPrefix(), qname.getLocalPart(), qname.getNamespaceURI());
}
@Override
public boolean isDestructiveWrite() {
return false;
}
};
}
});
assertThat(body.getFirstElement()).isInstanceOf(OMSourcedElement.class);
}
}
use of javax.xml.stream.XMLStreamWriter in project jqa-core-framework by buschmais.
the class RuleSetWriterImpl method marshal.
private void marshal(Writer writer, JqassistantRules rules) {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = null;
try {
streamWriter = xof.createXMLStreamWriter(writer);
} catch (XMLStreamException e) {
e.printStackTrace();
}
XMLStreamWriter indentingStreamWriter = new IndentingXMLStreamWriter(new CDataXMLStreamWriter(streamWriter));
try {
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.marshal(rules, indentingStreamWriter);
} catch (JAXBException e) {
throw new IllegalArgumentException("Cannot write rules to " + writer, e);
}
}
Aggregations