Search in sources :

Example 56 with OMText

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

the class TestCloneBinary method runTest.

@Override
protected void runTest() throws Throwable {
    DataHandler dh = new DataHandler(new RandomDataSource(600613L, 4096));
    StringReader rootPart = new StringReader("<root><xop:Include xmlns:xop='http://www.w3.org/2004/08/xop/include' href='cid:123456@example.org'/></root>");
    DummyAttachmentAccessor attachmentAccessor = new DummyAttachmentAccessor("123456@example.org", dh);
    OMElement root = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StreamSource(rootPart), attachmentAccessor).getDocumentElement();
    OMText text = (OMText) root.getFirstOMChild();
    OMCloneOptions options = new OMCloneOptions();
    options.setFetchDataHandlers(fetch);
    OMText clone = (OMText) text.clone(options);
    assertTrue(clone.isBinary());
    assertEquals(fetch, attachmentAccessor.isLoaded());
    assertSame(dh, clone.getDataHandler());
}
Also used : RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) DataHandler(javax.activation.DataHandler)

Example 57 with OMText

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

the class TestGetNamespace method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement element = factory.createOMElement("element", null);
    element.declareNamespace("urn:ns", "p");
    OMText text = factory.createOMText(element, "p:value");
    OMNamespace ns = text.getNamespace();
    assertEquals("urn:ns", ns.getNamespaceURI());
    assertEquals("p", ns.getPrefix());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 58 with OMText

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

the class TestSetOptimize method runTest.

@Override
protected void runTest() throws Throwable {
    InputStream in = XOP_SPEC_SAMPLE.getInputStream();
    try {
        OMDocument document = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, MultipartBody.builder().setInputStream(in).setContentType(XOP_SPEC_SAMPLE.getContentType()).build()).getDocument();
        for (Iterator<OMSerializable> it = document.getDescendants(false); it.hasNext(); ) {
            OMSerializable node = it.next();
            if (node instanceof OMText) {
                OMText text = (OMText) node;
                if (text.isBinary()) {
                    text.setOptimize(optimize);
                }
            }
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        OMOutputFormat format = new OMOutputFormat();
        format.setDoOptimize(true);
        document.serialize(out, format);
        Multipart mp = new MimeMultipart(new ByteArrayDataSource(out.toByteArray(), format.getContentType()));
        assertThat(mp.getCount()).isEqualTo(optimize ? 3 : 1);
    } finally {
        in.close();
    }
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) Multipart(javax.mail.Multipart) MimeMultipart(javax.mail.internet.MimeMultipart) InputStream(java.io.InputStream) OMText(org.apache.axiom.om.OMText) OMSerializable(org.apache.axiom.om.OMSerializable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) OMDocument(org.apache.axiom.om.OMDocument)

Example 59 with OMText

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

the class WriteCharactersCharArrayScenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) {
    OMNode child = element.getFirstOMChild();
    Assert.assertTrue(child instanceof OMText);
    Assert.assertEquals("test", ((OMText) child).getText());
    child = child.getNextOMSibling();
    Assert.assertTrue(child instanceof OMText);
    Assert.assertEquals("case", ((OMText) child).getText());
    Assert.assertNull(child.getNextOMSibling());
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText)

Example 60 with OMText

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

the class WriteDataHandlerProviderScenario method validate.

@Override
public void validate(OMElement element, boolean dataHandlersPreserved) throws Throwable {
    OMText child = (OMText) element.getFirstOMChild();
    if (dataHandlersPreserved) {
        Assert.assertTrue(child.isBinary());
        Assert.assertSame(dh, child.getDataHandler());
    } else {
        child.setBinary(true);
        IOTestUtils.compareStreams(dh.getInputStream(), child.getDataHandler().getInputStream());
    }
}
Also used : OMText(org.apache.axiom.om.OMText)

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