Search in sources :

Example 36 with OMDocument

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

the class TestSetOMDocumentElementNew method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    OMComment comment = factory.createOMComment(document, "some comment");
    OMElement documentElement = factory.createOMElement("root", null);
    document.setOMDocumentElement(documentElement);
    assertSame(documentElement, document.getOMDocumentElement());
    assertSame(document, documentElement.getParent());
    Iterator<OMNode> it = document.getChildren();
    assertTrue(it.hasNext());
    assertSame(comment, it.next());
    assertTrue(it.hasNext());
    assertSame(documentElement, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 37 with OMDocument

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

the class TestSetOMDocumentElementReplace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!--comment1--><root/><!--comment2-->")).getDocument();
    OMElement documentElement = factory.createOMElement("new", null);
    document.setOMDocumentElement(documentElement);
    assertSame(documentElement, document.getOMDocumentElement());
    Iterator<OMNode> it = document.getChildren();
    assertTrue(it.hasNext());
    OMNode child = it.next();
    assertTrue(child instanceof OMComment);
    assertEquals("comment1", ((OMComment) child).getValue());
    assertTrue(it.hasNext());
    assertSame(documentElement, it.next());
    assertTrue(it.hasNext());
    child = it.next();
    assertTrue(child instanceof OMComment);
    assertEquals("comment2", ((OMComment) child).getValue());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMComment(org.apache.axiom.om.OMComment) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 38 with OMDocument

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

the class TestDTDReaderFromParser method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.STANDALONE, TestDTDReaderFromParser.class.getResourceAsStream("/web_w_dtd.xml")).getDocument();
    if (build) {
        doc.build();
    }
    XMLStreamReader reader = doc.getXMLStreamReader(cache);
    // Note that according to the specification of the DTDReader interface, it is
    // allowed to look up the extension before reaching the DTD event.
    DTDReader dtdReader = (DTDReader) reader.getProperty(DTDReader.PROPERTY);
    assertNotNull(dtdReader);
    while (reader.next() != XMLStreamReader.DTD) {
    // Just loop
    }
    assertEquals("web-app", dtdReader.getRootName());
    assertEquals("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", dtdReader.getPublicId());
    assertEquals("http://java.sun.com/dtd/web-app_2_3.dtd", dtdReader.getSystemId());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DTDReader(org.apache.axiom.ext.stax.DTDReader) OMDocument(org.apache.axiom.om.OMDocument)

Example 39 with OMDocument

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

the class TestAddChildIncomplete method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument parent = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!--a--><b/><!--c-->")).getDocument();
    parent.addChild(factory.createOMComment(null, "d"));
    Iterator<OMNode> it = parent.getChildren();
    assertEquals("a", ((OMComment) it.next()).getValue());
    assertEquals("b", ((OMElement) it.next()).getLocalName());
    assertEquals("c", ((OMComment) it.next()).getValue());
    assertEquals("d", ((OMComment) it.next()).getValue());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) StringReader(java.io.StringReader) OMDocument(org.apache.axiom.om.OMDocument)

Example 40 with OMDocument

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

the class TestGetOMDocumentElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    OMElement documentElement = factory.createOMElement("root", null, document);
    assertSame(documentElement, document.getOMDocumentElement());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) 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