List of usage examples for org.w3c.dom Node equals
public boolean equals(Object obj)
From source file:org.asqatasun.processing.ProcessRemarkServiceImpl.java
/** * This methods search the line where the current node is present in * the source code/* w w w. ja v a 2s. c om*/ * @param node * @return */ private int getNodeIndex(Node node) { try { XPathExpression xPathExpression = xpath.compile("//" + node.getNodeName().toUpperCase()); Object result = xPathExpression.evaluate(document, XPathConstants.NODESET); NodeList nodeList = (NodeList) result; for (int i = 0; i < nodeList.getLength(); i++) { Node current = nodeList.item(i); if (current.equals(node)) { return i; } } } catch (XPathExpressionException ex) { LOGGER.error("Error occured while searching index of a node " + ex.getMessage()); throw new RuntimeException(ex); } return -1; }
From source file:org.asqatasun.processor.DOMHandlerImpl.java
protected int getNodeIndex(Node node) { NodeList nodeList = document.getElementsByTagName(node.getNodeName()); for (int i = 0; i < nodeList.getLength(); i++) { Node current = nodeList.item(i); if (current.equals(node)) { return i; }//from w ww . j a v a2 s .c om } return -1; }
From source file:org.etudes.component.app.melete.SubSectionUtilImpl.java
public String moveAllUpSection(String sectionsSeqXML, String section_id) throws MeleteException { try {//from w w w .java2s. c o m org.w3c.dom.Document subSectionW3CDOM = Xml.readDocumentFromString(sectionsSeqXML); org.w3c.dom.Element root = subSectionW3CDOM.getDocumentElement(); org.w3c.dom.Element moveUpThisElement = subSectionW3CDOM.getElementById(section_id); org.w3c.dom.Node moveUpThisElementParent = moveUpThisElement.getParentNode(); org.w3c.dom.Node cloneMoveElement = moveUpThisElement.cloneNode(true); org.w3c.dom.Node FirstChildOfmoveUpThisElementParent = moveUpThisElementParent.getFirstChild(); if (!FirstChildOfmoveUpThisElementParent.equals(moveUpThisElement)) { moveUpThisElementParent.insertBefore(cloneMoveElement, FirstChildOfmoveUpThisElementParent); moveUpThisElementParent.removeChild(moveUpThisElement); } return writeDocumentToString(subSectionW3CDOM); } catch (Exception ex) { if (logger.isDebugEnabled()) { logger.debug("some other error on moving up subsections xml string" + ex.toString()); ex.printStackTrace(); } throw new MeleteException("move_up_fail"); } }
From source file:org.etudes.component.app.melete.SubSectionUtilImpl.java
public String moveAllDownSection(String sectionsSeqXML, String section_id) throws MeleteException { try {/*from w w w.ja v a2 s.c om*/ org.w3c.dom.Document subSectionW3CDOM = Xml.readDocumentFromString(sectionsSeqXML); org.w3c.dom.Element root = subSectionW3CDOM.getDocumentElement(); org.w3c.dom.Element moveDownThisElement = subSectionW3CDOM.getElementById(section_id); org.w3c.dom.Node cloneMoveElement = moveDownThisElement.cloneNode(true); org.w3c.dom.Node afterElementParent = moveDownThisElement.getParentNode(); org.w3c.dom.Node LastChildOfafterElementParent = afterElementParent.getLastChild(); org.w3c.dom.Node cloneLastChildElement = LastChildOfafterElementParent.cloneNode(true); if (!LastChildOfafterElementParent.equals(moveDownThisElement)) { afterElementParent.replaceChild(cloneMoveElement, LastChildOfafterElementParent); org.w3c.dom.Node newLastChild = afterElementParent.getLastChild(); afterElementParent.insertBefore(cloneLastChildElement, newLastChild); afterElementParent.removeChild(moveDownThisElement); } return writeDocumentToString(subSectionW3CDOM); } catch (Exception ex) { if (logger.isDebugEnabled()) { logger.debug("some other error on moving down subsections xml string" + ex.toString()); ex.printStackTrace(); } throw new MeleteException("move_down_fail"); } }
From source file:org.glom.app.libglom.Document.java
/** * getElementsByTagName() is recursive, but we do not want that. * * @param parentNode/*from ww w . j av a 2 s. co m*/ * @param tagName * @return */ private List<Node> getChildrenByTagName(final Element parentNode, final String tagName) { final List<Node> result = new ArrayList<>(); final NodeList list = parentNode.getElementsByTagName(tagName); final int num = list.getLength(); for (int i = 0; i < num; i++) { final Node node = list.item(i); if (node == null) { continue; } final Node itemParentNode = node.getParentNode(); if (itemParentNode.equals(parentNode)) { result.add(node); } } return result; }
From source file:org.glom.web.server.libglom.Document.java
/** * getElementsByTagName() is recursive, but we do not want that. * /*from w ww . j a va 2 s . c o m*/ * @param node * @param * @return */ private List<Node> getChildrenByTagName(final Element parentNode, final String tagName) { final List<Node> result = new ArrayList<Node>(); final NodeList list = parentNode.getElementsByTagName(tagName); final int num = list.getLength(); for (int i = 0; i < num; i++) { final Node node = list.item(i); if (node == null) { continue; } final Node itemParentNode = node.getParentNode(); if (itemParentNode.equals(parentNode)) { result.add(node); } } return result; }
From source file:org.silverpeas.SilverpeasSettings.xml.transform.XPathTransformer.java
/** * Transform the DOM tree using the configuration. * @param configuration the transformation configuration. * @param doc the DOM tree to be updated. *///from w ww . j av a 2 s. com protected void applyTransformation(XmlConfiguration configuration, Document doc) { List<Parameter> parameters = configuration.getParameters(); for (Parameter parameter : parameters) { displayMessageln("\t" + parameter.getKey() + " (mode:" + parameter.getMode() + ")"); Node rootXpathNode = getMatchingNode(parameter.getKey(), doc); if (rootXpathNode != null) { for (Value value : parameter.getValues()) { switch (value.getMode()) { case XmlTreeHandler.MODE_INSERT: { createNewNode(doc, rootXpathNode, value); } break; case XmlTreeHandler.MODE_DELETE: { Node deletedNode = getMatchingNode(value.getLocation(), rootXpathNode); rootXpathNode.removeChild(deletedNode); } break; case XmlTreeHandler.MODE_UPDATE: { Node oldNode = getMatchingNode(value.getLocation(), rootXpathNode); if (oldNode == null) { createNewNode(doc, rootXpathNode, value); } else { if (rootXpathNode.equals(oldNode)) { rootXpathNode = rootXpathNode.getParentNode(); } Node newNode = oldNode.cloneNode(true); if (oldNode instanceof Element) { ((Element) newNode).setTextContent(value.getValue()); rootXpathNode.replaceChild(newNode, oldNode); } else { ((Attr) newNode).setValue(value.getValue()); rootXpathNode.getAttributes().setNamedItem(newNode); } } break; } } } } } }
From source file:org.silverpeas.util.xml.transform.XPathTransformer.java
/** * Transform the DOM tree using the configuration. * * @param configuration the transformation configuration. * @param doc the DOM tree to be updated. *///from w ww .ja v a 2 s .c o m protected void applyTransformation(XmlConfiguration configuration, Document doc) { List<Parameter> parameters = configuration.getParameters(); for (Parameter parameter : parameters) { console.printMessage('\t' + parameter.getKey() + " (mode:" + parameter.getMode() + ')'); Node rootXpathNode = getMatchingNode(parameter.getKey(), doc); if (rootXpathNode != null) { for (Value value : parameter.getValues()) { switch (value.getMode()) { case XmlTreeHandler.MODE_INSERT: { createNewNode(doc, rootXpathNode, value); } break; case XmlTreeHandler.MODE_DELETE: { Node deletedNode = getMatchingNode(value.getLocation(), rootXpathNode); rootXpathNode.removeChild(deletedNode); } break; case XmlTreeHandler.MODE_UPDATE: { Node oldNode = getMatchingNode(value.getLocation(), rootXpathNode); if (oldNode == null) { createNewNode(doc, rootXpathNode, value); } else { if (rootXpathNode.equals(oldNode)) { rootXpathNode = rootXpathNode.getParentNode(); } Node newNode = oldNode.cloneNode(true); if (oldNode instanceof Element) { newNode.setTextContent(value.getValue()); rootXpathNode.replaceChild(newNode, oldNode); } else { ((Attr) newNode).setValue(value.getValue()); rootXpathNode.getAttributes().setNamedItem(newNode); } } break; } } } } } }