use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class OMDataSourceExtBase method reader2writer.
/**
* Simple utility that takes an XMLStreamReader and writes it
* to an XMLStreamWriter
* @param reader
* @param writer
* @throws XMLStreamException
*/
private static void reader2writer(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(reader);
try {
OMDocument omDocument = builder.getDocument();
Iterator<OMNode> it = omDocument.getChildren();
while (it.hasNext()) {
// TODO: this is extremely inefficient since next() will actually build the node!
OMNode omNode = it.next();
// TODO: quick fix required because OMChildrenIterator#next() no longer builds the node
omNode.getNextOMSibling();
omNode.serializeAndConsume(writer);
}
} finally {
builder.close();
}
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class OMXMLReader method parse.
private void parse() throws SAXException {
if (root instanceof OMDocument) {
generateEvents((OMDocument) root);
} else {
OMElement element = (OMElement) root;
contentHandler.startDocument();
generateParentPrefixMappingEvents(element, true);
generateEvents(element);
generateParentPrefixMappingEvents(element, false);
contentHandler.endDocument();
}
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class SerializeToXMLStreamWriter method serialize.
@Override
public XML serialize(OMContainer container) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String encoding = null;
// the output encoding so that it will match the encoding in the XML declaration.
if (container instanceof OMDocument) {
encoding = ((OMDocument) container).getXMLEncoding();
}
if (encoding == null) {
encoding = "UTF-8";
}
XMLStreamWriter writer = StAX.createXMLStreamWriter(baos, encoding);
if (cache) {
container.serialize(writer);
} else {
container.serializeAndConsume(writer);
}
writer.close();
return new XMLAsByteArray(baos.toByteArray());
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class DigestTestCase method runTest.
@Override
protected final void runTest() throws Throwable {
OMInformationItem node = createInformationItem();
DigestGenerator digestGenerator = new DigestGenerator();
byte[] digest;
if (node instanceof OMDocument) {
digest = digestGenerator.getDigest((OMDocument) node, algorithm);
} else if (node instanceof OMAttribute) {
digest = digestGenerator.getDigest((OMAttribute) node, algorithm);
} else {
digest = digestGenerator.getDigest((OMNode) node, algorithm);
}
assertEquals(expectedDigest, DigestUtils.toHexString(digest));
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class DialectTest method testDTD.
/**
* Tests that Axiom is able to read a DOCTYPE declaration. Since accessing the information in
* the DOCTYPE declaration is not standardized by the StAX specification, this will fail if the
* StAX dialect is not detected correctly.
*
* @throws Exception
*/
@Test
public void testDTD() throws Exception {
OMDocument document = OMXMLBuilderFactory.createOMBuilder(new StringReader("<!DOCTYPE root><root/>")).getDocument();
OMDocType dtd = (OMDocType) document.getFirstOMChild();
assertEquals("root", dtd.getRootName());
}
Aggregations