use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestGetSAXSourceIdentityTransformOnFragment method runTest.
@Override
protected void runTest() throws Throwable {
Transformer transformer = xsltImplementation.newTransformerFactory().newTransformer();
OMFactory factory = metaFactory.getOMFactory();
OMElement element = OMXMLBuilderFactory.createOMBuilder(factory, getInput()).getDocumentElement().getFirstElement();
OMDocument outputDocument = factory.createOMDocument();
transformer.transform(element.getSAXSource(cache), outputDocument.getSAXResult());
OMNamespace ns = outputDocument.getOMDocumentElement().findNamespaceURI("p");
assertNotNull(ns);
assertEquals("urn:some:namespace", ns.getNamespaceURI());
element.close(false);
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class AxiomTraverser method next.
@Override
public Event next() throws TraverserException {
if (node == null) {
if (root instanceof OMDocument) {
node = ((OMDocument) root).getFirstOMChild();
} else {
node = (OMElement) root;
}
} else if (!visited && node instanceof OMElement) {
OMNode firstChild = ((OMElement) node).getFirstOMChild();
if (firstChild != null) {
node = firstChild;
} else {
visited = true;
}
} else {
OMNode nextSibling = node.getNextOMSibling();
if (node == root) {
return null;
} else if (nextSibling != null) {
node = nextSibling;
visited = false;
} else {
OMContainer parent = node.getParent();
if (parent instanceof OMDocument) {
return null;
} else {
node = (OMElement) parent;
visited = true;
}
}
}
switch(node.getType()) {
case OMNode.DTD_NODE:
return Event.DOCUMENT_TYPE;
case OMNode.ELEMENT_NODE:
return visited ? Event.END_ELEMENT : Event.START_ELEMENT;
case OMNode.TEXT_NODE:
return Event.TEXT;
case OMNode.SPACE_NODE:
return Event.WHITESPACE;
case OMNode.ENTITY_REFERENCE_NODE:
if (expandEntityReferences) {
throw new UnsupportedOperationException();
} else {
return Event.ENTITY_REFERENCE;
}
case OMNode.COMMENT_NODE:
return Event.COMMENT;
case OMNode.CDATA_SECTION_NODE:
return Event.CDATA_SECTION;
case OMNode.PI_NODE:
return Event.PROCESSING_INSTRUCTION;
default:
throw new IllegalStateException();
}
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestClone method runTest.
@Override
protected void runTest() throws Throwable {
SOAPMessage message = soapFactory.createSOAPMessage();
message.addChild(soapFactory.getDefaultEnvelope());
OMCloneOptions options = new OMCloneOptions();
options.setPreserveModel(preserveModel);
OMInformationItem clone = message.clone(options);
if (preserveModel) {
assertTrue(clone instanceof SOAPMessage);
} else {
assertTrue(clone instanceof OMDocument);
assertFalse(clone instanceof SOAPMessage);
}
OMElement envelope = ((OMDocument) clone).getOMDocumentElement();
if (preserveModel) {
assertTrue(envelope instanceof SOAPEnvelope);
} else {
assertFalse(envelope instanceof SOAPEnvelope);
}
assertEquals("Envelope", envelope.getLocalName());
assertEquals(spec.getEnvelopeNamespaceURI(), envelope.getNamespaceURI());
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestCloneIncomplete method runTest.
@Override
protected void runTest() throws Throwable {
SOAPMessage message = SOAPSampleSet.WSA.getMessage(spec).getAdapter(SOAPSampleAdapter.class).getSOAPMessage(metaFactory);
OMCloneOptions options = new OMCloneOptions();
options.setPreserveModel(preserveModel);
OMInformationItem clone = message.clone(options);
if (preserveModel) {
assertTrue(clone instanceof SOAPMessage);
assertSame(soapFactory, clone.getOMFactory());
} else {
assertTrue(clone instanceof OMDocument);
assertFalse(clone instanceof SOAPMessage);
}
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestGetSAXResult method runTest.
@Override
protected void runTest() throws Throwable {
TransformerFactory transformerFactory = xsltImplementation.newTransformerFactory();
StreamSource source = new StreamSource(file.getUrl().toString());
OMDocument document = metaFactory.getOMFactory().createOMDocument();
SAXResult result = document.getSAXResult();
transformerFactory.newTransformer().transform(source, result);
assertAbout(xml()).that(xml(OMDocument.class, document)).ignoringWhitespaceInPrologAndEpilog().ignoringRedundantNamespaceDeclarations().expandingEntityReferences().hasSameContentAs(file.getUrl());
}
Aggregations