List of usage examples for org.dom4j Node detach
Node detach();
Removes this node from its parent if there is one.
From source file:nl.tue.gale.ae.processor.xmlmodule.RepositoryModule.java
License:Open Source License
private void moveContent(Element source, Element target) { @SuppressWarnings("unchecked") List<Node> content = (List<Node>) source.content(); for (Node node : ImmutableList.copyOf(content)) { node.detach(); target.add(node);/*from w w w. j av a2 s. c o m*/ } }
From source file:nl.tue.gale.ae.processor.xmlmodule.TextModule.java
License:Open Source License
@Override public Element traverse(Element element, Resource resource) throws ProcessorException { GaleContext gale = GaleContext.of(resource); if (!includeBlock(element, resource)) return (Element) replaceNode(element, null); // find possible class String classexpr = null;/* www.j ava2s . c o m*/ EntityValue ev = gale.um() .get(URIs.builder().uri(gale.conceptUri()).userInfo(gale.userId()).fragment("tags.class").build()); if (ev != null) classexpr = ev.getValueString(); if (classexpr != null && !"".equals(classexpr)) { CacheSession<EntityValue> session = gale.um().openSession(); try { String cl = (String) gale.cm().evaluate(gale.cr(), classexpr, Argument.of("gale", "nl.tue.gale.ae.GaleContext", gale, "session", "nl.tue.gale.common.cache.CacheSession", session, "element", "org.dom4j.Element", element)); if (cl != null) element.addAttribute("class", cl); } catch (Exception e) { e.printStackTrace(); return (Element) replaceNode(element, GaleUtil.createErrorElement("[" + e.getMessage() + "]")); } } // create result element Element result; if (element.attributeValue("class") != null) result = createHTMLElement("div").addAttribute("class", element.attributeValue("class")); else if (element.attributeValue("id") != null) result = createHTMLElement("div").addAttribute("id", element.attributeValue("id")); else result = createHTMLElement("span"); // handle textual content TextHandler handler = handlerMap.get(element.attributeValue("type")); if (handler != null) { processor.traverseChildren(element, resource); handler.handleTextElement(element); } // copy the content to the new node @SuppressWarnings("unchecked") List<Node> content = ImmutableList.copyOf((List<Node>) element.content()); for (Node node : content) { node.detach(); result.add(node); } replaceNode(element, result); return result; }
From source file:nz.govt.natlib.ndha.common.dublincore.DublinCore.java
License:Open Source License
private void removeNodeByXPath(String xPath) { Node node = m_document.selectSingleNode(xPath); if (node != null) { node.detach(); }/*from w w w . j a v a2 s .c om*/ }
From source file:org.apache.taglibs.xtags.servlet.XPathServlet.java
License:Apache License
protected void appendResults(Element element, List results) { for (int i = 0, size = results.size(); i < size; i++) { Object result = results.get(i); if (result instanceof String) { element.addText((String) result); } else if (result instanceof Node) { Node node = (Node) result; node.detach(); element.add(node);//from ww w . j av a 2 s. c o m } else if (result != null) { element.addText(result.toString()); } } }
From source file:org.apache.taglibs.xtags.xpath.AddTag.java
License:Apache License
public int doEndTag() throws JspException { Object element = TagHelper.getInputNodes(pageContext, this, false); if (element == null) { throw new JspException("No current node to add content to"); }//from w ww.j av a 2 s .c o m if (!(element instanceof Element)) { throw new JspException("Current node is not an Element"); } if (bodyContent != null) { try { StringReader sreader = new StringReader("<dummy>" + bodyContent.getString() + "</dummy>"); SAXReader reader = new SAXReader(); Document doc = reader.read(sreader); Element root = doc.getRootElement(); List nodes = root.content(); while (!nodes.isEmpty()) { Node node = (Node) nodes.remove(0); node.detach(); ((Element) element).add(node); } } catch (DocumentException e) { handleException(e); } } return EVAL_PAGE; }
From source file:org.apache.taglibs.xtags.xpath.RemoveTag.java
License:Apache License
public int doStartTag() throws JspException { if (xpath != null) { List list = xpath.selectNodes(getInputNodes()); if (list != null) { for (Iterator iter = list.iterator(); iter.hasNext();) { Object value = iter.next(); if (value instanceof Node) { Node node = (Node) value; node.detach(); }//w w w .j ava 2s . c o m } } } return SKIP_BODY; }
From source file:org.apache.taglibs.xtags.xpath.ReplaceTag.java
License:Apache License
public int doEndTag() throws JspException { Object context = TagHelper.getInputNodes(pageContext, this, false); if (context == null) { logInfo("No current node to replace"); return EVAL_PAGE; }/* w ww .ja va2 s . c om*/ try { String xmlFragment = null; if (bodyContent != null) { xmlFragment = bodyContent.getString(); } if (context instanceof List) { List els = (List) context; if (els.size() > 1) { throw new JspException("Current context contains more than one node"); } if (els.size() == 1) { context = els.get(0); } } if (context instanceof Document) { if (xmlFragment == null) { throw new JspException("Cannot replace document with empty body"); } Document sourceDoc = (Document) context; Document newDoc = DocumentHelper.parseText(xmlFragment); // clear source doc contents sourceDoc.clearContent(); for (int i = 0, size = newDoc.nodeCount(); i < size; i++) { Node node = newDoc.node(i); // detach from new doc node.detach(); // add to source sourceDoc.add(node); } } else { if (!(context instanceof Element)) { throw new JspException("Current node is not an Element: " + context.getClass().getName()); } Element element = (Element) context; SAXReader reader = new SAXReader(); if (element.isRootElement()) { if (xmlFragment == null) { throw new JspException("Cannot replace root element with empty body"); } Document newDoc = DocumentHelper.parseText(xmlFragment); Document sourceDoc = element.getDocument(); Element newRoot = newDoc.getRootElement(); newRoot.detach(); sourceDoc.setRootElement(newRoot); } else { Element parent = element.getParent(); List parentContent = parent.content(); int index = parentContent.indexOf(element); parentContent.remove(index); if (xmlFragment != null) { Document newDoc = DocumentHelper.parseText("<dummy>" + xmlFragment + "</dummy>"); parentContent.addAll(index, newDoc.getRootElement().content()); } } } } catch (DocumentException e) { handleException(e); } return EVAL_PAGE; }
From source file:org.arquillian.graphene.visual.testing.impl.JCRMaskHandler.java
private void deleteMaskFromConfiguration(String maskID, Document doc) { Namespace ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE); String xPath = "/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"visual-suite\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"global-configuration\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"mask\" and @id=\"" + maskID + "\"]"; Node maskElement = doc.selectSingleNode(xPath); maskElement.detach(); }
From source file:org.arquillian.graphene.visual.testing.impl.JCRMaskHandler.java
private void deleteMaskFromTest(String maskID, Document doc) { Namespace ns = Namespace.get(RushEye.NAMESPACE_VISUAL_SUITE); String xPath = "/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"visual-suite\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"test\"]/*[namespace-uri()=\"" + ns.getURI() + "\" and name()=\"mask\" and @id=\"" + maskID + "\"]"; Node maskElement = doc.selectSingleNode(xPath); maskElement.detach(); }
From source file:org.ballproject.knime.base.config.CTDNodeConfigurationWriter.java
License:Open Source License
@SuppressWarnings("unchecked") private void cleanItemLists() { List<Node> itemlists = doc.selectNodes("//ITEMLIST"); for (Node itemlist : itemlists) { List<Node> listitems = itemlist.selectNodes("LISTITEM"); for (Node item : listitems) { item.detach(); }//from w ww . ja v a2 s . c om } }