List of usage examples for org.jdom2 Element detach
@Override
public Element detach()
From source file:ataraxis.passwordmanager.XMLHandler.java
License:Open Source License
/** * Delete the Element with the ID ElementID and all sub-Elements * * @param ElementID ID of Element //from ww w . ja v a 2 s . co m * @throws JDOMException if Element does not exist */ private void deleteElement(String ElementID) throws JDOMException { XPathExpression<Element> xpath = XPathFactory.instance().compile("//*[@id='" + ElementID + "']", Filters.element()); Element el = xpath.evaluateFirst(s_doc); if (el != null) { el.detach(); } else { throw new JDOMException("Element not Found"); } }
From source file:ca.nrc.cadc.uws.JobReader.java
License:Open Source License
private JobInfo parseJobInfo(Document doc) { JobInfo rtn = null;/*from w w w. ja va 2 s . c o m*/ Element root = doc.getRootElement(); Element e = root.getChild(JobAttribute.JOB_INFO.getAttributeName(), UWS.NS); if (e != null) { log.debug("found jobInfo element"); String content = e.getText(); List children = e.getChildren(); if (content != null) content = content.trim(); if (content.length() > 0) // it was text content { rtn = new JobInfo(content, null, null); } else if (children != null) { if (children.size() == 1) { try { Element ce = (Element) children.get(0); Document jiDoc = new Document((Element) ce.detach()); XMLOutputter outputter = new XMLOutputter(); StringWriter sw = new StringWriter(); outputter.output(jiDoc, sw); sw.close(); rtn = new JobInfo(sw.toString(), null, null); } catch (IOException ex) { throw new RuntimeException("BUG while writing element to string", ex); } } } } log.debug("parseJobInfo: " + rtn); return rtn; }
From source file:ca.nrc.cadc.vos.server.RssView.java
License:Open Source License
/** * Write to root Element to a writer./*from ww w . ja v a 2 s . c o m*/ * * @param root Root Element to write. * @param writer Writer to write to. * @throws IOException if the writer fails to write. */ protected void write(Element root, Writer writer) throws IOException { XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); Document document = new Document(); root.detach(); document.setRootElement(root); outputter.output(document, writer); }
From source file:com.archimatetool.editor.model.compatibility.Archimate2To3Converter.java
License:Open Source License
/** * Remove "Derived" folder and move contents to "Relations" folder *///from w ww.j a v a 2s . c om private void moveDerivedRelationsFolderContents() { Element eDerivedFolder = getModelFolder("derived"); if (eDerivedFolder != null) { eDerivedFolder.detach(); Element eRelationsFolder = getModelFolder("relations"); if (eRelationsFolder != null) { List<Element> copy = new ArrayList<>(eDerivedFolder.getChildren()); for (Element eChild : copy) { eChild.detach(); eRelationsFolder.addContent(eChild); } } } }
From source file:com.archimatetool.editor.model.compatibility.Archimate2To3Converter.java
License:Open Source License
/** * Move concepts to different folders// w w w . j a v a2s. c o m */ private void moveConceptType(Element element) { Attribute attType = element.getAttribute("type", JDOMUtils.XSI_Namespace); if (attType != null) { String value = attType.getValue(); // Location if ("archimate:Location".equals(value)) { Element eFolder = getModelFolder("other"); if (eFolder != null) { element.detach(); eFolder.addContent(element); } } // Value / Meaning if ("archimate:Value".equals(value) || "archimate:Meaning".equals(value)) { Element eFolder = getModelFolder("motivation"); if (eFolder != null) { element.detach(); eFolder.addContent(element); } } } }
From source file:com.izforge.izpack.util.xmlmerge.merge.DefaultXmlMerge.java
License:Open Source License
/** * Performs the actual merge./*from w w w . j a v a 2s .c om*/ * * @param docs The documents to merge. The first doc is assumed to be the original one to apply patches against. * @return The merged result document * @throws AbstractXmlMergeException If an error occurred during the merge */ private Document doMerge(Document[] docs) throws AbstractXmlMergeException { Document originalDoc = docs[0]; Element origRootElement = originalDoc.getRootElement(); for (int i = 1; i < docs.length; i++) { Element comparedRootElement = docs[i].getRootElement(); Document output = new Document(); if (originalDoc.getDocType() != null) { output.setDocType((DocType) originalDoc.getDocType().clone()); } output.setRootElement(new Element("root")); Element outputRootElement = output.getRootElement(); m_rootMergeAction.perform(origRootElement, comparedRootElement, outputRootElement); Element root = (Element) outputRootElement.getChildren().get(0); root.detach(); sortRootChildrenRecursive(root); originalDoc.setRootElement(root); } return originalDoc; }
From source file:com.ohnosequences.xml.model.uniprot.ProteinXML.java
License:Open Source License
public void clasifyGoTermsByAspect() throws JDOMException { initComponentTag();//from ww w.j av a2s . co m initFunctionTag(); initProcessTag(); if (doc == null) { doc = root.getDocument(); } XPathExpression<Element> xpProcess = XPathFactory.instance() .compile( "//protein[id/text()='" + getId() + "']//" + GoTermXML.TAG_NAME + "[" + GoTermXML.ASPECT_TAG_NAME + "/text()='" + GoTermXML.ASPECT_PROCESS + "']", Filters.element()); List<Element> processGoTerms = xpProcess.evaluate(doc); XPathExpression<Element> xpFunction = XPathFactory.instance() .compile( "//protein[id/text()='" + getId() + "']//" + GoTermXML.TAG_NAME + "[" + GoTermXML.ASPECT_TAG_NAME + "/text()='" + GoTermXML.ASPECT_FUNCTION + "']", Filters.element()); List<Element> functionGoTerms = xpFunction.evaluate(doc); XPathExpression<Element> xpComponent = XPathFactory.instance() .compile( "//protein[id/text()='" + getId() + "']//" + GoTermXML.TAG_NAME + "[" + GoTermXML.ASPECT_TAG_NAME + "/text()='" + GoTermXML.ASPECT_COMPONENT + "']", Filters.element()); List<Element> componentGoTerms = xpComponent.evaluate(doc); for (Element processGo : processGoTerms) { processGo.detach(); this.addGoTerm(new GoTermXML(processGo), true); } for (Element componentGo : componentGoTerms) { componentGo.detach(); this.addGoTerm(new GoTermXML(componentGo), true); } for (Element functionGo : functionGoTerms) { functionGo.detach(); this.addGoTerm(new GoTermXML(functionGo), true); } }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
/** * Parse entry from reader.//from w ww .j a v a 2 s .c o m */ public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException, FeedException { // Parse entry into JDOM tree final SAXBuilder builder = new SAXBuilder(); final Document entryDoc = builder.build(rd); final Element fetchedEntryElement = entryDoc.getRootElement(); fetchedEntryElement.detach(); // Put entry into a JDOM document with 'feed' root so that Rome can // handle it final Feed feed = new Feed(); feed.setFeedType("atom_1.0"); final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(feed); feedDoc.getRootElement().addContent(fetchedEntryElement); if (baseURI != null) { feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE); } final WireFeedInput input = new WireFeedInput(false, locale); final Feed parsedFeed = (Feed) input.build(feedDoc); return parsedFeed.getEntries().get(0); }
From source file:com.sun.syndication.io.impl.Atom10Parser.java
License:Open Source License
/** * Parse entry from reader./* w w w . j a v a2 s .co m*/ */ public static Entry parseEntry(Reader rd, String baseURI) throws JDOMException, IOException, IllegalArgumentException, FeedException { // Parse entry into JDOM tree SAXBuilder builder = new SAXBuilder(); Document entryDoc = builder.build(rd); Element fetchedEntryElement = entryDoc.getRootElement(); fetchedEntryElement.detach(); // Put entry into a JDOM document with 'feed' root so that Rome can handle it Feed feed = new Feed(); feed.setFeedType("atom_1.0"); WireFeedOutput wireFeedOutput = new WireFeedOutput(); Document feedDoc = wireFeedOutput.outputJDom(feed); feedDoc.getRootElement().addContent(fetchedEntryElement); if (baseURI != null) { feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE); } WireFeedInput input = new WireFeedInput(); Feed parsedFeed = (Feed) input.build(feedDoc); return (Entry) parsedFeed.getEntries().get(0); }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.FunctionNormalizer.java
License:Apache License
private void normalizeFunctionApplication(final Element element, final Collection<String> functionOperators) { assert element != null && functionOperators != null; final List<Element> children = element.getChildren(); for (int i = 0; i < children.size(); i++) { if (isFunction(i, children, functionOperators)) { final int parameterPosition = i + 2; Element parameter = children.get(parameterPosition); // mrow in which the parameter will be stored final Element newParameter = new Element(ROW); if (parameter.getName().equals(ROW)) { if (hasInsideBrackets(parameter)) { children.get(i + 1).detach(); // just detach operator } else { // add parentheses parameter.addContent(1, new Element(OPERATOR).setText("(")); parameter.addContent(new Element(OPERATOR).setText(")")); LOGGER.fine("Parentheses around function argument added"); children.get(i + 1).detach(); // detach funct app operator }// w w w .ja v a2 s . co m LOGGER.fine("Function application operator removed"); continue; // no need to set newParameter } else if (isOperator(parameter, "(")) { int bracketsDepth = 1; newParameter.addContent(parameter.detach()); while ((parameterPosition < children.size()) && (bracketsDepth > 0)) { parameter = children.get(parameterPosition); if (isOperator(parameter, "(")) { bracketsDepth++; } else if (isOperator(parameter, ")")) { bracketsDepth--; } newParameter.addContent(parameter.detach()); } for (; bracketsDepth > 0; bracketsDepth--) { // add missing right brackets newParameter.addContent(new Element(OPERATOR).setText(")")); LOGGER.fine("Added missing )"); } } else { // if the paramether is neither mrow or ( newParameter.addContent(new Element(OPERATOR).setText("(")); // add left bracket newParameter.addContent(children.get(parameterPosition).detach()); newParameter.addContent(new Element(OPERATOR).setText(")")); // add right bracket LOGGER.fine("Function argument wrapped with parentheses and mrow"); } children.set(i + 1, newParameter); // replace function app operator with newParameter LOGGER.fine("Function application operator removed"); } else { // if there isnt start of function application apply normalization on children normalizeFunctionApplication(children.get(i), functionOperators); } } }