List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:eu.planets_project.pp.plato.util.XMLCompare.java
License:Open Source License
private boolean compareTrees(Element node1, Document doc2, boolean ignoreEmptyNodes, boolean ignoreEmptyAttributes) { boolean isValid = true; Element root2 = doc2.getRootElement(); String path = node1.getUniquePath(); Element elementDoc2 = (Element) doc2.selectSingleNode(path); // the node doesn't exist in doc2 if (elementDoc2 == null && node1.elements().size() == 0 && "".equals(node1.getTextTrim())) { if (ignoreEmptyNodes == false) { errorMessages//from w ww. j av a 2s. co m .append("The following empty node doesnt exist in xml file #2: " + node1.getUniquePath()) .append(System.getProperty("line.separator")); isValid = false; } } else if (elementDoc2 == null && (node1.elements().size() > 0 || !"".equals(node1.getTextTrim()))) { errorMessages.append("The following node (which is not empty) doesn't exist in xml file #2: " + node1.getUniquePath() + System.getProperty("line.separator")); errorMessages.append("File #1: " + node1.getTextTrim() + System.getProperty("line.separator")); errorMessages .append("File #2: " + ((elementDoc2 == null) ? "<not existent>" : elementDoc2.getTextTrim()) + System.getProperty("line.separator")); isValid = false; } else if (elementDoc2 == null || !elementDoc2.getTextTrim().equals(node1.getTextTrim())) { errorMessages.append("Text of following nodes not equal in both xmls: " + node1.getUniquePath() + System.getProperty("line.separator")); errorMessages.append("File #1: " + node1.getTextTrim() + System.getProperty("line.separator")); errorMessages .append("File #2: " + ((elementDoc2 == null) ? "<not existent>" : elementDoc2.getTextTrim()) + System.getProperty("line.separator")); isValid = false; } // // compare attributes // List<Attribute> attributes = node1.attributes(); for (Attribute a : attributes) { String attributePath = a.getUniquePath(); org.dom4j.Node node = root2.selectSingleNode(attributePath); if (node == null && "".equals(a.getValue().trim())) { // document 1 has an empty attribute (sting length = 0) which // does not exist in document 2 if (ignoreEmptyAttributes == false) { errorMessages.append( "Attribute " + a.getName() + " doesn't exist in xml file #2, node " + a.getUniquePath()) .append(System.getProperty("line.separator")); isValid = false; } continue; } if (node == null || !a.getValue().equals(node.getText())) { errorMessages.append("Value of following attribute not equal in both xmls: " + a.getUniquePath() + System.getProperty("line.separator")); errorMessages.append("File #1: " + a.getValue() + System.getProperty("line.separator")); errorMessages.append("File #2: " + ((node != null) ? node.getText() : "<not existent>") + System.getProperty("line.separator")); isValid = false; } } List<Element> elements = node1.elements(); for (Element e : elements) { if (!compareTrees(e, doc2, ignoreEmptyNodes, ignoreEmptyAttributes)) { isValid = false; } } return isValid; }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
private String getValue(final Element e) { if (e == null) return ""; return getValue(e.getTextTrim()); }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Parse the "sequencefilters" element of the DOM. * @param rootElement root element of the document * @return a list of SequenceFilter objects * @throws IOException if an error occurs while parsing *//*from www .ja va2 s . co m*/ private List<SequenceFilter> parseSequenceFilters(final Element rootElement) throws IOException { List<SequenceFilter> list = new ArrayList<SequenceFilter>(); for (Iterator i = rootElement.elementIterator("sequencefilters"); i.hasNext();) { final Element filters = (Element) i.next(); for (Iterator i2 = filters.elementIterator("sequencefilter"); i2.hasNext();) { final Element filter = (Element) i2.next(); String filterName = null; for (Iterator i3 = filter.elementIterator("name"); i3.hasNext();) { final Element name = (Element) i3.next(); filterName = name.getTextTrim(); } if (filterName == null) { logger.warning("Filter without name."); continue; } // Add the sequence filter to the registery if it is a plug in for (Iterator i4 = filter.elementIterator("class"); i4.hasNext();) { final Element clazz = (Element) i4.next(); String filterClass = clazz.getTextTrim(); SequenceFilterRegistery.addSequenceFilterType(filterName, filterClass); } // Get the parameters of the sequenceFilter final Properties properties = getElementParameters(filter); final SequenceFilter f = SequenceFilterRegistery.getSequenceFilter(filterName); if (f == null) logger.warning("Unknown sequence filter: " + filterName); else { for (Map.Entry<Object, Object> entry : properties.entrySet()) // Set the initialization parameters for the sequence filter f.setInitParameter((String) entry.getKey(), (String) entry.getValue()); list.add(f); } } } // Set the defaults initialization parameters of the sequence filters for (SequenceFilter sq : list) this.design.setDefaultModuleInitParameters(sq); return list; }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Parse the "measurements" element of the DOM. * @param rootElement root element of the document * @return a list of Measurement objects * @throws IOException if an error occurs while parsing */// www. j a v a2 s. co m private List<Measurement> parseMeasurements(final Element rootElement) throws IOException { final List<Measurement> list = new ArrayList<Measurement>(); list.add(new ChromosomeMeasurement()); list.add(new OligoStartMeasurement()); list.add(new OligoLengthMeasurement()); for (Iterator i = rootElement.elementIterator("measurements"); i.hasNext();) { final Element measurements = (Element) i.next(); for (Iterator i2 = measurements.elementIterator("measurement"); i2.hasNext();) { final Element measurement = (Element) i2.next(); String measurementName = null; for (Iterator i3 = measurement.elementIterator("name"); i3.hasNext();) { final Element name = (Element) i3.next(); measurementName = name.getTextTrim(); } if (measurementName == null) { logger.warning("Measurement without name."); continue; } // Skip if user attempt to add another Scaffold measurement if (ChromosomeMeasurement.MEASUREMENT_NAME.toLowerCase().equals(measurementName.toLowerCase())) continue; // Skip if user attempt to add another oligo start measurement if (OligoStartMeasurement.MEASUREMENT_NAME.toLowerCase().equals(measurementName.toLowerCase())) continue; // Add the measurement to registery if it is a plug in for (Iterator i4 = measurement.elementIterator("class"); i4.hasNext();) { final Element clazz = (Element) i4.next(); String measurementClass = clazz.getTextTrim(); MeasurementRegistery.addMeasurementType(measurementName, measurementClass); } // Get the parameters of the measurement final Properties properties = getElementParameters(measurement); final Measurement m = MeasurementRegistery.getMeasurement(measurementName); if (m == null) logger.warning("Unknown measurement: " + measurementName); else { // Set the initialization parameters for the measurement for (Map.Entry<Object, Object> entry : properties.entrySet()) m.setInitParameter((String) entry.getKey(), (String) entry.getValue()); list.add(m); } } } // Set the default initialization parameters of the measurements for (Measurement m : list) this.design.setDefaultModuleInitParameters(m); return list; }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Parse the "measurementfilters" element of the DOM. * @param rootElement root element of the document * @return a list of MeasurementFilter objects * @throws IOException if an error occurs while parsing *//*from ww w .jav a2 s . com*/ private List<MeasurementFilter> parseMeasurementFilters(final Element rootElement) throws IOException { final List<MeasurementFilter> list = new ArrayList<MeasurementFilter>(); for (Iterator i = rootElement.elementIterator("measurementfilters"); i.hasNext();) { final Element filters = (Element) i.next(); for (Iterator i2 = filters.elementIterator("measurementfilter"); i2.hasNext();) { final Element filter = (Element) i2.next(); String measurementFilterName = null; for (Iterator i3 = filter.elementIterator("name"); i3.hasNext();) { final Element name = (Element) i3.next(); measurementFilterName = name.getTextTrim(); } if (measurementFilterName == null) { logger.warning("Measurement filter without name."); continue; } // Add the measurement to registery if it is a plug in for (Iterator i4 = filter.elementIterator("class"); i4.hasNext();) { final Element clazz = (Element) i4.next(); String measurementClass = clazz.getTextTrim(); MeasurementFilterRegistery.addMeasurementFilterType(measurementFilterName, measurementClass); } // Get the parameters of the measurement filters final Properties properties = getElementParameters(filter); final MeasurementFilter mf = MeasurementFilterRegistery .getMeasuremrentFilter(measurementFilterName); if (mf == null) logger.warning("Unknown measurement: " + measurementFilterName); else { // Set the initialization parameters for the measurement filters for (Map.Entry<Object, Object> entry : properties.entrySet()) mf.setInitParameter((String) entry.getKey(), (String) entry.getValue()); list.add(mf); } } } // Set the defaults initialization parameters of the measurements filters for (MeasurementFilter mf : list) this.design.setDefaultModuleInitParameters(mf); return list; }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Parse the "selector" element of the DOM. * @param rootElement root element of the document * @return a selector objects//w w w .ja va 2 s . co m * @throws TeolennException if an error occurs while parsing */ private SequenceSelector parseSelector(final Element rootElement) throws TeolennException { for (Iterator i = rootElement.elementIterator("selector"); i.hasNext();) { final Element selector = (Element) i.next(); String selectorName = null; for (Iterator i1 = selector.elementIterator("name"); i1.hasNext();) { final Element name = (Element) i1.next(); selectorName = name.getTextTrim(); } // Add the selector to registery if it is a plug in for (Iterator i2 = selector.elementIterator("class"); i2.hasNext();) { final Element clazz = (Element) i2.next(); String selectorClass = clazz.getTextTrim(); SequenceSelectorRegistery.addSequenceSelectorType(selectorName, selectorClass); } // Get the parameters of the measurement final Properties properties = getElementParameters(selector); SequenceSelector s = SequenceSelectorRegistery.getSequenceSelector(selectorName); if (s == null) { logger.warning("Unknown selector: " + selectorName); throw new TeolennException("Unknown selector: " + selectorName); } // Set the initialization parameters for the selector for (Map.Entry<Object, Object> entry : properties.entrySet()) s.setInitParameter((String) entry.getKey(), (String) entry.getValue()); // Set defaults parameters this.design.setDefaultModuleInitParameters(s); return s; } throw new TeolennException("No selector found."); }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Parse the "select" element of the DOM. * @param rootElement root element of the document * @return a list of weights objects/*w w w .j a v a 2 s. c om*/ * @throws IOException if an error occurs while parsing */ private WeightsSetter parseSelectWeights(final Element rootElement) throws IOException { // Map of weights final Map<String, Float> selectWeights = new HashMap<String, Float>(); // Map of properties final Map<String, Properties> selectProperties = new HashMap<String, Properties>(); for (Iterator i = rootElement.elementIterator("selector"); i.hasNext();) { final Element select = (Element) i.next(); for (Iterator i2 = select.elementIterator("measurement"); i2.hasNext();) { final Element measurement = (Element) i2.next(); String measurementName = null; String measurementWeight = null; for (Iterator i3 = measurement.elementIterator("name"); i3.hasNext();) { final Element name = (Element) i3.next(); measurementName = name.getTextTrim(); } if (measurementName == null) { logger.warning("Measurement without name."); continue; } // Get the weight for the measurement for (Iterator i4 = measurement.elementIterator("weight"); i4.hasNext();) { final Element weight = (Element) i4.next(); measurementWeight = weight.getTextTrim(); } try { selectWeights.put(measurementName, Float.parseFloat(measurementWeight)); } catch (NumberFormatException e) { logger.warning("Invalid " + measurementName + " weight: " + measurementWeight); } // Get the properties of the measurement selectProperties.put(measurementName, getElementParameters(measurement)); } } return new WeightsSetter() { @Override public void setWeights(SequenceMeasurements sm) { // Set the weights for (Map.Entry<String, Float> e : selectWeights.entrySet()) sm.setWeight(sm.getMeasurement(e.getKey()), e.getValue()); // Set the properties for (Map.Entry<String, Properties> e : selectProperties.entrySet()) { final String name = e.getKey(); final Properties properties = e.getValue(); if (!sm.isMeasurement(name)) { logger.warning("Unknown measurement: " + name); continue; } for (Map.Entry<Object, Object> e2 : properties.entrySet()) { sm.getMeasurement(name).setProperty((String) e2.getKey(), (String) e2.getValue()); } } } }; }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Parse the "output" element of the DOM. * @param rootElement root element of the document * @return a selector objects/* w ww . j ava2 s.com*/ * @throws TeolennException if an error occurs while parsing */ private List<Output> parseOutput(final Element rootElement) throws TeolennException { List<Output> list = new ArrayList<Output>(); for (Iterator i = rootElement.elementIterator("outputs"); i.hasNext();) { final Element outputs = (Element) i.next(); for (Iterator i1 = outputs.elementIterator("output"); i1.hasNext();) { final Element output = (Element) i1.next(); String selectorName = null; for (Iterator i2 = output.elementIterator("name"); i2.hasNext();) { final Element name = (Element) i2.next(); selectorName = name.getTextTrim(); } // Add the selector to registery if it is a plug in for (Iterator i3 = output.elementIterator("class"); i3.hasNext();) { final Element clazz = (Element) i3.next(); String outputClass = clazz.getTextTrim(); OutputRegistery.addOutputType(selectorName, outputClass); } // Get the parameters of the measurement final Properties properties = getElementParameters(output); Output o = OutputRegistery.getOutput(selectorName); if (output == null) { logger.warning("Unknown output: " + selectorName); throw new TeolennException("Unknown output: " + selectorName); } // Set the initialization parameters for the selector for (Map.Entry<Object, Object> entry : properties.entrySet()) o.setInitParameter((String) entry.getKey(), (String) entry.getValue()); list.add(o); } } if (list.size() == 0) list.add(new DefaultOutput()); // Set the default initialization parameters of the outputs for (Output o : list) this.design.setDefaultModuleInitParameters(o); return list; }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Get the parameter of an element// w w w. j a va 2 s . co m * @param element Element to parse * @return a Properties object with the name and values of the parameters */ private final Properties getElementParameters(final Element element) { final Properties result = new Properties(); for (Iterator i4 = element.elementIterator("parameters"); i4.hasNext();) { final Element params = (Element) i4.next(); for (Iterator i5 = params.elementIterator("parameter"); i5.hasNext();) { final Element param = (Element) i5.next(); String pKey = null; String pValue = null; for (Iterator i6 = param.elementIterator("name"); i6.hasNext();) { final Element name = (Element) i6.next(); pKey = name.getTextTrim().toLowerCase(); } for (Iterator i7 = param.elementIterator("value"); i7.hasNext();) { final Element value = (Element) i7.next(); pValue = getValue(value.getTextTrim()); } if (pKey != null && pValue != null) result.setProperty(pKey, pValue); } } return result; }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Get the constants/*from ww w .j ava2 s. c o m*/ * @param element Element to parse * @return a Properties object with the name and values of the parameters */ private final Properties getElementConstants(final Element element) { final Properties result = new Properties(); for (Iterator i4 = element.elementIterator("constants"); i4.hasNext();) { final Element params = (Element) i4.next(); for (Iterator i5 = params.elementIterator("constant"); i5.hasNext();) { final Element param = (Element) i5.next(); String pKey = null; String pValue = null; for (Iterator i6 = param.elementIterator("name"); i6.hasNext();) { final Element name = (Element) i6.next(); pKey = name.getTextTrim().toLowerCase(); } for (Iterator i7 = param.elementIterator("value"); i7.hasNext();) { final Element value = (Element) i7.next(); pValue = value.getTextTrim(); } if (pKey != null || pValue != null) result.setProperty(pKey, pValue); } } return result; }