Search in sources :

Example 71 with XMLStreamWriter

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);
}
Also used : OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 72 with XMLStreamWriter

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);
}
Also used : OMComment(org.apache.axiom.om.OMComment) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 73 with XMLStreamWriter

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());
}
Also used : XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMDocument(org.apache.axiom.om.OMDocument)

Example 74 with XMLStreamWriter

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);
    }
}
Also used : OMDataSource(org.apache.axiom.om.OMDataSource) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) CustomBuilderSupport(org.apache.axiom.om.ds.custombuilder.CustomBuilderSupport) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) CustomBuilder(org.apache.axiom.om.ds.custombuilder.CustomBuilder) SOAPBody(org.apache.axiom.soap.SOAPBody) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StringReader(java.io.StringReader) AbstractPushOMDataSource(org.apache.axiom.om.ds.AbstractPushOMDataSource) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) OMException(org.apache.axiom.om.OMException)

Example 75 with XMLStreamWriter

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);
    }
}
Also used : IndentingXMLStreamWriter(com.sun.xml.txw2.output.IndentingXMLStreamWriter) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) Marshaller(javax.xml.bind.Marshaller) CDataXMLStreamWriter(com.buschmais.jqassistant.core.rule.impl.reader.CDataXMLStreamWriter) XMLStreamException(javax.xml.stream.XMLStreamException) IndentingXMLStreamWriter(com.sun.xml.txw2.output.IndentingXMLStreamWriter) CDataXMLStreamWriter(com.buschmais.jqassistant.core.rule.impl.reader.CDataXMLStreamWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) JAXBException(javax.xml.bind.JAXBException)

Aggregations

XMLStreamWriter (javax.xml.stream.XMLStreamWriter)82 XMLStreamException (javax.xml.stream.XMLStreamException)36 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)28 StringWriter (java.io.StringWriter)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 IOException (java.io.IOException)12 XmlWriter (org.apache.aries.blueprint.plugin.spi.XmlWriter)7 OutputStream (java.io.OutputStream)6 StAXResult (javax.xml.transform.stax.StAXResult)6 Test (org.junit.Test)6 OutputStreamWriter (java.io.OutputStreamWriter)5 JAXBException (javax.xml.bind.JAXBException)5 StreamResult (javax.xml.transform.stream.StreamResult)5 ZipEntry (java.util.zip.ZipEntry)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)3 StringReader (java.io.StringReader)3 ToXmlGenerator (com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator)2 IManifest (com.intel.mountwilson.manifest.data.IManifest)2 Headers (com.sun.net.httpserver.Headers)2