|| originalElementHashCode.equals(calculateUniqueKeyFor(originalElement))) { if (!equalElements(originalElement, proposedElement)) { originalElement.setAttribute("z", calculateUniqueKeyFor(proposedElement)); originalDocumentChanged = true; addOrUpdateElements(original, proposedElement, originalDocumentChanged);
/** * This method will compare the original document with the proposed document * and return true if adjustments to the original document were necessary. * Adjustments are only made if new elements or attributes are proposed. * Changes to the order of attributes or elements in the original document * will not result in an adjustment. * * @param original document as read from the file system * @param proposed document as determined by the JspViewManager * @return true if the document was adjusted, otherwise false */ public static boolean compareDocuments(final Document original, final Document proposed) { boolean originalDocumentAdjusted = checkNamespaces(original, proposed); originalDocumentAdjusted |= addOrUpdateElements(original.getDocumentElement(), proposed.getDocumentElement(), originalDocumentAdjusted); originalDocumentAdjusted |= removeElements(original.getDocumentElement(), proposed.getDocumentElement(), originalDocumentAdjusted); return originalDocumentAdjusted; }
/** * 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())); }
XmlUtils.findFirstElement("//*[@id='" + originalId + "']", proposed); if (null == proposedElement && (originalElement.getAttribute("z").equals(calculateUniqueKeyFor(originalElement)) || originalElement .getAttribute("z").equals("?"))) { removeElements(originalElement, proposed, originalDocumentChanged);
private boolean isNotUserManaged(final Element element) { return "?".equals(element.getAttribute("z")) || XmlRoundTripUtils.calculateUniqueKeyFor(element).equals( element.getAttribute("z")); }
final Document original = XmlUtils.readXml(fileManager .getInputStream(filename)); if (XmlRoundTripUtils.compareDocuments(original, proposed)) { DomUtils.removeTextNodes(original); final String updateContents = XmlUtils
/** * This method updates tocElement if necessary with correct configuration * * * @param mapElement * @param mapId */ private void updateTocElement(Element tocElement, String zTocValue, String mapId) { String validZTocValue = XmlRoundTripUtils .calculateUniqueKeyFor((Element) tocElement); // Regenerating id if is different String validId = String.format("%s_toc", mapId); if (!tocElement.getAttribute("id").equals(validId)) { tocElement.setAttribute("id", validId); } // Regenerating zValue if is blank if (StringUtils.isBlank(zTocValue)) { tocElement.setAttribute("z", validZTocValue); } }
if (XmlRoundTripUtils.compareDocuments(original, proposed)) { mutableFile = getFileManager().updateFile(jspFilename);
/** * This method obtains map element from document or create new one if not * exists * * * @param docRoot * @param docXml * @return */ private Element getOrCreateMapElement(Element docRoot, Document docXml, String mapId) { // Getting geo:map element NodeList mapElements = docRoot.getElementsByTagName("geo:map"); Element mapElement = (Element) mapElements.item(0); // If map element not exists, generate new one if (mapElement == null) { mapElement = docXml.createElement("geo:map"); mapElement.setAttribute("id", mapId); mapElement.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(mapElement)); docRoot.appendChild(mapElement); } return mapElement; }
/** * This method obtains toolbar element from document or create new one if * not exists and append to map parent * * @param docRoot * @param docXml * @param mapElement * @param mapId * @return */ private Element getOrCreateToolbarElement(Element docRoot, Document docXml, Element mapElement, String mapId) { NodeList toolbarElements = docRoot.getElementsByTagName("geo:toolbar"); Element toolbarElement = (Element) toolbarElements.item(0); // If not exists, create new toolbar element if (toolbarElement == null) { toolbarElement = docXml.createElement("geo:toolbar"); toolbarElement.setAttribute("id", String.format("%s_toolbar", mapId)); toolbarElement.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(toolbarElement)); mapElement.appendChild(toolbarElement); } return toolbarElement; }
/** * * This method updates toolbarElement if necessary with correct * configuration * * @param toolbarElement * @param zToolbarValue * @param mapId */ private void updateToolbarElement(Element toolbarElement, String zToolbarValue, String mapId) { String idToolbarValue = toolbarElement.getAttribute("id"); // Regenerating id if necessary if (!idToolbarValue.equals(String.format("%s_toolbar", mapId))) { toolbarElement.setAttribute("id", String.format("%s_toolbar", mapId)); } // Regenerating z value if necessary if (StringUtils.isBlank(zToolbarValue)) { toolbarElement.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(toolbarElement)); } }
/** * This method updates mapElement if necessary with correct configuration * * * @param mapElement * @param mapId */ private void updateMapElement(Element mapElement, String zValue, String mapId, String projection) { // Getting correct z value String validZValue = XmlRoundTripUtils .calculateUniqueKeyFor((Element) mapElement); // Regenerating zValue if is blank if (StringUtils.isBlank(zValue)) { mapElement.setAttribute("z", validZValue); } // Regenerating id if is different if (!mapElement.getAttribute("id").equals(mapId)) { mapElement.setAttribute("id", mapId); } // Regenerating projection mapElement.setAttribute("projection", projection); }
/** * This method obtains toc element from document or create new one if not * exists and append to map parent * * @param docRoot * @param docXml * @param mapId * @return */ private Element getOrCreateTocElement(Element docRoot, Document docXml, Element mapElement, String mapId) { NodeList tocElements = docRoot.getElementsByTagName("geo:toc"); Element tocElement = (Element) tocElements.item(0); // If toc element not exists, generate new one if (tocElement == null) { tocElement = docXml.createElement("geo:toc"); tocElement.setAttribute("id", String.format("%s_toc", mapId)); tocElement.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(tocElement)); mapElement.appendChild(tocElement); } return tocElement; }
tileElement.setAttribute("allowDisable", "false"); tileElement.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(tileElement)); tocElement.appendChild(tileElement);
XmlRoundTripUtils.calculateUniqueKeyFor(tool));
XmlRoundTripUtils.calculateUniqueKeyFor(baseLayer));
String.format("%s_MiniMap", mapId)); overViewElement.setAttribute("z", XmlRoundTripUtils .calculateUniqueKeyFor(overViewElement));
.calculateUniqueKeyFor((Element) entityLayerToUpdate); if (!zEntityLayerValue.equals(validEntityLayerZValue)) { entityLayerToUpdate.setAttribute("z", .calculateUniqueKeyFor(entityField); if (!zEntityFieldValue .equals(validZEntityFieldValue)) { "z", XmlRoundTripUtils .calculateUniqueKeyFor(entityFieldLayer));
map.setAttribute("projection", projection != null ? projection.toString() : "EPSG3857"); map.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(map)); toc.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(toc)); map.appendChild(toc); toolbar.setAttribute("id", String.format("%s_toolbar", mapId)); toolbar.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(toolbar)); map.appendChild(toolbar);
document).addAttribute("id", "_menu").build(); rootMenu.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(rootMenu)); rootElement = (Element) document.getDocumentElement().appendChild( rootMenu); "c_" + lcMenuCategoryName).build()); category.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(category)); properties.put("menu_category_" + lcMenuCategoryName + "_label", menuCategoryName.getReadableSymbolName()); .addAttribute("url", link).build(); menuItem.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(menuItem)); category.appendChild(menuItem);