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);
}
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());
}
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());
}
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());
}
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);
}
}
Aggregations