private void removeAttributeWithValue(String attributeName, String value, MetadataElement parentElement) { final MetadataElement[] childElements = parentElement.getElements(); for (MetadataElement elem : childElements) { if (elem.getAttributeString(attributeName).equals(value)) { parentElement.removeElement(elem); return; } } }
private static void removeUnusedMetadata(final MetadataElement root) { final MetadataElement[] elems = root.getElements(); for (MetadataElement elem : elems) { final String name = elem.getName(); boolean keep = false; for (String toKeep : elemsToKeep) { if (name.equals(toKeep)) { keep = true; break; } } if (!keep) { root.removeElement(elem); elem.dispose(); } } } }
MetadataElement element = metadataRoot.getElement(headerName); metadataElementBackup.add(element); metadataRoot.removeElement(element); final MetadataElement element = metadataRoot.getElement("History"); metadataElementBackup.add(element); metadataRoot.removeElement(element); final MetadataElement element = metadataRoot.getElement(name); metadataElementBackup.add(element); metadataRoot.removeElement(element);
/** * Adds a given elem to the history of the given product. If the products metadata root * does not contain a history entry a new one will be created. * * @param product the product to add the history element. * @param elem the element to add to the products history. If <code>null</code> nothing will be added. */ public static void addElementToHistory(Product product, MetadataElement elem) { Guardian.assertNotNull("product", product); if (elem != null) { final String historyName = Product.HISTORY_ROOT_NAME; final MetadataElement metadataRoot = product.getMetadataRoot(); if (!metadataRoot.containsElement(historyName)) { metadataRoot.addElement(new MetadataElement(historyName)); } final MetadataElement historyElem; historyElem = metadataRoot.getElement(historyName); if (historyElem.containsElement(elem.getName())) { final MetadataElement previousElem = historyElem.getElement(elem.getName()); historyElem.removeElement(previousElem); elem.addElement(previousElem); } historyElem.addElement(elem); } }