Search in sources :

Example 31 with OMDocument

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

the class TestGetSAXResultSAXParser method runTest.

@Override
protected void runTest() throws Throwable {
    SAXParserFactory factory = saxImplementation.newSAXParserFactory();
    factory.setNamespaceAware(true);
    XMLReader reader = factory.newSAXParser().getXMLReader();
    OMDocument document = metaFactory.getOMFactory().createOMDocument();
    ContentHandler handler = document.getSAXResult().getHandler();
    reader.setContentHandler(handler);
    reader.setDTDHandler((DTDHandler) handler);
    reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
    reader.setProperty("http://xml.org/sax/properties/declaration-handler", handler);
    reader.parse(new InputSource(file.getUrl().toString()));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    document.serialize(baos);
    InputSource actual = new InputSource();
    actual.setByteStream(new ByteArrayInputStream(baos.toByteArray()));
    actual.setSystemId(file.getUrl().toString());
    assertAbout(xml()).that(actual).ignoringWhitespaceInPrologAndEpilog().expandingEntityReferences().hasSameContentAs(file.getUrl());
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLReader(org.xml.sax.XMLReader) ContentHandler(org.xml.sax.ContentHandler) SAXParserFactory(javax.xml.parsers.SAXParserFactory) OMDocument(org.apache.axiom.om.OMDocument)

Example 32 with OMDocument

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

the class TestIsCompleteAfterAddingIncompleteChild method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement incompleteElement = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocumentElement(true);
    OMDocument document = factory.createOMDocument();
    assertTrue(document.isComplete());
    document.addChild(incompleteElement);
    assertFalse(document.isComplete());
}
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 33 with OMDocument

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

the class XMLDeclarationSerializationTestCase method runTest.

@Override
protected final void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMNamespace namespace = factory.createOMNamespace("http://testuri.org", "test");
    OMElement documentElement = factory.createOMElement("DocumentElement", namespace);
    OMElement child1 = factory.createOMElement("Child1", namespace);
    child1.setText("TestText");
    documentElement.addChild(child1);
    OMDocument document = factory.createOMDocument();
    document.addChild(documentElement);
    runTest(document);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMNamespace(org.apache.axiom.om.OMNamespace) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 34 with OMDocument

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

the class TestCharacterDataReaderFromParser method runTest.

@Override
protected void runTest() throws Throwable {
    String text = "This is a test for the CharacterDataReader extension";
    OMDocument doc = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<root>" + text + "</root>")).getDocument();
    XMLStreamReader reader = doc.getXMLStreamReader(cache);
    CharacterDataReader cdataReader = (CharacterDataReader) reader.getProperty(CharacterDataReader.PROPERTY);
    assertNotNull(cdataReader);
    assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
    StringWriter sw = new StringWriter();
    while (reader.next() == XMLStreamReader.CHARACTERS) {
        cdataReader.writeTextTo(sw);
    }
    assertEquals(text, sw.toString());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) StringWriter(java.io.StringWriter) CharacterDataReader(org.apache.axiom.ext.stax.CharacterDataReader) StringReader(java.io.StringReader) OMDocument(org.apache.axiom.om.OMDocument)

Example 35 with OMDocument

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

the class TestSerializeAndConsume method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<elem>text</elem>")).getDocument();
    document.serializeAndConsume(new NullOutputStream());
    assertConsumed(document);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMDocument(org.apache.axiom.om.OMDocument) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

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