/** * Compares two OMNodes for the XML equality * * @param node * @param comparingNode * @param digestAlgorithm * @return Returns true if the OMNode XML contents are equal */ public boolean compareOMNode(OMNode node, OMNode comparingNode, String digestAlgorithm) { return Arrays.equals(getDigest(node, digestAlgorithm), getDigest(comparingNode, digestAlgorithm)); }
/** * This method is an overloaded method for getting the expanded name namespaceURI followed by * the local name for OMElement * * @param element * @return Returns the expanded name of OMElement */ public String getExpandedName(OMElement element) { return internalGetExpandedName(element); }
DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(1); dos.write(getExpandedName(element).getBytes("UnicodeBigUnmarked")); dos.write((byte) 0); dos.write((byte) 0); Collection attrs = getAttributesWithoutNS(element); dos.writeInt(attrs.size()); Iterator itr = attrs.iterator(); while (itr.hasNext()) dos.write(getDigest((OMAttribute) itr.next(), digestAlgorithm)); OMNode node = element.getFirstOMChild(); dos.write(getDigest(node, digestAlgorithm)); node = node.getNextOMSibling();
DataOutputStream dos = new DataOutputStream(baos); dos.writeInt(9); Collection childNodes = getValidElements(document); dos.writeInt(childNodes.size()); Iterator itr = childNodes.iterator(); OMNode node = (OMNode) 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));
/** * Gets the collection of attributes which are none namespace declarations for an OMElement * * @param element * @return Returns the collection of attributes which are none namespace declarations */ public Collection getAttributesWithoutNS(OMElement element) { SortedMap map = new TreeMap(); Iterator itr = element.getAllAttributes(); while (itr.hasNext()) { OMAttribute attribute = (OMAttribute) itr.next(); if (!(attribute.getLocalName().equals("xmlns") || attribute.getLocalName().startsWith("xmlns:"))) map.put(getExpandedName(attribute), attribute); } return map.values(); }
/** * This method is an overloaded method for the digest generation for OMAttribute * * @param attribute * @param digestAlgorithm * @return Returns a byte array representing the calculated digest value */ public byte[] getDigest(OMAttribute attribute, String digestAlgorithm) throws OMException { byte[] digest = new byte[0]; if (!(attribute.getLocalName().equals("xmlns") || attribute.getLocalName().startsWith("xmlns:"))) try { MessageDigest md = MessageDigest.getInstance(digestAlgorithm); md.update((byte) 0); md.update((byte) 0); md.update((byte) 0); md.update((byte) 2); md.update(getExpandedName(attribute).getBytes("UnicodeBigUnmarked")); md.update((byte) 0); md.update((byte) 0); md.update(attribute.getAttributeValue().getBytes("UnicodeBigUnmarked")); digest = md.digest(); } catch (NoSuchAlgorithmException e) { throw new OMException(e); } catch (UnsupportedEncodingException e) { throw new OMException(e); } return digest; }
/** * Compares two OMDocuments for the XML equality * * @param document * @param comparingDocument * @param digestAlgorithm * @return Returns true if the OMDocument XML content are equal */ public boolean compareOMDocument(OMDocument document, OMDocument comparingDocument, String digestAlgorithm) { return Arrays.equals(getDigest(document, digestAlgorithm), getDigest(comparingDocument, digestAlgorithm)); }
/** * This method is an overloaded method for getting the expanded name namespaceURI followed by * the local name for OMAttribute * * @param attribute * @return Returns the expanded name of the OMAttribute */ public String getExpandedName(OMAttribute attribute) { return internalGetExpandedName(attribute); }
/** * Compares two OMAttributes for the XML equality * * @param attribute * @param comparingAttribute * @param digestAlgorithm * @return Returns true if the OMDocument XML content are equal */ public boolean compareOMAttribute(OMAttribute attribute, OMAttribute comparingAttribute, String digestAlgorithm) { return Arrays.equals(getDigest(attribute, digestAlgorithm), getDigest(comparingAttribute, digestAlgorithm)); }
/** * This method is an overloaded method for the digest generation for OMNode * * @param node * @param digestAlgorithm * @return Returns a byte array representing the calculated digest value */ public byte[] getDigest(OMNode node, String digestAlgorithm) { if (node.getType() == OMNode.ELEMENT_NODE) return getDigest((OMElement) node, digestAlgorithm); else if ( node.getType() == OMNode.TEXT_NODE) return getDigest((OMText) node, digestAlgorithm); else if (node.getType() == OMNode.PI_NODE) return getDigest((OMProcessingInstruction) node, digestAlgorithm); else return new byte[0]; }