@Override public String getProperty(String name) { Element property = DomHelper.getElement(String.format(DomHelper.PROPERTY_ELEMENT_FORMAT, name), element, false); if (property == null) { return null; } return DomHelper.getElementContent(DomHelper.VALUE_ELEMENT_NAME, property); }
@NotNull static Element setElementContent(String elementPath, Element parentElement, String value) { Element result = getElement(elementPath, parentElement, true); result.setTextContent(value); return result; }
public boolean shouldProtect(String name) { Element protectionElement = DomHelper.getElement("MemoryProtection/Protect" + name, dbMeta, false); if (protectionElement == null) { return false; } return Boolean.valueOf(protectionElement.getTextContent()); }
static boolean removeElement(String elementPath, Element parentElement) { Element toRemove = getElement(elementPath, parentElement, false); if (toRemove == null) { return false; } else { toRemove.getParentNode().removeChild(toRemove); return true; } }
@Nullable static String getElementContent(String elementPath, Element parentElement) { Element result = getElement(elementPath, parentElement, false); return (result == null) ? null : result.getTextContent(); }
@Nullable static byte[] getBinaryElementContent(String elementPath, Element parentElement) { Element result = getElement(elementPath, parentElement, false); if (result == null) { return null; } String id = result.getAttribute("Ref"); Element content = getElement("//Binaries/Binary[@ID=" + id + "]", parentElement.getOwnerDocument().getDocumentElement(),false); if (content == null) { throw new IllegalStateException("Could not find binary content with ID " + id); } return Helpers.decodeBase64Content(content.getTextContent().getBytes(), content.hasAttribute("Compressed")); }
@NotNull static String ensureElementContent(String elementPath, Element parentElement, @NotNull String value) { Element result = getElement(elementPath, parentElement, false); if (result == null) { result = createHierarchically(elementPath, parentElement); result.setTextContent(value); } return result.getTextContent(); }
@Override public byte[] getBinaryProperty(String name) { Element property = DomHelper.getElement(String.format(DomHelper.BINARY_PROPERTY_ELEMENT_FORMAT, name), element, false); if (property == null) { return null; } return DomHelper.getBinaryElementContent(DomHelper.VALUE_ELEMENT_NAME, property); }
private void ensureProperty(String name){ Element property = DomHelper.getElement(String.format(DomHelper.PROPERTY_ELEMENT_FORMAT, name), element, false); if (property == null) { Element container = DomHelper.newElement("String", element); DomHelper.setElementContent("Key", container, name); DomHelper.getElement("Value", container, true); } }
@Override public DomIconWrapper getIcon() { return new DomIconWrapper(DomHelper.getElement(DomHelper.ICON_ELEMENT_NAME, element, false)); }
@Override public DomIconWrapper getIcon() { return new DomIconWrapper(getElement(ICON_ELEMENT_NAME, element, false)); }
@NotNull static Element setBinaryElementContent(String elementPath, Element parentElement, byte[] value) { try { String b64 = Helpers.encodeBase64Content(value, true); //Find the highest numbered existing content String max = xpath.evaluate("//Binaries/Binary/@ID[not(. < ../../Binary/@ID)][1]", parentElement.getOwnerDocument().getDocumentElement()); Integer newIndex = Integer.valueOf(max) + 1; Element binaries = getElement("//Binaries", parentElement.getOwnerDocument().getDocumentElement(),false); if (binaries == null) { throw new IllegalStateException("Binaries not found"); } Element binary = (Element) binaries.appendChild(binaries.getOwnerDocument().createElement("Binary")); binary.setTextContent(b64); binary.setAttribute("Compressed", "True"); binary.setAttribute("ID", newIndex.toString()); Element result = getElement(elementPath, parentElement, true); result.setAttribute("Ref", newIndex.toString()); return result; } catch (XPathExpressionException e) { throw new IllegalStateException(e); } }
@Override public void setIcon(DomIconWrapper icon) { DomHelper.getElement(DomHelper.ICON_ELEMENT_NAME, element, true).setTextContent(String.valueOf(icon.getIndex())); DomHelper.touchElement(DomHelper.LAST_MODIFICATION_TIME_ELEMENT_NAME, element); database.setDirty(true); }
@Override public void setBinaryProperty(String name, byte[] value) { Element property = DomHelper.getElement(String.format(DomHelper.BINARY_PROPERTY_ELEMENT_FORMAT, name), element, false); if (property == null) { property = DomHelper.newElement("Binary", element); DomHelper.setElementContent("Key", property, name); } DomHelper.setBinaryElementContent(DomHelper.VALUE_ELEMENT_NAME, property, value); DomHelper.touchElement(DomHelper.LAST_MODIFICATION_TIME_ELEMENT_NAME, element); database.setDirty(true); }
@Override public void setProperty(String name, String value) { Element property = DomHelper.getElement(String.format(DomHelper.PROPERTY_ELEMENT_FORMAT, name), element, false); if (property == null) { property = DomHelper.newElement("String", element); DomHelper.setElementContent("Key", property, name); } DomHelper.setElementContent(DomHelper.VALUE_ELEMENT_NAME, property, value); DomHelper.touchElement(DomHelper.LAST_MODIFICATION_TIME_ELEMENT_NAME, element); database.setDirty(true); }