Search in sources :

Example 26 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestGetSAXSourceIdentityTransformOnFragment method runTest.

@Override
protected void runTest() throws Throwable {
    Transformer transformer = xsltImplementation.newTransformerFactory().newTransformer();
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, getInput()).getDocumentElement().getFirstElement();
    OMDocument outputDocument = factory.createOMDocument();
    transformer.transform(element.getSAXSource(cache), outputDocument.getSAXResult());
    OMNamespace ns = outputDocument.getOMDocumentElement().findNamespaceURI("p");
    assertNotNull(ns);
    assertEquals("urn:some:namespace", ns.getNamespaceURI());
    element.close(false);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) Transformer(javax.xml.transform.Transformer) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 27 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class AxiomTraverser method next.

@Override
public Event next() throws TraverserException {
    if (node == null) {
        if (root instanceof OMDocument) {
            node = ((OMDocument) root).getFirstOMChild();
        } else {
            node = (OMElement) root;
        }
    } else if (!visited && node instanceof OMElement) {
        OMNode firstChild = ((OMElement) node).getFirstOMChild();
        if (firstChild != null) {
            node = firstChild;
        } else {
            visited = true;
        }
    } else {
        OMNode nextSibling = node.getNextOMSibling();
        if (node == root) {
            return null;
        } else if (nextSibling != null) {
            node = nextSibling;
            visited = false;
        } else {
            OMContainer parent = node.getParent();
            if (parent instanceof OMDocument) {
                return null;
            } else {
                node = (OMElement) parent;
                visited = true;
            }
        }
    }
    switch(node.getType()) {
        case OMNode.DTD_NODE:
            return Event.DOCUMENT_TYPE;
        case OMNode.ELEMENT_NODE:
            return visited ? Event.END_ELEMENT : Event.START_ELEMENT;
        case OMNode.TEXT_NODE:
            return Event.TEXT;
        case OMNode.SPACE_NODE:
            return Event.WHITESPACE;
        case OMNode.ENTITY_REFERENCE_NODE:
            if (expandEntityReferences) {
                throw new UnsupportedOperationException();
            } else {
                return Event.ENTITY_REFERENCE;
            }
        case OMNode.COMMENT_NODE:
            return Event.COMMENT;
        case OMNode.CDATA_SECTION_NODE:
            return Event.CDATA_SECTION;
        case OMNode.PI_NODE:
            return Event.PROCESSING_INSTRUCTION;
        default:
            throw new IllegalStateException();
    }
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) OMContainer(org.apache.axiom.om.OMContainer) OMDocument(org.apache.axiom.om.OMDocument)

Example 28 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestClone method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = soapFactory.createSOAPMessage();
    message.addChild(soapFactory.getDefaultEnvelope());
    OMCloneOptions options = new OMCloneOptions();
    options.setPreserveModel(preserveModel);
    OMInformationItem clone = message.clone(options);
    if (preserveModel) {
        assertTrue(clone instanceof SOAPMessage);
    } else {
        assertTrue(clone instanceof OMDocument);
        assertFalse(clone instanceof SOAPMessage);
    }
    OMElement envelope = ((OMDocument) clone).getOMDocumentElement();
    if (preserveModel) {
        assertTrue(envelope instanceof SOAPEnvelope);
    } else {
        assertFalse(envelope instanceof SOAPEnvelope);
    }
    assertEquals("Envelope", envelope.getLocalName());
    assertEquals(spec.getEnvelopeNamespaceURI(), envelope.getNamespaceURI());
}
Also used : OMInformationItem(org.apache.axiom.om.OMInformationItem) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPMessage(org.apache.axiom.soap.SOAPMessage) OMDocument(org.apache.axiom.om.OMDocument)

Example 29 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestCloneIncomplete method runTest.

@Override
protected void runTest() throws Throwable {
    SOAPMessage message = SOAPSampleSet.WSA.getMessage(spec).getAdapter(SOAPSampleAdapter.class).getSOAPMessage(metaFactory);
    OMCloneOptions options = new OMCloneOptions();
    options.setPreserveModel(preserveModel);
    OMInformationItem clone = message.clone(options);
    if (preserveModel) {
        assertTrue(clone instanceof SOAPMessage);
        assertSame(soapFactory, clone.getOMFactory());
    } else {
        assertTrue(clone instanceof OMDocument);
        assertFalse(clone instanceof SOAPMessage);
    }
}
Also used : OMInformationItem(org.apache.axiom.om.OMInformationItem) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) SOAPSampleAdapter(org.apache.axiom.ts.soap.SOAPSampleAdapter) SOAPMessage(org.apache.axiom.soap.SOAPMessage) OMDocument(org.apache.axiom.om.OMDocument)

Example 30 with OMDocument

use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.

the class TestGetSAXResult method runTest.

@Override
protected void runTest() throws Throwable {
    TransformerFactory transformerFactory = xsltImplementation.newTransformerFactory();
    StreamSource source = new StreamSource(file.getUrl().toString());
    OMDocument document = metaFactory.getOMFactory().createOMDocument();
    SAXResult result = document.getSAXResult();
    transformerFactory.newTransformer().transform(source, result);
    assertAbout(xml()).that(xml(OMDocument.class, document)).ignoringWhitespaceInPrologAndEpilog().ignoringRedundantNamespaceDeclarations().expandingEntityReferences().hasSameContentAs(file.getUrl());
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) SAXResult(javax.xml.transform.sax.SAXResult) StreamSource(javax.xml.transform.stream.StreamSource) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMDocument (org.apache.axiom.om.OMDocument)51 OMElement (org.apache.axiom.om.OMElement)19 OMFactory (org.apache.axiom.om.OMFactory)18 StringReader (java.io.StringReader)13 OMNode (org.apache.axiom.om.OMNode)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Document (org.w3c.dom.Document)5 StringWriter (java.io.StringWriter)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 OMCloneOptions (org.apache.axiom.om.OMCloneOptions)3 OMInformationItem (org.apache.axiom.om.OMInformationItem)3 OMNamespace (org.apache.axiom.om.OMNamespace)3 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Transformer (javax.xml.transform.Transformer)2 DTDReader (org.apache.axiom.ext.stax.DTDReader)2 OMAttribute (org.apache.axiom.om.OMAttribute)2 OMComment (org.apache.axiom.om.OMComment)2