List of usage examples for org.dom4j Node getParent
Element getParent();
getParent
returns the parent Element
if this node supports the parent relationship or null if it is the root element or does not support the parent relationship.
From source file:com.globalsight.cxe.adapter.msoffice.WordRepairer.java
License:Apache License
private static void forTextInWp(Element element) { @SuppressWarnings("unchecked") List<Node> ts = element.selectNodes("//w:p/text()"); for (Node t : ts) { String c = t.getText();//from ww w. ja v a 2 s . co m if (c.matches("[\n\r]*")) { continue; } Element wp = t.getParent(); Element wr = DocumentHelper.createElement("w:r"); wp.content().add(wp.indexOf(t), wr); Element wt = wr.addElement("w:t"); wt.setText(t.getText()); wp.remove(t); } }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
/** * Judge if current node is in target TUV element. * // ww w . j av a2 s. c o m * @param p_node * @return */ private boolean isInTargetTuv(Node p_node) { boolean result = false; if (p_node == null) { return false; } Element parentNode = p_node.getParent(); while (parentNode != null) { // In Tuv. String nodeName = parentNode.getName(); if ("Tuv".equalsIgnoreCase(nodeName)) { Attribute langAtt = parentNode.attribute(TTXConstants.TUV_ATT_LANG); String attName = langAtt.getValue(); if (langAtt != null && targetLanguage.equalsIgnoreCase(attName)) { result = true; } break; } parentNode = parentNode.getParent(); } return result; }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
private boolean isLockedSegment(Node p_node) { boolean result = false; if (p_node == null) { return false; }// w w w . j a va 2 s.co m Element parentNode = p_node.getParent(); if (parentNode != null) { // In Tuv. String nodeName = parentNode.getName(); if ("ut".equalsIgnoreCase(nodeName)) { Attribute attt = parentNode.attribute(TTXConstants.UT_ATT_DISPLAYTEXT); if (attt != null) { String attValue = attt.getValue(); result = TTXConstants.GS_LOCKED_SEGMENT.equalsIgnoreCase(attValue); } } } return result; }
From source file:com.noterik.bart.fs.fscommand.CopyCommand.java
License:Open Source License
/** * /*w w w. j a va 2 s. co m*/ * @param uri * @return */ private Document getPropertiesOfUri(String uri, int depth) { // refactor uri String cp = URIParser.getCurrentUriPart(uri); if (cp.equals(FSXMLHelper.XML_PROPERTIES)) { uri = URIParser.getParentUri(uri); } // get complete Document pDoc = null; if (depth == -1) { pDoc = rHandler.getNodeProperties(uri, true); } else { pDoc = rHandler.getNodeProperties(uri, depth, true); } // loop through xml and check referid's List<Node> rNodes = pDoc.selectNodes("//@referid"); logger.debug("rNodes: " + rNodes); for (Iterator<Node> iter = rNodes.iterator(); iter.hasNext();) { // get referid attribute and parent node Node node = iter.next(); String referid = node.getText(); Element parent = node.getParent(); logger.debug("parent: " + parent.asXML() + ", refer: " + referid); // get properties of referid Document rDoc = rHandler.getNodeProperties(referid, 0, false); logger.debug("rDoc: " + rDoc.asXML()); Node properties = rDoc.selectSingleNode("//properties"); List<Node> pNodes = properties.selectNodes("child::*"); logger.debug("pNodes: " + pNodes); for (Iterator<Node> iter2 = pNodes.iterator(); iter2.hasNext();) { // select the same property elements that are in parent element and refer properties Node prop = iter2.next(); List<Node> parentPNodes = parent.selectNodes("properties/child::*"); for (Node parentPropNode : parentPNodes) { if (parentPropNode.getName().equals(prop.getName()) && parentPropNode.getText().equals(prop.getText())) { logger.debug("removing: " + parentPropNode.asXML()); parentPropNode.detach(); } } } } return pDoc; }
From source file:com.ten45.service.aggregator.ConfigurationServiceImpl.java
/** * Expand the original configuration document with the referred node. * It reads the referred document, finds the referred element in the same * path as the original document, and moves all the children of the * referred element into the original element. * /*from w w w.j a va 2s . c om*/ * @param doc * @param node * @return * @throws DocumentException */ private Document expandReference(Document doc, Node node) throws DocumentException { // Find the 'anchor' element that contains the reference declaration. Element anchor = node.getParent(); XPath anchorXPath = DocumentHelper.createXPath(anchor.getPath()); // Remove the reference declaration node from the document. node.detach(); // Read the new configuration. String resourceName = rootPath + node.getText() + ".xml"; log.debug("Reading resource " + resourceName); InputStream in = this.getClass().getResourceAsStream(resourceName); SAXReader reader = new SAXReader(); try { Document refDoc = reader.read(in); Element refElement = (Element) anchorXPath.selectSingleNode(refDoc); if (refElement != null) { log.debug("Expanding " + anchorXPath.getText() + " with " + refElement.asXML()); // Move all elements from the referenced document into the anchor. List children = refElement.elements(); if (children != null && children.size() > 0) { for (int i = 0; i < children.size(); i++) { Element child = (Element) children.get(i); XPath refXPath = DocumentHelper.createXPath(child.getPath()); if (refXPath.selectSingleNode(doc) == null) { log.debug("Adding element " + refXPath.getText()); child.detach(); anchor.add(child); } else { log.debug("Ignore pre-existing element " + refXPath.getText()); } } } } } catch (DocumentException de) { throw de; } return doc; }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void removeJob(String pipelineName, String stageName, String jobName) { Node job = getNode(String.format("//pipeline[@name='%s']//stage[@name='%s']//job[@name='%s']", pipelineName, stageName, jobName));/* w w w . ja v a 2 s . c om*/ job.getParent().remove(job); }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void removeEnvironments() { Node environmentsNode = root().selectSingleNode("//environments"); if (environmentsNode != null) { environmentsNode.getParent().remove(environmentsNode); }/*ww w . j ava 2 s. com*/ }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void removeTemplates() { Node templatesNode = root().selectSingleNode("//templates"); if (templatesNode != null) { templatesNode.getParent().remove(templatesNode); }//w w w . j a va 2s . c o m }
From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java
License:Apache License
public void updateValueOfKeyToForRepoWithId(String key, String value, String repoId) { Element repo = findRepo(repoId); Node userKey = repo.selectSingleNode(String.format("configuration/property/key[text()='%s']", key)); userKey.getParent().selectSingleNode("value").setText(value); }
From source file:com.xebia.mojo.dashboard.DashboardMojo.java
License:Apache License
private void removePlaceHolder(Branch dashboardTableDestination) { Node node = dashboardTableDestination.selectSingleNode("div[@class='section']/h2[text()='Dashboard']"); if (node != null) { Element div = node.getParent(); dashboardTableDestination.remove(div); }/* w w w.jav a 2s .co m*/ }