Search in sources :

Example 86 with OMElement

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));
}
Also used : OMElement(org.apache.axiom.om.OMElement)

Example 87 with OMElement

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;
}
Also used : DataOutputStream(java.io.DataOutputStream) OMElement(org.apache.axiom.om.OMElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) OMNode(org.apache.axiom.om.OMNode) OMText(org.apache.axiom.om.OMText) MessageDigest(java.security.MessageDigest) OMAttribute(org.apache.axiom.om.OMAttribute) OMException(org.apache.axiom.om.OMException)

Example 88 with OMElement

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;
}
Also used : OMNode(org.apache.axiom.om.OMNode) DataOutputStream(java.io.DataOutputStream) OMElement(org.apache.axiom.om.OMElement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) OMException(org.apache.axiom.om.OMException)

Example 89 with OMElement

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());
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Example 90 with OMElement

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/>");
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) OMProcessingInstruction(org.apache.axiom.om.OMProcessingInstruction) StringReader(java.io.StringReader) OMElement(org.apache.axiom.om.OMElement) OMDocument(org.apache.axiom.om.OMDocument)

Aggregations

OMElement (org.apache.axiom.om.OMElement)414 OMFactory (org.apache.axiom.om.OMFactory)202 OMNamespace (org.apache.axiom.om.OMNamespace)108 QName (javax.xml.namespace.QName)97 StringReader (java.io.StringReader)63 OMNode (org.apache.axiom.om.OMNode)43 OMText (org.apache.axiom.om.OMText)41 XMLStreamReader (javax.xml.stream.XMLStreamReader)37 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)32 OMAttribute (org.apache.axiom.om.OMAttribute)26 StringWriter (java.io.StringWriter)24 OMXMLParserWrapper (org.apache.axiom.om.OMXMLParserWrapper)21 DataHandler (javax.activation.DataHandler)20 OMDocument (org.apache.axiom.om.OMDocument)19 PullOMDataSource (org.apache.axiom.ts.om.sourcedelement.util.PullOMDataSource)18 Element (org.w3c.dom.Element)18 InputStream (java.io.InputStream)16 OMSourcedElement (org.apache.axiom.om.OMSourcedElement)16 ByteArrayInputStream (java.io.ByteArrayInputStream)13 OMException (org.apache.axiom.om.OMException)13