Index: lutinutil/src/java/org/codelutin/util/DigestGenerator.java diff -u lutinutil/src/java/org/codelutin/util/DigestGenerator.java:1.1 lutinutil/src/java/org/codelutin/util/DigestGenerator.java:1.2 --- lutinutil/src/java/org/codelutin/util/DigestGenerator.java:1.1 Tue Feb 12 18:10:47 2008 +++ lutinutil/src/java/org/codelutin/util/DigestGenerator.java Tue Feb 12 19:59:06 2008 @@ -59,10 +59,11 @@ * @param document * @param digestAlgorithm * @return Returns a byte array representing the calculated digest + * @throws Exception */ public byte[] getDigest(Document document, String digestAlgorithm) throws Exception { - byte[] digest = new byte[0]; + byte[] digest; try { MessageDigest md = MessageDigest.getInstance(digestAlgorithm); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -70,14 +71,15 @@ dos.writeInt(9); Collection childNodes = getValidElements(document); dos.writeInt(childNodes.size()); - Iterator itr = childNodes.iterator(); - while (itr.hasNext()) { - Node node = (Node) itr.next(); - if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) + for (Object childNode : childNodes) { + Node node = (Node) childNode; + if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { dos.write(getDigest((ProcessingInstruction) node, digestAlgorithm)); - else if (node.getNodeType() == Node.ELEMENT_NODE) + } + else if (node.getNodeType() == Node.ELEMENT_NODE) { dos.write(getDigest((Element) node, digestAlgorithm)); + } } dos.close(); md.update(baos.toByteArray()); @@ -96,16 +98,19 @@ * @param node * @param digestAlgorithm * @return Returns a byte array representing the calculated digest value + * @throws Exception */ public byte[] getDigest(Node node, String digestAlgorithm) throws Exception { - if (node.getNodeType() == Node.ELEMENT_NODE) + if (node.getNodeType() == Node.ELEMENT_NODE) { return getDigest((Element) node, digestAlgorithm); - else if (node.getNodeType() == Node.TEXT_NODE) + } + if (node.getNodeType() == Node.TEXT_NODE) { return getDigest((Text) node, digestAlgorithm); - else if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) + } + if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { return getDigest((ProcessingInstruction) node, digestAlgorithm); - else - return new byte[0]; + } + return new byte[0]; } /** @@ -114,10 +119,11 @@ * @param element * @param digestAlgorithm * @return Returns a byte array representing the calculated digest value + * @throws Exception */ public byte[] getDigest(Element element, String digestAlgorithm) throws Exception { - byte[] digest = new byte[0]; + byte[] digest; try { MessageDigest md = MessageDigest.getInstance(digestAlgorithm); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -128,9 +134,9 @@ dos.write((byte) 0); Collection attrs = getAttributesWithoutNS(element); dos.writeInt(attrs.size()); - Iterator itr = attrs.iterator(); - while (itr.hasNext()) - dos.write(getDigest((Attr) itr.next(), digestAlgorithm)); + for (Object attr : attrs) { + dos.write(getDigest((Attr) attr, digestAlgorithm)); + } Node node = element.getFirstChild(); // adjoining Texts are merged, // there is no 0-length Text, and @@ -158,10 +164,11 @@ * @param pi * @param digestAlgorithm * @return Returns a byte array representing the calculated digest value + * @throws Exception */ public byte[] getDigest(ProcessingInstruction pi, String digestAlgorithm) throws Exception { - byte[] digest = new byte[0]; + byte[] digest; try { MessageDigest md = MessageDigest.getInstance(digestAlgorithm); md.update((byte) 0); @@ -187,12 +194,13 @@ * @param attribute * @param digestAlgorithm * @return Returns a byte array representing the calculated digest value + * @throws Exception */ public byte[] getDigest(Attr attribute, String digestAlgorithm) throws Exception { byte[] digest = new byte[0]; if (!(attribute.getLocalName().equals("xmlns") || attribute - .getLocalName().startsWith("xmlns:"))) + .getLocalName().startsWith("xmlns:"))) { try { MessageDigest md = MessageDigest.getInstance(digestAlgorithm); md.update((byte) 0); @@ -210,6 +218,7 @@ } catch (UnsupportedEncodingException e) { throw new Exception(e); } + } return digest; } @@ -219,9 +228,10 @@ * @param text * @param digestAlgorithm * @return Returns a byte array representing the calculated digest value + * @throws Exception */ public byte[] getDigest(Text text, String digestAlgorithm) throws Exception { - byte[] digest = new byte[0]; + byte[] digest; try { MessageDigest md = MessageDigest.getInstance(digestAlgorithm); md.update((byte) 0); @@ -271,8 +281,9 @@ for (int i = 0; i < element.getAttributes().getLength(); i++) { Attr attribute = (Attr) element.getAttributes().item(i); if (!(attribute.getLocalName().equals("xmlns") || attribute - .getLocalName().startsWith("xmlns:"))) + .getLocalName().startsWith("xmlns:"))) { map.put(getExpandedName(attribute), attribute); + } } return map.values(); } @@ -289,8 +300,9 @@ for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE - || node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) + || node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { list.add(node); + } } return list; } @@ -303,8 +315,9 @@ */ public String getStringRepresentation(byte[] array) { String str = ""; - for (int i = 0; i < array.length; i++) - str += array[i]; + for (byte anArray : array) { + str += anArray; + } return str; } @@ -315,6 +328,7 @@ * @param comparingNode * @param digestAlgorithm * @return Returns true if the Node XML contents are equal + * @throws Exception */ public boolean compareNode(Node node, Node comparingNode, String digestAlgorithm) throws Exception { @@ -329,6 +343,7 @@ * @param comparingDocument * @param digestAlgorithm * @return Returns true if the Document XML content are equal + * @throws Exception */ public boolean compareDocument(Document document, Document comparingDocument, String digestAlgorithm) @@ -344,6 +359,7 @@ * @param comparingAttribute * @param digestAlgorithm * @return Returns true if the Document XML content are equal + * @throws Exception */ public boolean compareAttribute(Attr attribute, Attr comparingAttribute, String digestAlgorithm) throws Exception {