/** * Create a base 64 encoded SHA1 hash key for a given XML element. The key * is based on the element name, the attribute names and their values. Child * elements are ignored. Attributes named 'z' are not concluded since they * contain the hash key itself. * * @param element The element to create the base 64 encoded hash key for * @return the unique key */ public static String calculateUniqueKeyFor(final Element element) { final StringBuilder sb = new StringBuilder(); sb.append(element.getTagName()); final NamedNodeMap attributes = element.getAttributes(); final SortedMap<String, String> attrKVStore = Collections.synchronizedSortedMap(new TreeMap<String, String>()); for (int i = 0, n = attributes.getLength(); i < n; i++) { final Node attr = attributes.item(i); if (!"z".equals(attr.getNodeName()) && !attr.getNodeName().startsWith("_")) { attrKVStore.put(attr.getNodeName(), attr.getNodeValue()); } } for (final Entry<String, String> entry : attrKVStore.entrySet()) { sb.append(entry.getKey()).append(entry.getValue()); } return Base64.encodeBase64String(sha1(sb.toString().getBytes())); }