Search in sources :

Example 21 with OMText

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

the class TestSetTextQNameWithExistingChildren method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("TestElement", null);
    // Add some children of various types
    factory.createOMText(element, "some text");
    factory.createOMText(element, "cdata section", OMNode.CDATA_SECTION_NODE);
    factory.createOMComment(element, "comment");
    factory.createOMProcessingInstruction(element, "piTarget", "piData");
    factory.createOMElement("child", null, element);
    QName qname = new QName("urn:ns1", "test", "ns");
    element.setText(qname);
    assertEquals("ns:test", element.getText());
    // Check that OMElement#setText() has created the expected nodes
    OMNode child = element.getFirstOMChild();
    assertTrue(child instanceof OMText);
    assertSame(element, child.getParent());
    assertEquals("ns:test", ((OMText) child).getText());
    assertNull(child.getNextOMSibling());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) QName(javax.xml.namespace.QName) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 22 with OMText

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

the class TestAddChild method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", null);
    OMText text = factory.createOMText("test");
    element.addChild(text);
    assertSame(element, text.getParent());
    assertSame(text, element.getFirstOMChild());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 23 with OMText

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

the class TestAddChildWithParent method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element1 = factory.createOMElement("test1", null);
    OMElement element2 = factory.createOMElement("test2", null);
    OMText text = factory.createOMText("test");
    element1.addChild(text);
    element2.addChild(text);
    assertSame(element2, text.getParent());
    assertNull(element1.getFirstOMChild());
    assertSame(text, element2.getFirstOMChild());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 24 with OMText

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

the class TestDataHandlerExpansion method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    JAXBContext context = JAXBContext.newInstance(DocumentBean.class);
    DataHandler dh = new DataHandler("some content", "text/plain");
    DocumentBean object = new DocumentBean();
    object.setId("123456");
    object.setContent(dh);
    OMElement element = factory.createOMElement(new JAXBOMDataSource(context, object));
    OMElement child = (OMElement) element.getFirstOMChild();
    assertEquals("id", child.getLocalName());
    assertEquals("123456", child.getText());
    child = (OMElement) child.getNextOMSibling();
    assertEquals("content", child.getLocalName());
    OMText content = (OMText) child.getFirstOMChild();
    assertTrue(content.isBinary());
    assertTrue(content.isOptimized());
    assertSame(dh, content.getDataHandler());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) DocumentBean(org.apache.axiom.ts.jaxb.beans.DocumentBean) OMText(org.apache.axiom.om.OMText) JAXBContext(javax.xml.bind.JAXBContext) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) JAXBOMDataSource(org.apache.axiom.om.ds.jaxb.JAXBOMDataSource)

Example 25 with OMText

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

the class TestInsertSiblingBeforeSameParent method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory fac = metaFactory.getOMFactory();
    OMElement parent = fac.createOMElement("test", null);
    OMText text1 = fac.createOMText("text1");
    OMText text2 = fac.createOMText("text2");
    OMText text3 = fac.createOMText("text3");
    parent.addChild(text1);
    parent.addChild(text2);
    parent.addChild(text3);
    text2.insertSiblingBefore(text3);
    assertSame(parent, text3.getParent());
    Iterator<OMNode> it = parent.getChildren();
    assertSame(text1, it.next());
    assertSame(text3, it.next());
    assertSame(text2, it.next());
    assertFalse(it.hasNext());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMText (org.apache.axiom.om.OMText)92 OMElement (org.apache.axiom.om.OMElement)62 OMFactory (org.apache.axiom.om.OMFactory)39 DataHandler (javax.activation.DataHandler)26 OMNode (org.apache.axiom.om.OMNode)21 OMNamespace (org.apache.axiom.om.OMNamespace)10 QName (javax.xml.namespace.QName)8 OMException (org.apache.axiom.om.OMException)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 InputStream (java.io.InputStream)6 OMAttribute (org.apache.axiom.om.OMAttribute)6 Entry (org.apache.synapse.config.Entry)6 ArrayList (java.util.ArrayList)5 DataSource (javax.activation.DataSource)5 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)5 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)5 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)5 OutputStream (java.io.OutputStream)4 StringReader (java.io.StringReader)4