Search in sources :

Example 21 with OMDocument

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

the class TestSetOMDocumentElementReplaceSame method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    OMElement root = factory.createOMElement("root", null, document);
    document.setOMDocumentElement(root);
    assertThat(document.getOMDocumentElement()).isSameAs(root);
    assertThat(root.getPreviousOMSibling()).isNull();
    assertThat(root.getNextOMSibling()).isNull();
    assertThat(root.getParent()).isSameAs(document);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 22 with OMDocument

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

the class TestCloseWithoutCaching method runTest.

@Override
protected void runTest() throws Throwable {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer writer = new OutputStreamWriter(baos, "UTF-8");
    writer.write("<root><a>");
    for (int i = 0; i < 20000; i++) {
        writer.write('a');
    }
    writer.write("</a></root>");
    writer.close();
    InstrumentedInputStream in = new InstrumentedInputStream(new ByteArrayInputStream(baos.toByteArray()));
    OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), in).getDocument();
    XMLStreamReader reader = doc.getXMLStreamReaderWithoutCaching();
    reader.next();
    reader.next();
    long count = in.getCount();
    reader.close();
    assertEquals(count, in.getCount());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InstrumentedInputStream(org.apache.axiom.testutils.io.InstrumentedInputStream) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) OMDocument(org.apache.axiom.om.OMDocument)

Example 23 with OMDocument

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

the class TestDTDReader method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    factory.createOMDocType(document, "root", "-//MY//DTD", "my.dtd", "<!ELEMENT root (#PCDATA)>");
    factory.createOMElement("root", null, document);
    XMLStreamReader reader = document.getXMLStreamReader();
    // Note that according to the specification of the DTDReader interface, it is
    // allowed to look up the extension before reaching the DTD event.
    DTDReader dtdReader = (DTDReader) reader.getProperty(DTDReader.PROPERTY);
    assertNotNull(dtdReader);
    assertEquals(XMLStreamReader.DTD, reader.next());
    assertEquals("root", dtdReader.getRootName());
    assertEquals("-//MY//DTD", dtdReader.getPublicId());
    assertEquals("my.dtd", dtdReader.getSystemId());
    assertEquals("<!ELEMENT root (#PCDATA)>", reader.getText());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) XMLStreamReader(javax.xml.stream.XMLStreamReader) DTDReader(org.apache.axiom.ext.stax.DTDReader) OMDocument(org.apache.axiom.om.OMDocument)

Example 24 with OMDocument

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

the class TestDiscardDocumentElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<root><a>text</a></root>")).getDocument();
    OMElement element = document.getOMDocumentElement();
    element.discard();
    assertNull(document.getFirstOMChild());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 25 with OMDocument

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

the class OMXMLParserWrapperImpl method getDocumentElement.

@Override
public final OMElement getDocumentElement(boolean discardDocument) {
    try {
        OMDocument document = getDocument();
        OMElement element = document.getOMDocumentElement();
        if (discardDocument) {
            element.detach();
            ((AxiomDocument) document).coreDiscard(false);
        }
        return element;
    } catch (CoreModelException ex) {
        throw AxiomExceptionTranslator.translate(ex);
    }
}
Also used : AxiomDocument(org.apache.axiom.om.impl.intf.AxiomDocument) CoreModelException(org.apache.axiom.core.CoreModelException) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMDocument (org.apache.axiom.om.OMDocument)51 OMElement (org.apache.axiom.om.OMElement)19 OMFactory (org.apache.axiom.om.OMFactory)18 StringReader (java.io.StringReader)13 OMNode (org.apache.axiom.om.OMNode)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Document (org.w3c.dom.Document)5 StringWriter (java.io.StringWriter)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 OMCloneOptions (org.apache.axiom.om.OMCloneOptions)3 OMInformationItem (org.apache.axiom.om.OMInformationItem)3 OMNamespace (org.apache.axiom.om.OMNamespace)3 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Transformer (javax.xml.transform.Transformer)2 DTDReader (org.apache.axiom.ext.stax.DTDReader)2 OMAttribute (org.apache.axiom.om.OMAttribute)2 OMComment (org.apache.axiom.om.OMComment)2