Search in sources :

Example 1 with OMDocument

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

the class DOOMDocumentBuilder method parse.

public Document parse(InputSource inputSource) throws SAXException, IOException {
    OMDocument document = ((OMMetaFactorySPI) factory.getMetaFactory()).createOMBuilder(parserConfiguration, inputSource).getDocument();
    document.close(true);
    return (Document) document;
}
Also used : DOMDocument(org.apache.axiom.dom.DOMDocument) Document(org.w3c.dom.Document) OMDocument(org.apache.axiom.om.OMDocument) DOMDocument(org.apache.axiom.dom.DOMDocument) OMDocument(org.apache.axiom.om.OMDocument)

Example 2 with OMDocument

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

the class MTOMStAXSOAPModelBuilderTest method testDeferredLoadingOfAttachments.

/**
     * Test that MIME parts are not loaded before requesting the DataHandlers from the corresponding
     * OMText nodes.
     *  
     * @throws Exception
     */
public void testDeferredLoadingOfAttachments() throws Exception {
    Attachments attachments = createAttachmentsForTestMTOMMessage();
    SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments);
    OMDocument doc = builder.getDocument();
    // Find all the binary nodes
    List<OMText> binaryNodes = new ArrayList<>();
    for (Iterator<OMSerializable> it = doc.getDescendants(false); it.hasNext(); ) {
        OMSerializable node = it.next();
        if (node instanceof OMText) {
            OMText text = (OMText) node;
            if (text.isBinary()) {
                binaryNodes.add(text);
            }
        }
    }
    assertFalse(binaryNodes.isEmpty());
    // At this moment only the SOAP part should have been loaded
    assertEquals(1, attachments.getContentIDList().size());
    for (OMText node : binaryNodes) {
        // Request the DataHandler and do something with it to make sure
        // the part is loaded
        node.getDataHandler().getInputStream().close();
    }
    assertEquals(binaryNodes.size() + 1, attachments.getContentIDList().size());
}
Also used : ArrayList(java.util.ArrayList) OMText(org.apache.axiom.om.OMText) OMSerializable(org.apache.axiom.om.OMSerializable) SOAPModelBuilder(org.apache.axiom.soap.SOAPModelBuilder) Attachments(org.apache.axiom.attachments.Attachments) OMDocument(org.apache.axiom.om.OMDocument)

Example 3 with OMDocument

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

the class TestAppendChildForbidden method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument omDocument = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<test/>")).getDocument();
    if (build) {
        omDocument.build();
    }
    Document document = (Document) omDocument;
    try {
        document.appendChild(document.createElementNS(null, "test"));
        fail("Expected DOMException");
    } catch (DOMException ex) {
        assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) OMDocument(org.apache.axiom.om.OMDocument) OMDocument(org.apache.axiom.om.OMDocument)

Example 4 with OMDocument

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

the class TestGetOMFactory1 method runTest.

@Override
protected void runTest() throws Throwable {
    Document document = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder().newDocument();
    assertSame(metaFactory.getOMFactory(), ((OMDocument) document).getOMFactory());
}
Also used : DOMMetaFactory(org.apache.axiom.om.dom.DOMMetaFactory) Document(org.w3c.dom.Document) OMDocument(org.apache.axiom.om.OMDocument)

Example 5 with OMDocument

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

the class TestInsertBeforeForbidden method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument omDocument = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<!--test--><test/>")).getDocument();
    if (build) {
        omDocument.build();
    }
    Document document = (Document) omDocument;
    Comment comment = (Comment) document.getFirstChild();
    try {
        document.insertBefore(document.createElementNS(null, "test"), comment);
        fail("Expected DOMException");
    } catch (DOMException ex) {
        assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
    }
}
Also used : Comment(org.w3c.dom.Comment) DOMException(org.w3c.dom.DOMException) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) OMDocument(org.apache.axiom.om.OMDocument) 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