use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestGetSAXSourceIdentityTransform method runTest.
@Override
protected void runTest() throws Throwable {
Transformer transformer = xsltImplementation.newTransformerFactory().newTransformer();
OMFactory factory = metaFactory.getOMFactory();
OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, getInput()).getDocumentElement();
OMDocument outputDocument = factory.createOMDocument();
transformer.transform(element.getSAXSource(cache), outputDocument.getSAXResult());
assertAbout(xml()).that(xml(OMDocument.class, outputDocument)).ignoringWhitespaceInPrologAndEpilog().hasSameContentAs(getInput());
element.close(false);
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestStandaloneConfiguration method runTest.
@Override
protected void runTest() throws Throwable {
InputStream is = TestStandaloneConfiguration.class.getResourceAsStream("web_w_dtd2.xml");
OMXMLParserWrapper builder = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.STANDALONE, is);
OMElement root = builder.getDocumentElement();
assertTrue(root.getLocalName().equals("web-app"));
OMDocument document = builder.getDocument();
Iterator<OMNode> i = document.getChildren();
OMDocType docType = null;
while (docType == null && i.hasNext()) {
OMNode obj = i.next();
if (obj instanceof OMDocType) {
docType = (OMDocType) obj;
}
}
assertTrue(docType != null);
root.close(false);
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestSetOptimize method runTest.
@Override
protected void runTest() throws Throwable {
InputStream in = XOP_SPEC_SAMPLE.getInputStream();
try {
OMDocument document = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), StAXParserConfiguration.DEFAULT, MultipartBody.builder().setInputStream(in).setContentType(XOP_SPEC_SAMPLE.getContentType()).build()).getDocument();
for (Iterator<OMSerializable> it = document.getDescendants(false); it.hasNext(); ) {
OMSerializable node = it.next();
if (node instanceof OMText) {
OMText text = (OMText) node;
if (text.isBinary()) {
text.setOptimize(optimize);
}
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
document.serialize(out, format);
Multipart mp = new MimeMultipart(new ByteArrayDataSource(out.toByteArray(), format.getContentType()));
assertThat(mp.getCount()).isEqualTo(optimize ? 3 : 1);
} finally {
in.close();
}
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class DocumentNavigator method getNamespaceAxisIterator.
/**
* Retrieves an <code>Iterator</code> matching the <code>namespace</code> XPath axis.
*
* @param contextNode the original context node
* @return Returns an Iterator capable of traversing the axis, not null.
* @throws UnsupportedAxisException if the semantics of the namespace axis are not supported by
* this object model
*/
@Override
public Iterator<?> getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException {
if (!(contextNode instanceof OMContainer && contextNode instanceof OMElement)) {
return JaxenConstants.EMPTY_ITERATOR;
}
OMContainer omContextNode = (OMContainer) contextNode;
List<OMNamespaceEx> nsList = new ArrayList<OMNamespaceEx>();
Set<String> prefixes = new HashSet<String>();
for (OMContainer context = omContextNode; context != null && !(context instanceof OMDocument); context = ((OMElement) context).getParent()) {
OMElement element = (OMElement) context;
List<OMNamespace> declaredNS = new ArrayList<OMNamespace>();
Iterator<OMNamespace> i = element.getAllDeclaredNamespaces();
while (i != null && i.hasNext()) {
declaredNS.add(i.next());
}
declaredNS.add(element.getNamespace());
for (Iterator<OMAttribute> iter = element.getAllAttributes(); iter != null && iter.hasNext(); ) {
OMAttribute attr = iter.next();
OMNamespace namespace = attr.getNamespace();
if (namespace != null) {
declaredNS.add(namespace);
}
}
for (OMNamespace namespace : declaredNS) {
if (namespace != null) {
String prefix = namespace.getPrefix();
if (prefix != null && !prefixes.contains(prefix)) {
prefixes.add(prefix);
nsList.add(new OMNamespaceEx(namespace, context));
}
}
}
}
nsList.add(new OMNamespaceEx(omContextNode.getOMFactory().createOMNamespace("http://www.w3.org/XML/1998/namespace", "xml"), omContextNode));
return nsList.iterator();
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class CopyUtils method reader2writer.
/**
* Simple utility that takes an XMLStreamReader and writes it
* to an XMLStreamWriter
* @param reader
* @param writer
* @throws XMLStreamException
*/
public 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()) {
OMNode omNode = it.next();
omNode.serializeAndConsume(writer);
}
} finally {
builder.close();
}
}
Aggregations