Search in sources :

Example 11 with OMXMLParserWrapper

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

the class TestGetElementTextFromParser method runTest.

@Override
protected void runTest() throws Throwable {
    // Note: We test getElementText on a child element ("b") of the element from which we request
    //       the XMLStreamReader ("a"). This is to make sure that the XMLStreamReader implementation actually
    //       delegates to the underlying parser (which is not necessarily the case on "a").
    OMXMLParserWrapper builder = builderFactory.getBuilder(metaFactory, new InputSource(new StringReader("<a><b>AB<!--comment text-->CD</b></a>")));
    OMElement element = builder.getDocumentElement();
    // Build a certain number of descendants. This is used to test scenarios where the XMLStreamReader
    // needs to switch to pull through mode in the middle of the element from which we attempt to
    // get the text.
    Iterator<OMNode> it = element.getDescendants(true);
    for (int i = 0; i < build; i++) {
        it.next();
    }
    XMLStreamReader reader = element.getXMLStreamReader(cache);
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    assertEquals("ABCD", reader.getElementText());
}
Also used : OMNode(org.apache.axiom.om.OMNode) InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 12 with OMXMLParserWrapper

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

the class TestAxiom95 method runTest.

@Override
protected void runTest() throws Throwable {
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), TestAxiom95.class.getResourceAsStream("defaultNamespace2.xml"));
    String serializedXML = builder.getDocumentElement().toString();
    //        System.out.println("serializedXML = " + serializedXML);
    assertTrue(serializedXML.indexOf("xmlns=\"\"") == -1);
}
Also used : OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 13 with OMXMLParserWrapper

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

the class TestDiscardIncomplete method runTest.

@Override
protected void runTest() throws Throwable {
    OMElement documentElement = null;
    // first build the OM tree without caching and see whether we can discard
    // an element from it
    // TODO: we shouldn't use a SOAP message here
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), SOAPSampleSet.WSA.getMessage(SOAPSpec.SOAP11).getInputStream());
    documentElement = builder.getDocumentElement();
    documentElement.getFirstElement().discard();
    String envelopeString = documentElement.toStringWithConsume();
    documentElement.close(false);
}
Also used : OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 14 with OMXMLParserWrapper

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

the class TestDetachAfterBuilderClose method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<a><b/></a>"));
    OMElement element = builder.getDocumentElement();
    element.build();
    builder.close();
    // Since the node has been fully built, this should not result in an error
    element.detach();
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Example 15 with OMXMLParserWrapper

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

the class TestGetDocumentFromBuilder method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDataSource ds = new StringOMDataSource("<root><a/></root>");
    OMSourcedElement element = factory.createOMElement(ds);
    // Force expansion
    element.getFirstOMChild();
    OMXMLParserWrapper builder = element.getBuilder();
    try {
        builder.getDocument();
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // Expected
    }
    try {
        builder.getDocumentElement();
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMDataSource(org.apache.axiom.om.OMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) StringOMDataSource(org.apache.axiom.om.ds.StringOMDataSource) OMSourcedElement(org.apache.axiom.om.OMSourcedElement) OMXMLParserWrapper(org.apache.axiom.om.OMXMLParserWrapper)

Aggregations

OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)37 OMElement (org.apache.axiom.om.OMElement)21 StringReader (java.io.StringReader)12 XMLStreamReader (javax.xml.stream.XMLStreamReader)8 OMFactory (org.apache.axiom.om.OMFactory)8 InputSource (org.xml.sax.InputSource)8 OMNode (org.apache.axiom.om.OMNode)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 QName (javax.xml.namespace.QName)3 OMAttribute (org.apache.axiom.om.OMAttribute)3 OMDocument (org.apache.axiom.om.OMDocument)3 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)3 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)3 DOMSource (javax.xml.transform.dom.DOMSource)2 SAXSource (javax.xml.transform.sax.SAXSource)2 NodeUnavailableException (org.apache.axiom.om.NodeUnavailableException)2 OMException (org.apache.axiom.om.OMException)2 OMNamespace (org.apache.axiom.om.OMNamespace)2