List of usage examples for org.dom4j Node detach
Node detach();
Removes this node from its parent if there is one.
From source file:edu.scripps.fl.pubchem.xml.ResultTidXML.java
License:Apache License
public void addTidPlots(Document document, Integer numberPlots) { Element root = (Element) document.selectSingleNode(rootString); Node dr = root.selectSingleNode("PC-AssayDescription_dr"); if (dr != null) dr.detach(); Element tidPlotDR = root.addElement("PC-AssayDescription_dr"); for (int ii = 1; ii <= numberPlots; ii++) { Element assayDRAttr = tidPlotDR.addElement("PC-AssayDRAttr"); assayDRAttr.addElement("PC-AssayDRAttr_id").addText("" + ii); assayDRAttr.addElement("PC-AssayDRAttr_descr").addText("Response vs Concentration [" + ii + "]"); assayDRAttr.addElement("PC-AssayDRAttr_dn").addText("Concentration"); assayDRAttr.addElement("PC-AssayDRAttr_rn").addText("Response"); }// w w w. j a v a 2 s. c o m }
From source file:edu.scripps.fl.pubchem.xml.ResultTidXML.java
License:Apache License
public void buildTidDocument(Document document, List<ResultTid> tidValues) { Integer tidInt = decideTids(tidValues); if (tidInt > 0) { Integer numberPlots = getNumberPlots(tidValues); if (numberPlots > 1) addTidPlots(document, numberPlots); Element root = (Element) document.selectSingleNode(rootString + "/" + results); List<Node> nodes = root.selectNodes("PC-ResultType"); for (Node n : nodes) n.detach(); for (int tt = 0; tt < tidValues.size(); tt++) { ResultTid tidValue = tidValues.get(tt); Element resultType = root.addElement("PC-ResultType"); resultType.addElement("PC-ResultType_tid").addText("" + (tt + 1)); resultType.addElement("PC-ResultType_name").addText(tidValue.getTidName()); String description = tidValue.getTidDescription(); if (null != description) resultType.addElement("PC-ResultType_description").addElement("PC-ResultType_description_E") .addText(description); String tidType = tidValue.getTidType(); if (null != tidType) resultType.addElement("PC-ResultType_type").addAttribute("value", tidType) .addText("" + tidValue.getTidTypeValue()); String tidUnit = tidValue.getTidUnit(); if (null != tidUnit & "" != tidUnit & tidUnit != "null") resultType.addElement("PC-ResultType_unit").addAttribute("value", tidUnit) .addText("" + tidValue.getTidUnitValue()); Boolean isAC = tidValue.getIsActiveConcentration(); if (null != isAC) resultType.addElement("PC-ResultType_ac").addAttribute("value", isAC.toString()); Double concentration = tidValue.getTidConcentration(); if (null != concentration) { Element tc = resultType.addElement("PC-ResultType_tc"); Element concentrationattr = tc.addElement("PC-ConcentrationAttr"); concentrationattr.addElement("PC-ConcentrationAttr_concentration").addText("" + concentration); concentrationattr.addElement("PC-ConcentrationAttr_unit").addAttribute("value", "um") .addText("5"); Integer plot = tidValue.getTidPlot(); if (null != plot) concentrationattr.addElement("PC-ConcentrationAttr_dr-id").addText("" + plot); }/*from w w w . j ava2s. c o m*/ Integer panelNum = tidValue.getTidPanelNum(); if (null != panelNum) { Element panel = resultType.addElement("PC-ResultType_panel-info"); Element passay = panel.addElement("PC-AssayPanelTestResult"); passay.addElement("PC-AssayPanelTestResult_mid").addText("" + panelNum); passay.addElement("PC-AssayPanelTestResult_readout-annot") .addAttribute("value", tidValue.getTidPanelReadout()) .addText("" + tidValue.getTidPanelReadoutValue()); } } } }
From source file:edu.scripps.fl.pubchem.xml.TargetXML.java
License:Apache License
public List<Target> buildTargetDocument(Document document, List<Target> targets) throws Exception { List<Target> targetsOfAssay = new ArrayList<Target>(); List<Target> otherTargets = new ArrayList<Target>(); for (Target xx : targets) { otherTargets.add(xx);/* w w w.ja va2s. c o m*/ if (xx.isAssayTarget()) { targetsOfAssay.add(xx); otherTargets.remove(xx); } } if (targetsOfAssay != null) { Element root = (Element) document.selectSingleNode(rootString); Node targetNode = root.selectSingleNode("//" + target); if (targetNode != null) { targetNode.detach(); } Element targetElement = root.addElement(target); PubChemXMLDoc xmlDoc = new PubChemXMLDoc(); for (Target xx : targetsOfAssay) { String type = xx.getType(); String name = xx.getName(); if (type.equalsIgnoreCase("nucleotide")) { if (name.contains("dna") | name.contains("DNA") | name.contains("gene")) xx.setXMLTargetValue(2); else if (name.contains("RNA") | name.contains("rna")) xx.setXMLTargetValue(3); } else if (type.equalsIgnoreCase("protein")) { xx.setXMLTargetValue(1); } Document taxonDoc = xmlDoc.getDocument(xx.getTaxonomy(), "taxonomy"); Element info = targetElement.addElement("PC-AssayTargetInfo"); info.addElement("PC-AssayTargetInfo_name").addText(name); info.addElement("PC-AssayTargetInfo_mol-id").addText(String.valueOf(xx.getId())); info.addElement("PC-AssayTargetInfo_molecule-type").addAttribute("value", xx.getXMLTargetType()) .addText(xx.getXMLTargetValue().toString()); Element organism = info.addElement("PC-AssayTargetInfo_organism"); Element element = organism.addElement("BioSource"); element = element.addElement("BioSource_org"); element = element.addElement("Org-ref"); element.addElement("Org-ref_taxname") .addText(xmlDoc.getTargetInformation(taxonDoc, "ScientificName")); element.addElement("Org-ref_common").addText(xmlDoc.getTargetInformation(taxonDoc, "CommonName")); element = element.addElement("Org-ref_db"); element = element.addElement("Dbtag"); element.addElement("Dbtag_db").addText("taxon"); element = element.addElement("Dbtag_tag"); element = element.addElement("Object-id"); element.addElement("Object-id_id").addText(xx.getTaxonomy().toString()); } } return otherTargets; }
From source file:edu.scripps.fl.pubchem.xml.XrefXML.java
License:Apache License
public void buildXrefDocument(Document document, PubChemAssay assay) throws Exception { Set<Xref> xrefs = assay.getXrefs(); PubChemAssayFactory factory = new PubChemAssayFactory(); List<Target> targets = factory.removePanelsFromTargets(assay); List<Gene> genes = factory.removePanelsFromGenes(assay); List<Xref> aids = assay.getAids(); List<Xref> pmids = assay.getPmids(); if (targets != null && targets.size() > 0) targets = new TargetXML().buildTargetDocument(document, targets); if (xrefs.size() > 0 || genes.size() > 0 || aids.size() > 0 || pmids.size() > 0 || targets.size() > 0) { Element rootElement = (Element) document.selectSingleNode(rootString); Element adXref = (Element) rootElement.selectSingleNode((String) xref); if (adXref != null) { List<Node> nodes = adXref.selectNodes("PC-AnnotatedXRef"); for (Node nn : nodes) nn.detach(); } else/*from ww w. ja va2s.c o m*/ adXref = rootElement.addElement((String) xref); for (Xref xx : aids) addXref(adXref, "PC-XRefData_aid", xx.getXrefValue().toString(), xx.getXrefComment()); for (Target tt : targets) { String elementName = "PC-XRefData_" + tt.getType().toLowerCase() + "-gi"; addXref(adXref, elementName, tt.getId().toString(), tt.getName()); } for (Gene gg : genes) { if (!gg.getIsTarget()) addXref(adXref, "PC-XRefData_gene", gg.getId().toString(), gg.getName()); else new TargetXML().addGeneTargetToDocument(document, gg); } for (Xref xx : xrefs) { Element annotatedXref = adXref.addElement("PC-AnnotatedXRef"); Element annotatedXrefXref = annotatedXref.addElement("PC-AnnotatedXRef_xref"); Element xrefData = annotatedXrefXref.addElement("PC-XRefData"); Object xrefValue = xx.getXrefValue(); String xrefType = xx.getXrefType(); String strValue = xrefValue.toString(); // these are strings if (xrefType.equalsIgnoreCase("source database homepage")) xrefData.addElement("PC-XRefData_dburl").addText(strValue); else if (xrefType.equalsIgnoreCase("mesh")) xrefData.addElement("PC-XRefData_mesh").addText(strValue); else if (xrefType.equalsIgnoreCase("substance homepage")) xrefData.addElement("PC-XRefData_sburl").addText(strValue); else if (xrefType.equalsIgnoreCase("assay homepage")) xrefData.addElement("PC-XRefData_asurl").addText(strValue); else if (xrefType.equalsIgnoreCase("substance registry #")) xrefData.addElement("PC-XRefData_rn").addText(strValue); // all these others are really numbers else { Double idD = Double.parseDouble(strValue); Integer id = idD.intValue(); if (xrefType.equalsIgnoreCase("sid")) xrefData.addElement("PC-XRefData_sid").addText(id.toString()); else if (xrefType.equalsIgnoreCase("omim")) xrefData.addElement("PC-XRefData_mim").addText(id.toString()); else if (xrefType.equalsIgnoreCase("taxonomy")) xrefData.addElement("PC-XRefData_taxonomy").addText(id.toString()); else if (xrefType.equalsIgnoreCase("cid")) xrefData.addElement("PC-XRefData_cid").addText(id.toString()); else if (xrefType.equalsIgnoreCase("genbank")) xrefData.addElement("PC-XRefData_gi").addText(id.toString()); else if (xrefType.equalsIgnoreCase("mmdb")) xrefData.addElement("PC-XRefData_mmdb").addText(id.toString()); else if (xrefType.equalsIgnoreCase("biosystems id")) xrefData.addElement("PC-XRefData_biosystem").addText(id.toString()); } String comment = xx.getXrefComment(); if (null != comment) annotatedXref.addElement("PC-AnnotatedXRef_comment").addText(comment); } for (Xref xx : pmids) { Element annotatedXref = adXref.addElement("PC-AnnotatedXRef"); Element annotatedXrefXref = annotatedXref.addElement("PC-AnnotatedXRef_xref"); Element xrefData = annotatedXrefXref.addElement("PC-XRefData"); xrefData.addElement("PC-XRefData_pmid").addText(xx.getXrefValue().toString()); if (null != xx.getXrefComment()) annotatedXref.addElement("PC-AnnotatedXRef_comment").addText(xx.getXrefComment()); if (xx.getIsPrimaryCitation() != null) { if (xx.getIsPrimaryCitation()) new PubChemXMLUtils().attributeAndTextAdd("PC-AnnotatedXRef_type", "pcit", "1", annotatedXref); } } } }
From source file:edu.ucsd.library.xdre.imports.RDFDAMS4ImportHandler.java
/** * Update record for resource linking//from w w w .j a va2s . c o m * @param url * @param node */ public void toResourceLinking(String url, Node record) { Element pNode = record.getParent(); if (pNode.getName().endsWith("List") && !record.getName().toLowerCase().endsWith(pNode.getName().toLowerCase())) { //List elements record.setName("rdf:Description"); ((Element) record).clearContent(); ((Element) record).selectSingleNode("@rdf:about").setText(toDamsUrl(url)); } else { pNode.addAttribute("rdf:resource", toDamsUrl(url)); record.detach(); } }
From source file:eu.planets_project.pp.plato.util.XMLCompare.java
License:Open Source License
private void excludeNodes(Document doc) { Element root = doc.getRootElement(); for (String xpathString : excludedNodes) { XPath xpath = doc.createXPath(xpathString); List<Node> l = xpath.selectNodes(root); for (Node n : l) { n.detach(); }// www . ja va 2 s. c o m } }
From source file:hk.hku.cecid.piazza.commons.util.PropertyTree.java
License:Open Source License
/** * Sets a property value with the specified key. * /* ww w . j a v a2s.c o m*/ * @param xpath the property xpath. * @param value the property value. * @return true if the operation is successful. false otherwise. * @see hk.hku.cecid.piazza.commons.util.PropertySheet#setProperty(java.lang.String, * java.lang.String) */ public boolean setProperty(String xpath, String value) { Node node = getPropertyNode(xpath); boolean result; if (node == null) { result = addProperty(xpath, value); } else { try { if (value == null) { node.detach(); } else { node.setText(value); } result = true; } catch (Exception e) { result = false; } } return result; }
From source file:main.FrevoMain.java
License:Open Source License
/** * Removes the component from the installed components. This function also * removes all files within the component's directory. Forces FREVO to * reload all components afterwards.//from www.ja v a 2 s . c o m * * @param cdata * The component to be removed */ public static void deleteComponent(ComponentXMLData cdata) { // remove base XML File baseXML = cdata.getSourceXMLFile(); baseXML.delete(); // erase all files within component directory // get class root directory String classDir = cdata.getClassDir(); // extract directory name // construct copy int i = 0; while (i < classDir.length()) { char c = classDir.charAt(i); if ((c == '/') || (c == '\\')) { i++; } else { break; } } int end = i + 1; while (end < classDir.length()) { char c = classDir.charAt(end); if ((c == '/') || (c == '\\')) { break; } else { end++; } } classDir = classDir.substring(i, end); String comprootdirname = classDir.split("/")[0]; // get component root directory String comprootdir = FrevoMain.getComponentDirectory(cdata.getComponentType()) + comprootdirname; File rootdir = new File(comprootdir); eraseDirectory(rootdir); // Remove entry from classpath File classpath = new File(FrevoMain.getInstallDirectory() + File.separator + ".classpath"); if (classpath.exists()) { Document doc = SafeSAX.read(classpath, true); Element root = doc.getRootElement(); String output; // the string to match the "output" field in // classpath xml // correct pathname for multiproblems if (cdata.getComponentType() == ComponentType.FREVO_MULTIPROBLEM) output = "Components/" + "Problems/" + comprootdirname; else if (cdata.getComponentType() == ComponentType.FREVO_BULKREPRESENTATION) output = "Components/" + "Representations/" + comprootdirname; else output = "Components/" + FrevoMain.getComponentTypeAsString(cdata.getComponentType()) + "s/" + comprootdirname; // System.out.println("removing "+output); Node node = root.selectSingleNode("classpathentry[@output='" + output + "']"); if (node != null) node.detach(); // save XML try { OutputFormat format = OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); FileWriter out = new FileWriter(classpath); BufferedWriter bw = new BufferedWriter(out); XMLWriter wr = new XMLWriter(bw, format); wr.write(doc); wr.close(); } catch (IOException e) { System.err.println("ERROR: Could not write Eclipse classpath file!"); e.printStackTrace(); } } // force reloading components FrevoMain.reLoadComponents(true); }
From source file:nl.tue.gale.ae.processor.xmlmodule.CreoleTextHandler.java
License:Open Source License
@SuppressWarnings("unchecked") private List<Node> parse(String text, boolean flat) { Element result = CreoleParser.instance().parse(text); List<Node> content; if (flat) {/*from w w w .j ava 2 s.c o m*/ content = new LinkedList<Node>(); for (Element element : (List<Element>) result.elements()) content.addAll(element.content()); content = ImmutableList.copyOf(content); } else content = (List<Node>) ImmutableList.copyOf(result.content()); for (Node node : content) node.detach(); return content; }
From source file:nl.tue.gale.ae.processor.xmlmodule.ExampleModule.java
License:Open Source License
@Override public Element traverse(Element element, Resource resource) throws ProcessorException { Element pre = createHTMLElement("pre"); @SuppressWarnings("unchecked") List<Node> content = (List<Node>) element.content(); content = ImmutableList.copyOf(content); for (Node node : content) { node.detach(); pre.add(node);//w w w .ja va 2 s .c om } replaceNode(element, pre); return pre; }