Search in sources :

Example 11 with OMDocument

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

the class TestMalformedDocument method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<Root><Child attr='a' attr='a'/></Root>")).getDocument();
    try {
        document.serialize(new ByteArrayOutputStream());
        fail("Expected exception");
    } catch (Exception ex) {
    // We expect an exception here
    }
    document.close(false);
}
Also used : StringReader(java.io.StringReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMDocument(org.apache.axiom.om.OMDocument)

Example 12 with OMDocument

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

the class TestAddChildWithExistingDocumentElement method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = factory.createOMDocument();
    document.addChild(factory.createOMElement(new QName("root1")));
    try {
        document.addChild(factory.createOMElement(new QName("root2")));
        fail("Expected OMException");
    } catch (OMException ex) {
    // Expected
    }
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) QName(javax.xml.namespace.QName) OMException(org.apache.axiom.om.OMException) OMDocument(org.apache.axiom.om.OMDocument)

Example 13 with OMDocument

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

the class TestBuild method runTest.

@Override
protected void runTest() throws Throwable {
    InstrumentedInputStream in = new InstrumentedInputStream(XMLSample.LARGE.getInputStream());
    OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), in).getDocument();
    assertFalse(doc.isComplete());
    long countBeforeBuild = in.getCount();
    doc.build();
    assertTrue(doc.isComplete());
    long countAfterBuild = in.getCount();
    assertTrue(countAfterBuild > countBeforeBuild);
    OMNode node = doc.getFirstOMChild();
    while (node != null) {
        node = node.getNextOMSibling();
    }
    assertEquals(countAfterBuild, in.getCount());
}
Also used : OMNode(org.apache.axiom.om.OMNode) InstrumentedInputStream(org.apache.axiom.testutils.io.InstrumentedInputStream) OMDocument(org.apache.axiom.om.OMDocument)

Example 14 with OMDocument

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

the class TestDigest method createInformationItem.

@Override
protected OMInformationItem createInformationItem() throws Exception {
    InputStream in = TestDigest.class.getResourceAsStream(file);
    try {
        OMDocument document = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), in).getDocument();
        document.build();
        return document;
    } finally {
        in.close();
    }
}
Also used : InputStream(java.io.InputStream) OMDocument(org.apache.axiom.om.OMDocument)

Example 15 with OMDocument

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

the class TestClone method runTest.

@Override
protected void runTest() throws Throwable {
    OMDocument original = file.getAdapter(XMLSampleAdapter.class).getDocument(metaFactory);
    OMDocument clone = (OMDocument) original.clone(new OMCloneOptions());
    assertAbout(xml()).that(xml(OMDocument.class, clone)).hasSameContentAs(xml(OMDocument.class, original));
}
Also used : OMCloneOptions(org.apache.axiom.om.OMCloneOptions) XMLSampleAdapter(org.apache.axiom.ts.om.XMLSampleAdapter) 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