Search in sources :

Example 51 with OMFactory

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

the class TestAddChildWithIncompleteSibling method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMContainer container = containerFactory.create(factory);
    container.addChild(OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<a>test</a>")).getDocumentElement(true));
    assertThat(container.isComplete()).isFalse();
    container.addChild(factory.createOMText("test"));
    assertThat(container).hasNumberOfChildren(2);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMContainer(org.apache.axiom.om.OMContainer)

Example 52 with OMFactory

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

the class TestCreateOMTextCDATASectionWithParent method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("test", null);
    OMText text = factory.createOMText(parent, "cdata section content", OMNode.CDATA_SECTION_NODE);
    assertTrue(text instanceof CDATASection);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) CDATASection(org.w3c.dom.CDATASection) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 53 with OMFactory

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

the class TestGetDataHandlerFromElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    RandomDataSource orgDS = new RandomDataSource(64 * 1024);
    OMElement orgRoot = factory.createOMElement(new QName("root"));
    OMElement orgChild = factory.createOMElement(new QName("child"), orgRoot);
    orgChild.addChild(factory.createOMText(new DataHandler(orgDS), false));
    OMElement root = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader(orgRoot.toString())).getDocumentElement();
    XMLStreamReader reader = root.getXMLStreamReader(cache);
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    DataSource ds = XMLStreamReaderUtils.getDataHandlerFromElement(reader).getDataSource();
    IOTestUtils.compareStreams(orgDS.getInputStream(), ds.getInputStream());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 54 with OMFactory

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

the class TestSetTextQName method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("TestElement", null);
    QName qname = new QName("urn:ns1", "test", "ns");
    element.setText(qname);
    boolean foundNamespace = false;
    for (Iterator<OMNamespace> it = element.getAllDeclaredNamespaces(); it.hasNext(); ) {
        OMNamespace ns = it.next();
        if ("urn:ns1".equals(ns.getNamespaceURI()) && "ns".equals(ns.getPrefix())) {
            foundNamespace = true;
        }
    }
    assertTrue("Namespace of the text is not defined in the parent element", foundNamespace);
    assertTrue(element.toString().contains("ns:test"));
    assertEquals("ns:test", element.getText());
    assertEquals(qname, element.getTextAsQName());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Example 55 with OMFactory

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

the class TestSetTextQNameWithEmptyPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    QName qname = new QName("urn:test", "test");
    element.setText(qname);
    Iterator<OMNamespace> it = element.getAllDeclaredNamespaces();
    assertTrue(it.hasNext());
    OMNamespace ns = it.next();
    assertEquals("urn:test", ns.getNamespaceURI());
    String prefix = ns.getPrefix();
    assertTrue(prefix.length() > 0);
    assertEquals(prefix + ":test", element.getText());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMFactory (org.apache.axiom.om.OMFactory)270 OMElement (org.apache.axiom.om.OMElement)202 OMNamespace (org.apache.axiom.om.OMNamespace)101 QName (javax.xml.namespace.QName)71 StringReader (java.io.StringReader)37 OMText (org.apache.axiom.om.OMText)35 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)32 OMAttribute (org.apache.axiom.om.OMAttribute)31 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)26 StringWriter (java.io.StringWriter)18 OMDocument (org.apache.axiom.om.OMDocument)18 DataHandler (javax.activation.DataHandler)14 XMLStreamReader (javax.xml.stream.XMLStreamReader)14 OMNode (org.apache.axiom.om.OMNode)14 OMException (org.apache.axiom.om.OMException)12 DataSource (javax.activation.DataSource)11 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)9 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)9 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)8 Element (org.w3c.dom.Element)8