use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetChild method runTest.
@Override
protected void runTest(OMElement parent, SOAPElementTypeAdapter adapter) {
assertNull(adapter.getGetter().invoke(parent));
OMElement child = adapter.create(soapFactory, type, parent);
assertSame(child, adapter.getGetter().invoke(parent));
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class DigestGenerator method getDigest.
/**
* This method is an overloaded method for the digest generation for OMElement
*
* @param element
* @param digestAlgorithm
* @return Returns a byte array representing the calculated digest value
*/
public byte[] getDigest(OMElement element, String digestAlgorithm) throws OMException {
byte[] digest = new byte[0];
try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(1);
dos.write(getExpandedName(element).getBytes("UnicodeBigUnmarked"));
dos.write((byte) 0);
dos.write((byte) 0);
Collection<OMAttribute> attrs = getAttributesWithoutNS(element);
dos.writeInt(attrs.size());
for (Iterator<OMAttribute> itr = attrs.iterator(); itr.hasNext(); ) {
dos.write(getDigest(itr.next(), digestAlgorithm));
}
OMNode node = element.getFirstOMChild();
// adjoining Texts are merged,
// there is no 0-length Text, and
// comment nodes are removed.
int length = 0;
for (Iterator<OMNode> itr = element.getChildren(); itr.hasNext(); ) {
OMNode child = itr.next();
if (child instanceof OMElement || child instanceof OMText || child instanceof OMProcessingInstruction) {
length++;
}
}
dos.writeInt(length);
while (node != null) {
dos.write(getDigest(node, digestAlgorithm));
node = node.getNextOMSibling();
}
dos.close();
md.update(baos.toByteArray());
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new OMException(e);
} catch (IOException e) {
throw new OMException(e);
}
return digest;
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class DigestGenerator method getDigest.
/**
* This method is an overloaded method for the digest generation for OMDocument
*
* @param document
* @param digestAlgorithm
* @return Returns a byte array representing the calculated digest
*/
public byte[] getDigest(OMDocument document, String digestAlgorithm) throws OMException {
byte[] digest = new byte[0];
try {
MessageDigest md = MessageDigest.getInstance(digestAlgorithm);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeInt(9);
Collection<OMNode> childNodes = getValidElements(document);
dos.writeInt(childNodes.size());
Iterator<OMNode> itr = childNodes.iterator();
while (itr.hasNext()) {
OMNode node = itr.next();
if (node.getType() == OMNode.PI_NODE)
dos.write(getDigest((OMProcessingInstruction) node, digestAlgorithm));
else if (node.getType() == OMNode.ELEMENT_NODE)
dos.write(getDigest((OMElement) node, digestAlgorithm));
}
dos.close();
md.update(baos.toByteArray());
digest = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new OMException(e);
} catch (IOException e) {
throw new OMException(e);
}
return digest;
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestGetOMDocumentElementWithParser method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<!-- comment --><root/><!-- comment -->")).getDocument();
OMElement documentElement = document.getOMDocumentElement();
assertNotNull(documentElement);
assertEquals("root", documentElement.getLocalName());
}
use of org.apache.axiom.om.OMElement in project webservices-axiom by apache.
the class TestRemoveChildren method runTest.
@Override
protected void runTest() throws Throwable {
OMFactory factory = metaFactory.getOMFactory();
OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new StringReader("<?pi data?><root>text</root>")).getDocument();
if (complete) {
document.build();
}
OMProcessingInstruction firstChild = (OMProcessingInstruction) document.getFirstOMChild();
OMElement documentElement;
if (accessDocumentElement) {
documentElement = document.getOMDocumentElement();
assertEquals(complete, documentElement.isComplete());
} else {
documentElement = null;
}
document.removeChildren();
// Test that the child has been detached correctly.
assertNull(firstChild.getParent());
assertNull(firstChild.getPreviousOMSibling());
assertNull(firstChild.getNextOMSibling());
if (documentElement != null) {
// Test that the child has been detached correctly.
assertNull(documentElement.getParent());
assertNull(documentElement.getPreviousOMSibling());
assertNull(documentElement.getNextOMSibling());
// Test that we can still get the content of the document element.
assertEquals("text", documentElement.getText());
}
// Test that the document is now empty.
assertNull(document.getFirstOMChild());
// Check that the document is in a clean state and that we are able to add
// new children.
document.addChild(factory.createOMElement("newroot", null));
assertAbout(xml()).that(xml(OMDocument.class, document)).hasSameContentAs("<newroot/>");
}
Aggregations