use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class DOOMDocumentBuilder method parse.
public Document parse(InputSource inputSource) throws SAXException, IOException {
OMDocument document = ((OMMetaFactorySPI) factory.getMetaFactory()).createOMBuilder(parserConfiguration, inputSource).getDocument();
document.close(true);
return (Document) document;
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class MTOMStAXSOAPModelBuilderTest method testDeferredLoadingOfAttachments.
/**
* Test that MIME parts are not loaded before requesting the DataHandlers from the corresponding
* OMText nodes.
*
* @throws Exception
*/
public void testDeferredLoadingOfAttachments() throws Exception {
Attachments attachments = createAttachmentsForTestMTOMMessage();
SOAPModelBuilder builder = OMXMLBuilderFactory.createSOAPModelBuilder(attachments);
OMDocument doc = builder.getDocument();
// Find all the binary nodes
List<OMText> binaryNodes = new ArrayList<>();
for (Iterator<OMSerializable> it = doc.getDescendants(false); it.hasNext(); ) {
OMSerializable node = it.next();
if (node instanceof OMText) {
OMText text = (OMText) node;
if (text.isBinary()) {
binaryNodes.add(text);
}
}
}
assertFalse(binaryNodes.isEmpty());
// At this moment only the SOAP part should have been loaded
assertEquals(1, attachments.getContentIDList().size());
for (OMText node : binaryNodes) {
// Request the DataHandler and do something with it to make sure
// the part is loaded
node.getDataHandler().getInputStream().close();
}
assertEquals(binaryNodes.size() + 1, attachments.getContentIDList().size());
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestAppendChildForbidden method runTest.
@Override
protected void runTest() throws Throwable {
OMDocument omDocument = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<test/>")).getDocument();
if (build) {
omDocument.build();
}
Document document = (Document) omDocument;
try {
document.appendChild(document.createElementNS(null, "test"));
fail("Expected DOMException");
} catch (DOMException ex) {
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
}
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestGetOMFactory1 method runTest.
@Override
protected void runTest() throws Throwable {
Document document = ((DOMMetaFactory) metaFactory).newDocumentBuilderFactory().newDocumentBuilder().newDocument();
assertSame(metaFactory.getOMFactory(), ((OMDocument) document).getOMFactory());
}
use of org.apache.axiom.om.OMDocument in project webservices-axiom by apache.
the class TestInsertBeforeForbidden method runTest.
@Override
protected void runTest() throws Throwable {
OMDocument omDocument = OMXMLBuilderFactory.createOMBuilder(metaFactory.getOMFactory(), new StringReader("<!--test--><test/>")).getDocument();
if (build) {
omDocument.build();
}
Document document = (Document) omDocument;
Comment comment = (Comment) document.getFirstChild();
try {
document.insertBefore(document.createElementNS(null, "test"), comment);
fail("Expected DOMException");
} catch (DOMException ex) {
assertThat(ex.code).isEqualTo(DOMException.HIERARCHY_REQUEST_ERR);
}
}
Aggregations