List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:nnga.NNGA.java
License:Open Source License
/** * Initializes population(s) from XML document * @param problemData information about problem * @param representationData information about representation * @param doc XML document which contains data about population * @return <i>true</i> if population has been loaded successfully, <i>false</i> - otherwise *///w ww.j a va2 s.com private boolean loadFromDoc(ProblemXMLData problemData, ComponentXMLData representationData, Document doc) { // obtain problem requirements int inputnumber = problemData.getRequiredNumberOfInputs(); int outputnumber = problemData.getRequiredNumberOfOutputs(); // record the best fitness over the evolution Node dpopulations = doc.selectSingleNode("/frevo/populations"); long randomseed = Long.parseLong(dpopulations.valueOf("./@randomseed")); getRandom().setSeed(randomseed); // load initial population(s) ArrayList<ArrayList<AbstractRepresentation>> loadedPops = loadFromXML(doc); for (int i = 0; i < parameters.getPopulationNumber(); i++) { try { pops.add(new SimplePopulation(representationData, parameters, inputnumber, outputnumber, loadedPops.get(i))); } catch (Exception e) { e.printStackTrace(); return false; } } return true; }
From source file:org.ballproject.knime.base.config.CTDFileNodeConfigurationReader.java
License:Open Source License
public String getPath(Node n) { List<String> path_nodes = new ArrayList<String>(); while (n != null && !n.getName().equals("PARAMETERS")) { path_nodes.add(n.valueOf("@name")); n = n.getParent();//from www . ja v a 2s. c o m } Collections.reverse(path_nodes); String ret = ""; int N = path_nodes.size(); for (int i = 0; i < N; i++) { if (i == N - 1) { ret += path_nodes.get(i); } else { ret += path_nodes.get(i) + "."; } } return ret; }
From source file:org.ballproject.knime.base.config.CTDFileNodeConfigurationReader.java
License:Open Source License
private void createPortFromNode(Node node, boolean multi) throws Exception { Element elem = (Element) node; String name = node.valueOf("@name"); String descr = node.valueOf("@description"); String tags = node.valueOf("@tags"); if (name.equals("write_ini") || name.equals("write_par") || name.equals("par") || name.equals("help")) return;/*from www . j av a2 s . c om*/ Port port = new Port(); port.setMultiFile(multi); if (tags.contains(this.INPUTFILE_TAG) || tags.contains(this.OUTPUTFILE_TAG)) { String[] file_extensions = null; if (elem.attributeValue("supported_formats") == null) { if (elem.attributeValue("restrictions") != null) { String formats = node.valueOf("@restrictions"); file_extensions = formats.split(","); for (int i = 0; i < file_extensions.length; i++) { file_extensions[i] = file_extensions[i].replace("*.", ""); } } else throw new Exception("i/o item '" + elem.attributeValue("name") + "' with missing attribute supported_formats detected"); } else { String formats = node.valueOf("@supported_formats"); file_extensions = formats.split(","); for (int i = 0; i < file_extensions.length; i++) { file_extensions[i] = file_extensions[i].trim(); } } String path = this.getPath(node); port.setName(path); port.setDescription(descr); boolean optional = true; if (tags.contains("mandatory") || tags.contains("required")) { optional = false; } else { optional = true; } port.setOptional(optional); for (String mt : file_extensions) { port.addMimeType(new MIMEtype(mt.trim())); } } if (tags.contains(this.OUTPUTFILE_TAG)) { out_ports.add(port); this.captured_ports.add(port.getName()); if (multi) { String path = this.getPath(node); FileListParameter param = new FileListParameter(name, new ArrayList<String>()); param.setPort(port); param.setDescription(descr); param.setIsOptional(false); this.config.addParameter(path, param); } } if (tags.contains(this.INPUTFILE_TAG)) { in_ports.add(port); this.captured_ports.add(port.getName()); } }
From source file:org.ballproject.knime.base.config.CTDFileNodeConfigurationReader.java
License:Open Source License
public void processItem(Node elem) throws Exception { String name = elem.valueOf("@name"); String path = this.getPath(elem); if (this.captured_ports.contains(path)) return;// ww w .j a va 2s.c o m if (name.equals("write_ini") || name.equals("write_par") || name.equals("par") || name.equals("help")) return; Parameter<?> param = this.getParameterFromNode(elem); this.config.addParameter(path, param); }
From source file:org.ballproject.knime.base.config.CTDFileNodeConfigurationReader.java
License:Open Source License
public void processMultiItem(Node elem) throws Exception { String name = elem.valueOf("@name"); String path = this.getPath(elem); if (this.captured_ports.contains(path)) return;//from w w w.j a v a2 s . com if (name.equals("write_ini") || name.equals("write_par") || name.equals("par") || name.equals("help")) return; Parameter<?> param = this.getMultiParameterFromNode(elem); this.config.addParameter(path, param); }
From source file:org.ballproject.knime.base.config.CTDFileNodeConfigurationReader.java
License:Open Source License
private void readDescription() throws Exception { Node node = this.doc.selectSingleNode("/tool"); if (node == null) throw new Exception("CTD has no root named tool"); String lstatus = node.valueOf("@status"); if (lstatus != null && lstatus.equals("")) throw new Exception("CTD has no status"); this.config.setStatus(lstatus); node = this.doc.selectSingleNode("/tool/name"); if (node == null) throw new Exception("CTD has no tool name"); String name = node.valueOf("text()"); if (name.equals("")) throw new Exception("CTD has no tool name"); this.config.setName(name); node = this.doc.selectSingleNode("/tool/description"); String sdescr = ""; if (node != null) { sdescr = node.valueOf("text()"); }// w w w .j ava 2s .c o m this.config.setDescription(sdescr); node = this.doc.selectSingleNode("/tool/path"); String spath = ""; if (node != null) { spath = node.valueOf("text()"); } this.config.setCommand(spath); node = this.doc.selectSingleNode("/tool/manual"); String ldescr = ""; if (node != null) { ldescr = node.valueOf("text()"); } this.config.setManual(ldescr); node = this.doc.selectSingleNode("/tool/version"); String lversion = ""; if (node != null) { lversion = node.valueOf("text()"); } this.config.setVersion(lversion); node = this.doc.selectSingleNode("/tool/docurl"); String docurl = ""; if (node != null) { docurl = node.valueOf("text()"); } this.config.setDocUrl(docurl); node = this.doc.selectSingleNode("/tool/category"); String cat = ""; if (node != null) { cat = node.valueOf("text()"); } this.config.setCategory(cat); }
From source file:org.ballproject.knime.base.config.CTDFileNodeConfigurationReader.java
License:Open Source License
private Parameter<?> getParameterFromNode(Node node) throws Exception { Parameter<?> ret = null; String type = node.valueOf("@type"); String name = node.valueOf("@name"); String value = node.valueOf("@value"); String restrs = node.valueOf("@restrictions"); String descr = node.valueOf("@description"); String tags = node.valueOf("@tags"); if (type.toLowerCase().equals("double") || type.toLowerCase().equals("float")) { ret = this.processDoubleParameter(name, value, restrs, tags); } else {/*from w ww .j a v a2 s . com*/ if (type.toLowerCase().equals("int")) { ret = this.processIntParameter(name, value, restrs, tags); } else { if (type.toLowerCase().equals("string")) { ret = this.processStringParameter(name, value, restrs, tags); } } } ret.setDescription(descr); Set<String> tagset = tokenSet(tags); if (tagset.contains("mandatory") || tagset.contains("required")) { ret.setIsOptional(false); } if (tagset.contains("advanced")) { ret.setAdvanced(true); } return ret; }
From source file:org.ballproject.knime.base.config.CTDFileNodeConfigurationReader.java
License:Open Source License
private Parameter<?> getMultiParameterFromNode(Node node) throws Exception { String type = node.valueOf("@type"); String name = node.valueOf("@name"); String restrs = node.valueOf("@restrictions"); String descr = node.valueOf("@description"); String tags = node.valueOf("@tags"); Set<String> tagset = tokenSet(tags); @SuppressWarnings("unchecked") List<Node> subnodes = node.selectNodes("LISTITEM"); List<String> values = new ArrayList<String>(); for (Node n : subnodes) { values.add(n.valueOf("@value")); }//www. j a v a 2s . com Parameter<?> param = null; if (type.toLowerCase().equals("double") || type.toLowerCase().equals("float")) { param = this.processDoubleListParameter(name, values, restrs, tags); } else { if (type.toLowerCase().equals("int")) { param = this.processIntListParameter(name, values, restrs, tags); } else { if (type.toLowerCase().equals("string")) { param = this.processStringListParameter(name, values, restrs, tags); } } } param.setDescription(descr); if (tagset.contains("mandatory") || tagset.contains("required")) { param.setIsOptional(false); } if (tagset.contains("advanced")) { param.setAdvanced(true); } return param; }
From source file:org.ballproject.knime.base.config.CTDFileNodeConfigurationReader.java
License:Open Source License
private void readMapping() throws Exception { Node node = this.doc.selectSingleNode("/tool/mapping"); if (node == null && this.config.getStatus().equals("external")) throw new Exception("CTD has no mapping tag and is an external tool"); if (node == null) return;/*from w w w . jav a 2s . co m*/ String mapping = node.valueOf("text()"); if (mapping.equals("")) throw new Exception("CTD has an empty mapping tag"); this.config.setMapping(mapping); }
From source file:org.ballproject.knime.base.config.DOMHelper.java
License:Open Source License
public static String valueOf(Node n, String query) throws Exception { String val = n.valueOf(query); if (val == null) throw new Exception("XPath query yielded null result"); return val; }