List of usage examples for org.w3c.dom Element removeChild
public Node removeChild(Node oldChild) throws DOMException;
oldChild
from the list of children, and returns it. From source file:org.apereo.portal.layout.dlm.PLFIntegrator.java
private static void applyChildChanges(Element plfParent, Element ilfParent, IntegrationResult result, NodeInfoTracker tracker) throws PortalException { Element positions = null;//w w w.jav a 2s . com Element node = (Element) plfParent.getFirstChild(); while (node != null) { Element nextNode = (Element) node.getNextSibling(); if (node.getNodeName().equals("folder")) mergeFolder(node, plfParent, ilfParent, result, tracker); else if (node.getNodeName().equals(Constants.ELM_POSITION_SET)) positions = node; else if (node.getNodeName().equals("channel")) mergeChannel(node, plfParent, ilfParent, result, tracker); node = nextNode; } if (positions != null) { IntegrationResult posResult = new IntegrationResult(); if (LOG.isInfoEnabled()) LOG.info("applying positions"); PositionManager.applyPositions(ilfParent, positions, posResult, tracker); if (!posResult.isChangedILF()) { if (LOG.isInfoEnabled()) LOG.info("removing positionSet"); plfParent.removeChild(positions); result.setChangedPLF(true); } else { result.setChangedILF(true); if (posResult.isChangedPLF()) result.setChangedPLF(true); } } }
From source file:org.apereo.portal.layout.dlm.PLFIntegrator.java
private static void mergeChannel(Element plfChild, Element plfParent, Element ilfParent, IntegrationResult result, NodeInfoTracker tracker) { String id = plfChild.getAttribute(Constants.ATT_ID); if (id.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) { // incorporated channel - if a copy of an inc'd channel is in the // plf it is because either it has attribute edits. It does not // imply movement. // That is accomplished by the position set. So see if it still // exists in the ilf for applying changes Document ilf = ilfParent.getOwnerDocument(); Element original = ilf.getElementById(id); if (original == null) { // not there anymore, discard from plf plfParent.removeChild(plfChild); result.setChangedPLF(true);// ww w . j ava 2 s.c o m return; } // found it, apply changes and see if they had any affect boolean attributeChanged = false; IntegrationResult childChanges = new IntegrationResult(); attributeChanged = EditManager.applyEditSet(plfChild, original); applyChildChanges(plfChild, original, childChanges, tracker); if (attributeChanged == false && !childChanges.isChangedILF()) { // no changes were used so remove this guy from plf. plfParent.removeChild(plfChild); result.setChangedPLF(true); } else result.setChangedILF(true); // need to pass on up whether PLF changed in called methods if (childChanges.isChangedPLF()) result.setChangedPLF(true); } else // plf channel { if (LOG.isInfoEnabled()) LOG.info("merging into ilf channel " + id); if (ilfParent.getAttribute(Constants.ATT_ADD_CHILD_ALLOWED).equals("false")) { if (LOG.isInfoEnabled()) LOG.info("removing from plf disallowed add of channel " + id); plfParent.removeChild(plfChild); result.setChangedPLF(true); } else { appendChild(plfChild, ilfParent, true); result.setChangedILF(true); } } }
From source file:org.apereo.portal.layout.dlm.PLFIntegrator.java
private static void mergeFolder(Element plfChild, Element plfParent, Element ilfParent, IntegrationResult result, NodeInfoTracker tracker) throws PortalException { String id = plfChild.getAttribute(Constants.ATT_ID); if (id.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) { // incorporated folder - if a copy of an inc'd folder is in the // plf it is because either it has attribute edits or there are // nested child changes to be applied. It does not imply movement. // That is accomplished by the position set. So see if it still // exists in the ilf for applying changes Document ilf = ilfParent.getOwnerDocument(); Element original = ilf.getElementById(id); if (original == null) { // not there anymore, discard from plf plfParent.removeChild(plfChild); result.setChangedPLF(true);/* w ww. j a v a 2 s. c o m*/ return; } // found it, apply changes and see if they had any affect boolean attributeChanged = false; IntegrationResult childChanges = new IntegrationResult(); attributeChanged = EditManager.applyEditSet(plfChild, original); applyChildChanges(plfChild, original, childChanges, tracker); if (attributeChanged == false && !childChanges.isChangedILF()) { // no changes were used so remove this guy from plf. plfParent.removeChild(plfChild); result.setChangedPLF(true); } else result.setChangedILF(true); // need to pass on up whether PLF changed in called methods if (childChanges.isChangedPLF()) result.setChangedPLF(true); } else { // plf folder - the real node. What is being portrayed in this // case is a plf node that is supposed to be added into the ilf // parent if (ilfParent.getAttribute(Constants.ATT_ADD_CHILD_ALLOWED).equals("false")) { // nope, delete directive from plf if (LOG.isInfoEnabled()) LOG.info("removing folder from plf " + id); plfParent.removeChild(plfChild); result.setChangedPLF(true); return; } Element ilfChild = appendChild(plfChild, ilfParent, false); result.setChangedILF(true); IntegrationResult childChanges = new IntegrationResult(); applyChildChanges(plfChild, ilfChild, childChanges, tracker); if (childChanges.isChangedPLF()) result.setChangedPLF(true); } }
From source file:org.apereo.portal.layout.dlm.PositionManager.java
/** This method trims down the position set to the position directives on the node info elements still having a position directive. Any directives that violated restrictions were removed from the node info objects so the position set should be made to match the order of those still having one./*from ww w .j a v a 2s .co m*/ */ static void adjustPositionSet(List<NodeInfo> order, Element positionSet, IntegrationResult result) { Node nodeToMatch = positionSet.getFirstChild(); Element nodeToInsertBefore = positionSet.getOwnerDocument().createElement("INSERT_POINT"); positionSet.insertBefore(nodeToInsertBefore, nodeToMatch); for (Iterator<NodeInfo> iter = order.iterator(); iter.hasNext();) { NodeInfo ni = iter.next(); if (ni.getPositionDirective() != null) { // found one check it against the current one in the position // set to see if it is different. If so then indicate that // something (the position set) has changed in the plf if (ni.getPositionDirective() != nodeToMatch) result.setChangedPLF(true); ; // now bump the insertion point forward prior to // moving on to the next position node to be evaluated if (nodeToMatch != null) nodeToMatch = nodeToMatch.getNextSibling(); // now insert it prior to insertion point positionSet.insertBefore(ni.getPositionDirective(), nodeToInsertBefore); } } // now for any left over after the insert point remove them. while (nodeToInsertBefore.getNextSibling() != null) positionSet.removeChild(nodeToInsertBefore.getNextSibling()); // now remove the insertion point positionSet.removeChild(nodeToInsertBefore); }
From source file:org.apereo.portal.layout.dlm.PositionManager.java
/** This method applies the ordering specified in the passed in order list to the child nodes of the compViewParent. Nodes specified in the list but located elsewhere are pulled in./*from w w w . j a va 2 s . co m*/ */ static void applyToNodes(List<NodeInfo> order, Element compViewParent) { // first set up a bogus node to assist with inserting Node insertPoint = compViewParent.getOwnerDocument().createElement("bogus"); Node first = compViewParent.getFirstChild(); if (first != null) compViewParent.insertBefore(insertPoint, first); else compViewParent.appendChild(insertPoint); // now pass through the order list inserting the nodes as you go for (int i = 0; i < order.size(); i++) compViewParent.insertBefore(order.get(i).getNode(), insertPoint); compViewParent.removeChild(insertPoint); }
From source file:org.apereo.portal.layout.dlm.PositionManager.java
/** This method updates the positions recorded in a position set to reflect the ids of the nodes in the composite view of the layout. Any position nodes already in existence are reused to reduce database interaction needed to generate a new ID attribute. If any are left over after updating those position elements are removed. If no position set existed a new one is created for the parent. If no ILF nodes are found in the parent node then the position set as a whole is reclaimed. *///from ww w .j a v a 2s. c o m public static void updatePositionSet(Element compViewParent, Element plfParent, IPerson person) throws PortalException { if (LOG.isDebugEnabled()) LOG.debug("Updating Position Set"); if (compViewParent.getChildNodes().getLength() == 0) { // no nodes to position. if set exists reclaim the space. if (LOG.isDebugEnabled()) LOG.debug("No Nodes to position"); Element positions = getPositionSet(plfParent, person, false); if (positions != null) plfParent.removeChild(positions); return; } Element posSet = (Element) getPositionSet(plfParent, person, true); Element position = (Element) posSet.getFirstChild(); Element viewNode = (Element) compViewParent.getFirstChild(); boolean ilfNodesFound = false; while (viewNode != null) { String ID = viewNode.getAttribute(Constants.ATT_ID); String channelId = viewNode.getAttribute(Constants.ATT_CHANNEL_ID); String type = viewNode.getAttribute(Constants.ATT_TYPE); String hidden = viewNode.getAttribute(Constants.ATT_HIDDEN); if (ID.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) ilfNodesFound = true; if (!channelId.equals("") || // its a channel node or (type.equals("regular") && // a regular, visible folder hidden.equals("false"))) { if (position != null) position.setAttribute(Constants.ATT_NAME, ID); else position = createAndAppendPosition(ID, posSet, person); position = (Element) position.getNextSibling(); } viewNode = (Element) viewNode.getNextSibling(); } if (ilfNodesFound == false) // only plf nodes, no pos set needed plfParent.removeChild(posSet); else { // reclaim any leftover positions while (position != null) { Element nextPos = (Element) position.getNextSibling(); posSet.removeChild(position); position = nextPos; } } }
From source file:org.apereo.portal.layout.dlm.TabColumnPrefsHandler.java
/** Handles user requests to delete UI elements. For ILF owned nodes it delegates to the DeleteManager to add a delete directive. For PLF owned nodes it deletes the node outright. *///from w ww .ja v a 2s . co m public static void deleteNode(Element compViewNode, Element compViewParent, IPerson person) throws PortalException { String ID = compViewNode.getAttribute(Constants.ATT_ID); if (ID.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) // ilf node DeleteManager.addDeleteDirective(compViewNode, ID, person); else { // plf node Document plf = (Document) person.getAttribute(Constants.PLF); Element node = plf.getElementById(ID); if (node == null) return; Element parent = (Element) node.getParentNode(); if (parent == null) return; parent.removeChild(node); } }
From source file:org.chiba.xml.xforms.Container.java
/** * imports the passed input Element into the Containers' DOM Document by appending them as a child of the specified * instance Element./*from w w w.j a v a 2s .c om*/ * * @param id the instance id where to place the new instancedata * @param e the input DOM Element to be imported * @throws XFormsException */ public void importInstance(String id, Element e) throws XFormsException { Element instanceElement = findElement(XFormsConstants.INSTANCE, id); if (instanceElement == null) { throw new XFormsException("instance element '" + id + "' not found"); } Element firstChild = DOMUtil.getFirstChildElement(instanceElement); if (firstChild != null) { instanceElement.removeChild(firstChild); } Element newElement = (Element) getDocument().importNode(e, true); instanceElement.appendChild(newElement); }
From source file:org.commonjava.maven.plugins.monolith.handler.PluginDescriptorHandler.java
@Override protected boolean process(final FileInfo fileInfo) throws IOException { if (fileInfo.isFile()) { String entry = fileInfo.getName().replace('\\', '/'); if (entry.startsWith("/")) { entry = entry.substring(1);//from w ww . j ava 2 s. co m } if (PLUGIN_XML_PATH.equals(entry)) { logger.info("Found plugin descriptor..."); if (doc == null) { logger.info("Parsing plugin descriptor."); try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(fileInfo.getContents()); } catch (final SAXException e) { throw new ArchiverException("Failed to parse plugin.xml file: " + e.getMessage(), e); } catch (final ParserConfigurationException e) { throw new ArchiverException("Failed to parse plugin.xml file: " + e.getMessage(), e); } final String modifiedVersion = monolithVersioningContext.getCurrentMonolithVersion(); if (modifiedVersion != null) { final Element version = getChild(doc.getDocumentElement(), "version"); if (version != null && !version.getTextContent().equals(modifiedVersion)) { version.setTextContent(modifiedVersion); } } final Element depRoot = getChild(doc.getDocumentElement(), "dependencies"); if (depRoot != null) { final List<Element> deps = getChildren(depRoot, "dependency"); for (final Element dep : deps) { if (!monolithVersioningContext.isMonolith(dep)) { depRoot.removeChild(dep); } } } } else { logger.info("Skipping...plugin descriptor was already stored for inclusion."); } return true; } } return false; }
From source file:org.dita.dost.AbstractIntegrationTest.java
private void removeWorkdirProcessingInstruction(final Element e) { Node n = e.getFirstChild();/* w ww.j av a 2 s .c o m*/ while (n != null) { final Node next = n.getNextSibling(); if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE && (n.getNodeName().equals(PI_WORKDIR_TARGET) || n.getNodeName().equals(PI_WORKDIR_TARGET_URI))) { e.removeChild(n); } n = next; } }