List of usage examples for org.dom4j Element remove
boolean remove(Text text);
Text
if the node is an immediate child of this element. From source file:cn.com.iscs.base.util.XMLProperties.java
License:Open Source License
/** * Deletes the specified property./* ww w .j a v a 2 s .co m*/ * * @param name * the property to delete. */ public synchronized void deleteProperty(String name) { // Remove property from cache. propertyCache.remove(name); String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML heirarchy. Element element = document.getRootElement(); for (int i = 0; i < propName.length - 1; i++) { element = element.element(propName[i]); // Can't find the property so return. if (element == null) { return; } } // Found the correct element to remove, so remove it... element.remove(element.element(propName[propName.length - 1])); // .. then write to disk. saveProperties(); // Generate event. Map<String, Object> params = Collections.emptyMap(); // PropertyEventDispatcher.dispatchEvent(name, PropertyEventDispatcher.EventType.xml_property_deleted, params); }
From source file:com.adspore.splat.xep0060.NodeAffiliate.java
License:Open Source License
/** * Sends an event notification for the published items to the affiliate. The event * notification may contain zero, one or many published items based on the items * included in the original publication. If the affiliate has many subscriptions and * many items were published then the affiliate will get a notification for each set * of items that affected the same subscriptions. * * @param notification the message to sent to the subscribers. The message will be completed * with the items to include in each notification. * @param event the event Element included in the notification message. Passed as an * optimization to avoid future look ups. * @param leafNode the leaf node where the items where published. * @param publishedItems the list of items that were published. Could be an empty list. */// ww w .jav a 2 s. c om void sendPublishedNotifications(Message notification, Element event, LeafNode leafNode, List<PublishedItem> publishedItems) { if (!publishedItems.isEmpty()) { Map<List<NodeSubscription>, List<PublishedItem>> itemsBySubs = getItemsBySubscriptions(leafNode, publishedItems); // Send one notification for published items that affect the same subscriptions for (List<NodeSubscription> nodeSubscriptions : itemsBySubs.keySet()) { // Add items information Element items = event.addElement("items"); items.addAttribute("node", getNode().getNodeID()); for (PublishedItem publishedItem : itemsBySubs.get(nodeSubscriptions)) { // FIXME: This was added for compatibility with PEP supporting clients. // Alternate solution needed when XEP-0163 version > 1.0 is released. // // If the node ID looks like a JID, replace it with the published item's node ID. if (getNode().getNodeID().indexOf("@") >= 0) { items.addAttribute("node", publishedItem.getNodeID()); } // Add item information to the event notification Element item = items.addElement("item"); if (leafNode.isItemRequired()) { item.addAttribute("id", publishedItem.getID()); } if (leafNode.isPayloadDelivered()) { item.add(publishedItem.getPayload().createCopy()); } // Add leaf leafNode information if affiliated leafNode and node // where the item was published are different if (leafNode != getNode()) { item.addAttribute("node", leafNode.getNodeID()); } } // Send the event notification sendEventNotification(notification, nodeSubscriptions); // Remove the added items information event.remove(items); } } else { // Filter affiliate subscriptions and only use approved and configured ones List<NodeSubscription> affectedSubscriptions = new ArrayList<NodeSubscription>(); for (NodeSubscription subscription : getSubscriptions()) { if (subscription.canSendPublicationEvent(leafNode, null)) { affectedSubscriptions.add(subscription); } } // Add item information to the event notification Element items = event.addElement("items"); items.addAttribute("node", leafNode.getNodeID()); // Send the event notification sendEventNotification(notification, affectedSubscriptions); // Remove the added items information event.remove(items); } }
From source file:com.adspore.splat.xep0060.NodeAffiliate.java
License:Open Source License
/** * Sends an event notification to the affiliate for the deleted items. The event * notification may contain one or many published items based on the items included * in the original publication. If the affiliate has many subscriptions and many * items were deleted then the affiliate will get a notification for each set * of items that affected the same subscriptions. * * @param notification the message to sent to the subscribers. The message will be completed * with the items to include in each notification. * @param event the event Element included in the notification message. Passed as an * optimization to avoid future look ups. * @param leafNode the leaf node where the items where deleted from. * @param publishedItems the list of items that were deleted. *///from ww w.j a v a2s . co m void sendDeletionNotifications(Message notification, Element event, LeafNode leafNode, List<PublishedItem> publishedItems) { if (!publishedItems.isEmpty()) { Map<List<NodeSubscription>, List<PublishedItem>> itemsBySubs = getItemsBySubscriptions(leafNode, publishedItems); // Send one notification for published items that affect the same subscriptions for (List<NodeSubscription> nodeSubscriptions : itemsBySubs.keySet()) { // Add items information Element items = event.addElement("items"); items.addAttribute("node", leafNode.getNodeID()); for (PublishedItem publishedItem : itemsBySubs.get(nodeSubscriptions)) { // Add retract information to the event notification Element item = items.addElement("retract"); if (leafNode.isItemRequired()) { item.addAttribute("id", publishedItem.getID()); } } // Send the event notification sendEventNotification(notification, nodeSubscriptions); // Remove the added items information event.remove(items); } } }
From source file:com.alibaba.citrus.springext.support.SchemaUtil.java
License:Open Source License
/** element/attribute??namespace */ public static Transformer getUnqualifiedStyleTransformer(ResourceResolver resourceResolver) { if (isUnqualifiedStyle(resourceResolver)) { return new Transformer() { public void transform(Document document, String systemId) { Element root = document.getRootElement(); if (root.attribute("elementFormDefault") != null) { root.remove(root.attribute("elementFormDefault")); }//from w ww . j a v a 2 s . com if (root.attribute("attributeFormDefault") != null) { root.remove(root.attribute("attributeFormDefault")); } } }; } else { return getNoopTransformer(); } }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void removeChild(TreeObject parent, TreeObject child) { if (parent.getParent() == null && parent.getDisplayName().equals("INVISIBLE ROOT")) { return;// w w w. ja v a 2s .c o m } if (synchronize) { synchronizeWithElem(child, (TreeParent) parent, true); } Element elemFolder = getParentElement(parent); String xpath = "child::*[name()='" + filterOutBlank(child.getDisplayName()) + "' and text()='" //$NON-NLS-1$//$NON-NLS-2$ + child.getType() + "']";//$NON-NLS-1$ if (elemFolder == null) { return; } List<Element> list = elemFolder.selectNodes(xpath); if (!list.isEmpty()) { elemFolder.remove(list.get(0)); } saveDocument(parent); }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void addAttributeToCategoryElem(TreeParent category, String attrName, String defaultAttrValue) { Element elem = locateCategoryElement(category); Attribute attr = elem.attribute(attrName); if (attr != null) { elem.remove(attr); }//from w w w . j ava 2 s .c o m elem.addAttribute(attrName, defaultAttrValue); }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public void makeUpDocWithImportCategory(String[] schemas, TreeParent serverRoot) { if (serverRoot.getServerRoot() == null) { return;/*from w w w . ja v a 2 s. c o m*/ } Document orgDoc = credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc; // spareDoc is meant to show the category when import digloag is launched spareDoc = (Document) orgDoc.clone(); if (schemas != null) { for (String schema : schemas) { Element subRoot = parseElements(schema); String subRootXquery = "descendant::" + subRoot.getName() + "[text()='" + subRoot.getTextTrim() //$NON-NLS-1$//$NON-NLS-2$ + "']";//$NON-NLS-1$ Element division = pingElement(subRootXquery, spareDoc.getRootElement()); if (division == null || division.getParent() == null) { return; } Element divisionParent = division.getParent(); divisionParent.remove(division); divisionParent.add((Element) subRoot.clone()); } String url = getURLFromTreeObject(serverRoot); String urlXquery = "descendant::*[@Url != '" + url + "']";//$NON-NLS-1$//$NON-NLS-2$ List<Element> elems = spareDoc.selectNodes(urlXquery); for (Element elem : elems) { elem.addAttribute("Url", url);//$NON-NLS-1$ } } credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc = spareDoc; spareDoc = orgDoc; importCategories = schemas; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void mergeImportCategory(String[] schemas, TreeParent serverRoot, ArrayList<String> xpathsToDel) { if (serverRoot.getServerRoot() == null) { return;// www . j a v a2s. c o m } Document orgDoc = spareDoc; String user = serverRoot.getServerRoot().getUser().getUsername(); String xpathPrefix = "/category/" + user;//$NON-NLS-1$ String xmlPrefix = "<category><" + user + ">*</" + user + "></category>";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (schemas == null) // old version, skip the import { credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc = orgDoc; return; } for (String schema : schemas) { Element root = parseElements(xmlPrefix.replace("*", schema));//$NON-NLS-1$ Element subRoot = parseElements(schema); // delete all unselected xobjects from orgDoc for (String xpathToDel : xpathsToDel) { Element elemToDel = pingElement(xpathToDel, root); if (elemToDel != null) { Element parent = elemToDel.getParent(); if (parent != null) { parent.remove(elemToDel); } } } // check out all categories having none child, and delete them if available String xpathForCategoriesWithNoneChild = "//child::*[count(child::*) = 0 and text()='" //$NON-NLS-1$ + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$ Element categoryToDel = pingElement(xpathForCategoriesWithNoneChild, root); while (categoryToDel != null) { Element categoryParent = categoryToDel.getParent(); if (categoryParent != null) { categoryParent.remove(categoryToDel); } categoryToDel = pingElement(xpathForCategoriesWithNoneChild, root); } subRoot = this.pingElement(xpathPrefix + "/" + subRoot.getName(), root);//$NON-NLS-1$ String xpathForCategory = "//descendant::*[text()='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$ List<Element> elementList = subRoot.selectNodes(xpathForCategory); List<String> categoryXpathForCurDoc = new ArrayList<String>(); List<String> categoryXpathForOrgDoc = new ArrayList<String>(); for (Element element : elementList) { List<String> categoryHierarchicals = parseXpathForElement(element, subRoot); String xpathForOrgCategory = xpathPrefix + "/" + subRoot.getName();//$NON-NLS-1$ for (String categoryHierarchical : categoryHierarchicals) { xpathForOrgCategory += "/" + categoryHierarchical;//$NON-NLS-1$ } if (!categoryXpathForOrgDoc.contains(xpathForOrgCategory)) { categoryXpathForOrgDoc.add(xpathForOrgCategory); } } xpathForCategory = xpathPrefix + "/" + subRoot.getName() + "//descendant::*[text()='" //$NON-NLS-1$//$NON-NLS-2$ + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$ // String xpathForOrgCategory = xpathPrefix + "/" + subRoot.getName() + "//descendant::" + element.getName() // + "[text()='" + element.getTextTrim() + "']"; String topElemXpath = xpathPrefix + "/" + subRoot.getName();//$NON-NLS-1$ Element topElem = pingElement(topElemXpath, orgDoc.getRootElement()); elementList = orgDoc.getRootElement().selectNodes(xpathForCategory); for (Element elem : elementList) { List<String> categoryHierarchicals = parseXpathForElement(elem, topElem); String xpathForOrgCategory = xpathPrefix + "/" + subRoot.getName();//$NON-NLS-1$ for (String categoryHierarchical : categoryHierarchicals) { xpathForOrgCategory += "/" + categoryHierarchical;//$NON-NLS-1$ } if (!categoryXpathForCurDoc.contains(xpathForOrgCategory)) { categoryXpathForCurDoc.add(xpathForOrgCategory); } } for (String categoryHierarchical : categoryXpathForOrgDoc) { createOrReplaceCategory(categoryHierarchical, categoryXpathForCurDoc, root, orgDoc.getRootElement(), serverRoot); } } // success credentials.get(UnifyUrl(serverRoot.getServerRoot().getWsKey().toString())).doc = orgDoc; }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void transferElementsWithCategoryPath(String categoryXpath, Element srcElemRoot, Element targtElemRoot) {/* ww w . j a va 2 s . c om*/ categoryXpath += "[text()='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$ // clear up the context of targtElemRoot firstly Element elemCategoryInTagt = pingElement(categoryXpath, targtElemRoot); List elems = elemCategoryInTagt.content(); List xobjects = new ArrayList(); for (Object obj : elems) { if (obj instanceof Element) { Element elem = (Element) obj; if (!elem.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$ Element division = drillUpForDevisionElement(elem); division.addElement(elem.getName()).setText(elem.getTextTrim()); xobjects.add(elem); } } } elemCategoryInTagt.content().removeAll(xobjects); Element elemCategoryInSrc = pingElement(categoryXpath, srcElemRoot); elems = elemCategoryInSrc.content(); for (Object obj : elems) { if (obj instanceof Element) { Element elem = (Element) obj; if (!elem.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$ String xpath = ".//descendant::" + elem.getName() + "[text()='" + elem.getTextTrim() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ List<Element> es = targtElemRoot.selectNodes(xpath); Element newElem = null; for (Element elemExist : es) { if (elemExist.getParent() != null && elemExist.getParent().getTextTrim().equals(TreeObject.EVENT_MANAGEMENT + "")) { continue; } if (elemExist != null) { Element parentExist = elemExist.getParent(); parentExist.remove(elemExist); } elemExist = pingElement(categoryXpath, targtElemRoot); newElem = elemExist.addElement(elem.getName()); newElem.setText(elem.getTextTrim()); } if (es.size() == 0 || (es.size() > 0 && newElem == null)) { Element elemExist = pingElement(categoryXpath, targtElemRoot); newElem = elemExist.addElement(elem.getName()); newElem.setText(elem.getTextTrim()); } } } } }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public void parseElementForOutput(TreeObject[] xobjs) { for (TreeObject xobj : xobjs) { TreeObject subParent = xobj;//from w w w . ja v a 2 s . c o m while (subParent.getParent().getType() != 0) { subParent = subParent.getParent(); } Element modelElem = getParentElement(subParent); if (!outPutSchemas.containsKey(modelElem.getName())) { Element copyElem = (Element) modelElem.clone(); copyElem.clearContent(); copyElem.setText(modelElem.getTextTrim()); outPutSchemas.put(modelElem.getName(), copyElem); } subParent = xobj; TreeObject categorySubRoot = null; while (subParent.getParent().getType() == TreeObject.CATEGORY_FOLDER) { categorySubRoot = subParent.getParent(); subParent = subParent.getParent(); } Element divisionElem = null; Element copyModelElem = outPutSchemas.get(modelElem.getName()); Document doc = credentials.get(UnifyUrl(xobj.getServerRoot().getWsKey().toString())).doc; String division = xobj.getType() == TreeObject.TRANSFORMER ? "Process" : "Trigger";//$NON-NLS-1$//$NON-NLS-2$ String xpathForDivision = ".//child::" + division + "[text()='" + xobj.getType() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (categorySubRoot != null) { Element categoryElem = getParentElement(categorySubRoot); if (categoryElem.getParent() != modelElem) { divisionElem = pingElement(xpathForDivision, copyModelElem); if (divisionElem == null) { divisionElem = copyModelElem.addElement(categoryElem.getParent().getName()); divisionElem.setText(categoryElem.getParent().getTextTrim()); } } else { divisionElem = copyModelElem; } Element categoryElementClone = (Element) categoryElem.clone(); String xpath = "./child::" + categoryElem.getName() + "[text()='" + TreeObject.CATEGORY_FOLDER //$NON-NLS-1$//$NON-NLS-2$ + "']";//$NON-NLS-1$ if (divisionElem.selectNodes(xpath).size() == 0) { divisionElem.add(categoryElementClone); } } else { // individual xobject Element xobjElem = pingElement(getXPathForTreeObject(xobj), doc.getRootElement()); Element parentElem = xobjElem.getParent(); if (parentElem == modelElem) { parentElem = copyModelElem; } else { divisionElem = pingElement(xpathForDivision, copyModelElem); if (divisionElem == null) { divisionElem = copyModelElem.addElement(parentElem.getName()); divisionElem.setText(parentElem.getTextTrim()); } } String xpath = ".//child::" + xobjElem.getName() + "[text()='" + xobjElem.getTextTrim() + "']";//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ if (divisionElem != null && pingElement(xpath, divisionElem) == null) { divisionElem.add((Element) xobjElem.clone()); } } } // filter those excluded from xobjects out of categorys String xpath = ".//descendant::*[text() ='" + TreeObject.CATEGORY_FOLDER + "']";//$NON-NLS-1$//$NON-NLS-2$ Iterator<Element> iter = outPutSchemas.values().iterator(); while (iter.hasNext()) { Element divisionElement = iter.next(); List<Element> categorys = divisionElement.selectNodes(xpath); if (categorys != null) { for (Element categoryElems : categorys) { List objs = categoryElems.content(); List<Element> elemToDel = new ArrayList<Element>(); for (Object obj : objs) { if (obj instanceof Element) { Element categoryElement = (Element) obj; if (categoryElement.getTextTrim().equals(TreeObject.CATEGORY_FOLDER + "")) { continue; } boolean match = false; for (TreeObject xobj : xobjs) { if (filterOutBlank(xobj.getDisplayName()).equals(categoryElement.getName()) && categoryElement.getTextTrim().equals(xobj.getType() + "")) {//$NON-NLS-1$ match = true; break; } } if (!match) { elemToDel.add(categoryElement); } } } for (Element del : elemToDel) { categoryElems.remove(del); } } } } ArrayList<String> schemas = new ArrayList<String>(); Iterator<Element> iterd = outPutSchemas.values().iterator(); while (iterd.hasNext()) { schemas.add(iterd.next().asXML()); } }