Search in sources :

Example 21 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.

the class TestGetAllDeclaredNamespaces method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMSourcedElement element = factory.createOMElement(new PullOMDataSource("<root xmlns:p='urn:ns1'/>"), "root", null);
    Iterator<OMNamespace> attributes = element.getAllDeclaredNamespaces();
    assertThat(attributes.hasNext()).isTrue();
    OMNamespace ns = attributes.next();
    assertThat(ns.getPrefix()).isEqualTo("p");
    assertThat(ns.getNamespaceURI()).isEqualTo("urn:ns1");
    assertThat(attributes.hasNext()).isFalse();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) OMNamespace(org.apache.axiom.om.OMNamespace) OMSourcedElement(org.apache.axiom.om.OMSourcedElement)

Example 22 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.

the class TestName1QualifiedPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory f = metaFactory.getOMFactory();
    // Create OMSE with an unknown prefix
    OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
    OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", null);
    OMElement element = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT2.getContent()), "library", ns);
    OMElement root = f.createOMElement("root", rootNS);
    root.addChild(element);
    // Test getting the local name and namespace URI. This should used not result in expansion
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
    // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
    StringWriter writer = new StringWriter();
    root.serialize(writer);
    String result = writer.toString();
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
    assertTrue(element.getNamespace().getPrefix().equals("pre"));
    assertTrue(element.getDefaultNamespace() == null);
    assertTrue(result.indexOf("xmlns=") < // Make sure that the serialized string does not contain default prefix declaration
    0);
    assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
    // Serialize again
    writer = new StringWriter();
    root.serialize(writer);
    result = writer.toString();
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
    assertTrue(element.getNamespace().getPrefix().equals("pre"));
    assertTrue(result.indexOf("xmlns=") < // Make sure that the serialized string does not contain default prefix declaration
    0);
    assertTrue(element.getDefaultNamespace() == null);
    assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) StringWriter(java.io.StringWriter) OMElement(org.apache.axiom.om.OMElement)

Example 23 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.

the class TestName2DefaultPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory f = metaFactory.getOMFactory();
    // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
    OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
    OMNamespace ns = f.createOMNamespace("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
    OMElement element = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT1.getContent()), "library", ns);
    OMElement root = f.createOMElement("root", rootNS);
    root.addChild(element);
    // Test getting the namespace, localpart and prefix.  This should used not result in expansion
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
    assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
    // Serialize and consume.  This should not cause expansion and currently won't update
    // the name of the element.
    StringWriter writer = new StringWriter();
    root.serializeAndConsume(writer);
    String result = writer.toString();
    assertTrue(element.getLocalName().equals("library"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
    assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
    assertTrue(result.indexOf("DUMMYPREFIX") < // Make sure that the serialized string does not contain DUMMYPREFIX
    0);
    assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) StringWriter(java.io.StringWriter) OMElement(org.apache.axiom.om.OMElement)

Example 24 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.

the class TestCloseWithoutCaching method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement root = factory.createOMElement("root", null);
    PullOMDataSource ds = new PullOMDataSource("<child>content</child>");
    root.addChild(factory.createOMElement(ds));
    XMLStreamReader reader = root.getXMLStreamReaderWithoutCaching();
    for (int i = 0; i < events; i++) {
        reader.next();
    }
    reader.close();
    assertFalse(ds.hasUnclosedReaders());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) AbstractPullOMDataSource(org.apache.axiom.om.ds.AbstractPullOMDataSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) OMElement(org.apache.axiom.om.OMElement)

Example 25 with PullOMDataSource

use of org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource in project webservices-axiom by apache.

the class TestName4QualifiedPrefix method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory f = metaFactory.getOMFactory();
    // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
    OMNamespace rootNS = f.createOMNamespace("http://sampleroot", "rootPrefix");
    OMNamespace ns = f.createOMNamespace("http://DUMMYNS", "");
    OMElement element = f.createOMElement(new PullOMDataSource(TestDocument.DOCUMENT2.getContent()), "DUMMYNAME", ns);
    OMElement root = f.createOMElement("root", rootNS);
    root.addChild(element);
    // Test getting the namespace, localpart and prefix.  This should used not result in expansion
    assertTrue(element.getLocalName().equals("DUMMYNAME"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
    assertTrue(element.getNamespace().getPrefix().equals(""));
    // Serialize and consume.  This should not cause expansion and currently won't update
    // the name of the element.
    StringWriter writer = new StringWriter();
    root.serializeAndConsume(writer);
    String result = writer.toString();
    assertTrue(element.getLocalName().equals("DUMMYNAME"));
    assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
    assertTrue(element.getNamespace().getPrefix().equals(""));
    assertTrue(result.indexOf("DUMMY") < // Make sure that the serialized string does not contain the DUMMY values
    0);
    assertTrue(result.indexOf("xmlns=") < // Make sure that the serialized string does not contain the default prefix declaration
    0);
    assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) PullOMDataSource(org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource) StringWriter(java.io.StringWriter) OMElement(org.apache.axiom.om.OMElement)

Aggregations

PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)29 OMFactory (org.apache.axiom.om.OMFactory)26 OMElement (org.apache.axiom.om.OMElement)18 OMNamespace (org.apache.axiom.om.OMNamespace)16 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)14 StringWriter (java.io.StringWriter)13 QName (javax.xml.namespace.QName)4 OMAttribute (org.apache.axiom.om.OMAttribute)3 OMDataSource (org.apache.axiom.om.OMDataSource)3 StringReader (java.io.StringReader)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 OMNode (org.apache.axiom.om.OMNode)2 AbstractPullOMDataSource (org.apache.axiom.om.ds.AbstractPullOMDataSource)2 OMContainer (org.apache.axiom.om.OMContainer)1 AbstractPushOMDataSource (org.apache.axiom.om.ds.AbstractPushOMDataSource)1 XML (org.apache.axiom.ts.dimension.serialization.XML)1 PushOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PushOMDataSource)1 InputSource (org.xml.sax.InputSource)1