use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestCloseWithStream method runTest.
@Override
protected void runTest() throws Throwable {
InstrumentedStream in = streamType.instrumentStream(streamType.getStream(XMLSample.SIMPLE));
try {
OMXMLParserWrapper builder = streamType.getAdapter(StreamTypeAdapter.class).createOMBuilder(metaFactory.getOMFactory(), in);
builder.getDocument().build();
builder.close();
// OMXMLParserWrapper#close() does _not_ close the underlying input stream
assertFalse(in.isClosed());
} finally {
in.close();
}
}
use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestCreateOMBuilderFromSAXSource method runTest.
@Override
protected void runTest() throws Throwable {
SAXParserFactory factory = implementation.newSAXParserFactory();
factory.setNamespaceAware(true);
factory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
SAXParser parser = factory.newSAXParser();
SAXSource source = new SAXSource(parser.getXMLReader(), new InputSource(file.getUrl().toString()));
OMXMLParserWrapper builder;
if (expandEntityReferences == null) {
builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source);
} else {
builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), source, expandEntityReferences.booleanValue());
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
builder.getDocument().serialize(baos);
InputSource actual = new InputSource();
actual.setByteStream(new ByteArrayInputStream(baos.toByteArray()));
actual.setSystemId(file.getUrl().toString());
assertAbout(xml()).that(actual).ignoringWhitespaceInPrologAndEpilog().expandingEntityReferences(expandEntityReferences == null ? false : expandEntityReferences.booleanValue()).hasSameContentAs(DOMImplementation.XERCES.parse(new InputSource(file.getUrl().toString()), expandEntityReferences == null || expandEntityReferences));
}
use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestCreateOMBuilderFromDOM method runTest.
@Override
protected void runTest() throws Throwable {
// We never expand entity references during parsing, but we may do this later when
// converting DOM to OM.
Document document = loadDocument(false);
OMXMLParserWrapper builder;
if (expandEntityReferences == null) {
builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new DOMSource(document));
} else {
builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), document, expandEntityReferences.booleanValue());
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
builder.getDocument().serialize(baos);
InputSource actual = new InputSource();
actual.setByteStream(new ByteArrayInputStream(baos.toByteArray()));
actual.setSystemId(file.getUrl().toString());
assertAbout(xml()).that(actual).ignoringWhitespaceInPrologAndEpilog().treatingElementContentWhitespaceAsText(!implementation.isDOM3()).hasSameContentAs(loadDocument(expandEntityReferences == null || expandEntityReferences));
}
use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestGetXMLStreamReaderWithCaching method runTest.
@Override
protected void runTest() throws Throwable {
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), TestGetChildElementsConsumed.class.getResourceAsStream("purchase-order.xml"));
OMElement documentElement = builder.getDocumentElement();
XMLStreamReader reader = documentElement.getXMLStreamReader();
//tree to be fully built
while (reader.hasNext()) {
reader.next();
}
//try to find the children of the document element. This should *NOT* produce an
//error even when the underlying stream is fully consumed , the object tree is already complete
Iterator<OMElement> childElements = documentElement.getChildElements();
int count = 0;
while (childElements.hasNext()) {
childElements.next();
count++;
}
assertEquals("Number of elements need to be 2", count, 2);
documentElement.close(false);
}
use of org.apache.axiom.om.OMXMLParserWrapper in project webservices-axiom by apache.
the class TestSerializeAndConsumeConsumed method runTest.
@Override
protected void runTest() throws Throwable {
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), TestGetChildElementsConsumed.class.getResourceAsStream("purchase-order.xml"));
OMElement documentElement = builder.getDocumentElement();
XMLStreamReader reader = documentElement.getXMLStreamReaderWithoutCaching();
//building the tree
while (reader.hasNext()) {
reader.next();
}
//error since the underlying stream is fully consumed without building the object tree
try {
documentElement.serializeAndConsume(StAX.createNullXMLStreamWriter());
fail("Expected NodeUnavailableException");
} catch (NodeUnavailableException e) {
//wea re cool
}
documentElement.close(false);
}
Aggregations