Search in sources :

Example 1 with WrappedTextNodeOMDataSourceFromDataSource

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

the class TestGetObject method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new BlobDataSource(Blobs.createBlob("test".getBytes("utf-8")), "text/plain; charset=utf-8");
    OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"), ds, Charset.forName("utf-8")));
    // getObject returns null if the data source is not of the expected type
    assertNull(element.getObject(StringOMDataSource.class));
    // Test with the right data source type
    assertSame(ds, element.getObject(WrappedTextNodeOMDataSourceFromDataSource.class));
    assertSame(ds, element.getObject(WrappedTextNodeOMDataSource.class));
    // Now modify the content of the element
    factory.createOMComment(element, "comment");
    assertNull(element.getObject(WrappedTextNodeOMDataSourceFromDataSource.class));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) BlobDataSource(org.apache.axiom.blob.BlobDataSource) QName(javax.xml.namespace.QName) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) WrappedTextNodeOMDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSource) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) DataSource(javax.activation.DataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) BlobDataSource(org.apache.axiom.blob.BlobDataSource) WrappedTextNodeOMDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSource)

Example 2 with WrappedTextNodeOMDataSourceFromDataSource

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

the class TestCloneNonDestructive method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDataSource ds = new WrappedTextNodeOMDataSourceFromDataSource(new QName("wrapper"), new ByteArrayDataSource("test".getBytes("utf-8")), Charset.forName("utf-8"));
    OMSourcedElement element = factory.createOMElement(ds);
    OMCloneOptions options = new OMCloneOptions();
    options.setCopyOMDataSources(copyOMDataSources);
    OMElement clone = (OMElement) element.clone(options);
    if (copyOMDataSources) {
        assertTrue(clone instanceof OMSourcedElement);
        assertFalse(element.isExpanded());
    } else {
        assertFalse(clone instanceof OMSourcedElement);
        assertTrue(clone.isComplete());
    }
    assertEquals("test", clone.getText());
    assertEquals("wrapper", clone.getLocalName());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMDataSource(org.apache.axiom.om.OMDataSource) QName(javax.xml.namespace.QName) OMCloneOptions(org.apache.axiom.om.OMCloneOptions) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) OMElement(org.apache.axiom.om.OMElement) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) ByteArrayDataSource(org.apache.axiom.attachments.ByteArrayDataSource)

Example 3 with WrappedTextNodeOMDataSourceFromDataSource

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

the class TestGetTextAsStreamWithNonDestructiveOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new RandomDataSource(445566, 32, 128, 20000000);
    QName qname = new QName("a");
    Charset cs = Charset.forName("ascii");
    OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, cs), qname);
    Reader in = element.getTextAsStream(true);
    assertFalse(in instanceof StringReader);
    IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), cs), in);
    assertFalse(element.isExpanded());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) InputStreamReader(java.io.InputStreamReader) QName(javax.xml.namespace.QName) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) StringReader(java.io.StringReader) Charset(java.nio.charset.Charset) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Example 4 with WrappedTextNodeOMDataSourceFromDataSource

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

the class TestWriteTextToWithNonDestructiveOMDataSource method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    DataSource ds = new RandomDataSource(665544, 32, 128, 20000000);
    QName qname = new QName("a");
    OMSourcedElement element = factory.createOMElement(new WrappedTextNodeOMDataSourceFromDataSource(qname, ds, Charset.forName("ascii")), qname);
    Reader in = new InputStreamReader(ds.getInputStream(), "ascii");
    Writer out = new CharacterStreamComparator(in);
    // cache doesn't matter here
    element.writeTextTo(out, true);
    out.close();
    assertFalse(element.isExpanded());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) InputStreamReader(java.io.InputStreamReader) QName(javax.xml.namespace.QName) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) CharacterStreamComparator(org.apache.axiom.testutils.io.CharacterStreamComparator) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) Writer(java.io.Writer) WrappedTextNodeOMDataSourceFromDataSource(org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource) RandomDataSource(org.apache.axiom.testutils.activation.RandomDataSource) DataSource(javax.activation.DataSource)

Aggregations

QName (javax.xml.namespace.QName)4 OMFactory (org.apache.axiom.om.OMFactory)4 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)4 WrappedTextNodeOMDataSourceFromDataSource (org.apache.axiom.om.ds.WrappedTextNodeOMDataSourceFromDataSource)4 DataSource (javax.activation.DataSource)3 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 RandomDataSource (org.apache.axiom.testutils.activation.RandomDataSource)2 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 Charset (java.nio.charset.Charset)1 ByteArrayDataSource (org.apache.axiom.attachments.ByteArrayDataSource)1 BlobDataSource (org.apache.axiom.blob.BlobDataSource)1 OMCloneOptions (org.apache.axiom.om.OMCloneOptions)1 OMDataSource (org.apache.axiom.om.OMDataSource)1 OMElement (org.apache.axiom.om.OMElement)1 StringOMDataSource (org.apache.axiom.om.ds.StringOMDataSource)1 WrappedTextNodeOMDataSource (org.apache.axiom.om.ds.WrappedTextNodeOMDataSource)1 CharacterStreamComparator (org.apache.axiom.testutils.io.CharacterStreamComparator)1