Search in sources :

Example 51 with OMText

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

the class TestInsertSiblingBefore 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");
    parent.addChild(text1);
    text1.insertSiblingBefore(text2);
    assertSame(parent, text2.getParent());
    assertSame(text2, parent.getFirstOMChild());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 52 with OMText

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

the class TestGetDescendants method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMContainer root = containerFactory.create(factory);
    OMElement child1 = factory.createOMElement("child", null, root);
    OMProcessingInstruction child2 = factory.createOMProcessingInstruction(root, "test", "data");
    OMText grandchild1 = factory.createOMText(child1, "text");
    OMComment grandchild2 = factory.createOMComment(child1, "text");
    Iterator<? extends OMSerializable> it = root.getDescendants(includeSelf);
    if (includeSelf) {
        assertThat(it.hasNext()).isTrue();
        assertThat(it.next()).isEqualTo(root);
    }
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(child1);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(grandchild1);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(grandchild2);
    assertThat(it.hasNext()).isTrue();
    assertThat(it.next()).isEqualTo(child2);
    assertThat(it.hasNext()).isFalse();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMComment(org.apache.axiom.om.OMComment) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) OMContainer(org.apache.axiom.om.OMContainer)

Example 53 with OMText

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

the class TestReadAttachmentBeforeRootPartComplete method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    // Programmatically create the message
    OMElement orgRoot = factory.createOMElement("root", null);
    OMElement orgChild1 = factory.createOMElement("child1", null, orgRoot);
    DataSource ds = new RandomDataSource(54321, 4096);
    orgChild1.addChild(factory.createOMText(new DataHandler(ds), true));
    // Create a child with a large text content and insert it after the binary node.
    // If we don't do this, then the root part may be buffered entirely by the parser,
    // and the test would not be effective.
    OMElement orgChild2 = factory.createOMElement("child2", null, orgRoot);
    String s = RandomUtils.randomString(128 * 1024);
    orgChild2.setText(s);
    // Serialize the message
    OMOutputFormat format = new OMOutputFormat();
    format.setDoOptimize(true);
    MemoryBlob blob = Blobs.createMemoryBlob();
    OutputStream out = blob.getOutputStream();
    orgRoot.serialize(out, format);
    out.close();
    // Parse the message
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, StAXParserConfiguration.NON_COALESCING, MultipartBody.builder().setInputStream(blob.getInputStream()).setContentType(format.getContentType()).build());
    OMElement root = builder.getDocumentElement();
    OMElement child1 = (OMElement) root.getFirstOMChild();
    OMText text = (OMText) child1.getFirstOMChild();
    assertTrue(text.isBinary());
    // Access the DataHandler
    DataHandler dh = text.getDataHandler();
    IOTestUtils.compareStreams(ds.getInputStream(), dh.getInputStream());
    OMElement child2 = (OMElement) child1.getNextOMSibling();
    assertFalse(child2.isComplete());
    assertEquals(s, child2.getText());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) MemoryBlob(org.apache.axiom.blob.MemoryBlob) OutputStream(java.io.OutputStream) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 54 with OMText

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

the class TestSetTextWithExistingChildren method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("test", 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);
    // Set the text; this should remove all child nodes
    element.setText("test");
    // Check that OMElement#getText() returns a matching value
    assertEquals("Text value mismatch", "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("test", ((OMText) child).getText());
    assertNull(child.getNextOMSibling());
}
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)

Example 55 with OMText

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

the class TestBase64StreamingWithSerialize method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement elem = factory.createOMElement("test", null);
    // Create a data source that would eat up all memory when loaded. If the test
    // doesn't fail with an OutOfMemoryError, we know that the OMText implementation
    // supports streaming.
    DataSource ds = new TestDataSource('A', Runtime.getRuntime().maxMemory());
    OMText text = factory.createOMText(new DataHandler(ds), false);
    elem.addChild(text);
    elem.serialize(new NullOutputStream());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler) DataSource(javax.activation.DataSource) TestDataSource(org.apache.axiom.testutils.activation.TestDataSource) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

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