List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator(QName qName);
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/*from w ww. j a v a2s. co m*/ * @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// ww w . ja v a 2 s. c om * @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/*from w w w .j a va 2s . c o 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// w ww.j a v a2 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; }
From source file:fr.ens.transcriptome.teolenn.DesignReader.java
License:Open Source License
/** * Test if the phase of the element must be skipped. * @param rootElement DOM root element//from ww w . ja v a2s . c o m * @param elementName Name of the tag to test * @return true if the phase of the element must be skipped */ private final boolean isSkipElementEnable(final Element rootElement, final String elementName) { boolean result = false; for (Iterator i = rootElement.elementIterator(elementName); i.hasNext();) { final Element e = (Element) i.next(); final String value = e.attributeValue("skip"); if (value == null) return false; result = Boolean.parseBoolean(value.trim()); } return result; }
From source file:fr.mael.microrss.xml.opml.OPMLReader.java
License:Open Source License
public List<Category> parse(InputStream stream) throws DocumentException { List<Category> categories = new ArrayList<Category>(); SAXReader reader = new SAXReader(); Document document = reader.read(stream); Element root = document.getRootElement(); Element body = (Element) root.elementIterator("body").next(); for (Iterator i = body.elementIterator("outline"); i.hasNext();) { Element el = (Element) i.next(); Category cat = getCategory(el, null); categories.add(cat);/*from w w w .ja va 2 s . co m*/ parseCategories(el, cat); } return categories; }
From source file:fr.mael.microrss.xml.opml.OPMLReader.java
License:Open Source License
private void parseCategories(Element element, Category parent) { for (Iterator i = element.elementIterator("outline"); i.hasNext();) { Element el = (Element) i.next(); if (isFeed(el)) { parent.getUserFeeds().add(getFeed(el, parent)); } else {//from w ww . j a v a2 s. co m Category cat = getCategory(el, parent); parseCategories(el, cat); } } }
From source file:galign.helpers.AlignmentMapping.java
License:Apache License
/** * Reads and validates a GAM XML file./* w ww. j a v a 2s.c om*/ */ protected void init(SAXReader p_reader, InputSource p_input) throws org.dom4j.DocumentException { Document dom = p_reader.read(p_input); Element root = dom.getRootElement(); m_version = root.attributeValue("version"); m_sourceTmxFileName = root.attributeValue("source-tmx"); m_targetTmxFileName = root.attributeValue("target-tmx"); clearAlignRecords(); for (Iterator i = root.elementIterator("align"); i.hasNext();) { // Example data: <align source="7,8" target="12,14" approved="N" /> Element item = (Element) i.next(); StringTokenizer tok1 = new StringTokenizer(item.attributeValue("source"), ","); while (tok1.hasMoreTokens()) { Align align = new Align(); align.m_source = tok1.nextToken(); StringTokenizer tok2 = new StringTokenizer(item.attributeValue("target"), " ,"); boolean first = true; while (tok2.hasMoreTokens()) { if (first) { align.m_target = tok2.nextToken(); align.m_approved = item.attributeValue("approved"); addAlignRecord(align); first = false; } else { Align align2 = new Align(); align2.m_source = align.m_source; align2.m_target = tok2.nextToken(); align2.m_approved = item.attributeValue("approved"); addAlignRecord(align2); } } } } clearRemoveRecords(); for (Iterator i = root.elementIterator("remove"); i.hasNext();) { Element item = (Element) i.next(); Remove remove = new Remove(); remove.m_id = item.attributeValue("id"); remove.m_isSource = item.attributeValue("locale"); addRemoveRecord(remove); } clearIsolateRecords(); for (Iterator i = root.elementIterator("isolate"); i.hasNext();) { Element item = (Element) i.next(); Isolate isolate = new Isolate(); isolate.m_id = item.attributeValue("id"); isolate.m_isSource = item.attributeValue("locale"); isolate.m_approved = item.attributeValue("approved"); addIsolateRecord(isolate); } }
From source file:galign.helpers.AlignmentPackage.java
License:Apache License
/** * Reads and validates a GAP XML file./*from w w w .j a v a2 s .c o m*/ */ protected void init(SAXReader p_reader, InputSource p_input, String p_dir) throws org.dom4j.DocumentException { Document dom = p_reader.read(p_input); Element root = dom.getRootElement(); m_version = root.attributeValue("version"); m_sourceLocale = root.attributeValue("source-locale"); m_targetLocale = root.attributeValue("target-locale"); m_dir = p_dir; m_files.clear(); for (Iterator i = root.elementIterator("files"); i.hasNext();) { Element item = (Element) i.next(); File file = new File(); file.m_originalSourceFileName = item.attributeValue("original-source-file"); file.m_originalTargetFileName = item.attributeValue("original-target-file"); file.m_sourceCuvId = item.attributeValue("source-cuv-id"); file.m_targetCuvId = item.attributeValue("target-cuv-id"); file.m_sourceTmxFileName = item.attributeValue("source-tmx"); file.m_targetTmxFileName = item.attributeValue("target-tmx"); file.m_mappingFileName = item.attributeValue("gam"); file.m_state = item.attributeValue("state"); addFile(file); } }
From source file:galign.helpers.tmx.TmxHeader.java
License:Apache License
private void init(Element p_element) { Attribute attr;/*from ww w . j a v a 2 s . c o m*/ List nodes; Date date; // mandatory m_creationtoolversion = p_element.attributeValue(CREATIONTOOLVERSION); m_creationtool = p_element.attributeValue(CREATIONTOOL); m_segtype = p_element.attributeValue(SEGTYPE); m_o_tmf = p_element.attributeValue(O_TMF); m_adminlang = p_element.attributeValue(ADMINLANG); m_srclang = p_element.attributeValue(SRCLANG); m_datatype = p_element.attributeValue(DATATYPE); // optional m_o_encoding = p_element.attributeValue(O_ENCODING); m_creationid = p_element.attributeValue(CREATIONID); m_changeid = p_element.attributeValue(CHANGEID); attr = p_element.attribute(CREATIONDATE); if (attr == null) { date = null; } else { date = UTC.parseNoSeparators(attr.getValue()); if (date == null) { date = UTC.parse(attr.getValue()); } } m_creationdate = date; attr = p_element.attribute(CHANGEDATE); if (attr == null) { date = null; } else { date = UTC.parseNoSeparators(attr.getValue()); if (date == null) { date = UTC.parse(attr.getValue()); } } m_changedate = date; // elements for (Iterator i = p_element.elementIterator("note"); i.hasNext();) { Element node = (Element) i.next(); m_notes.add(new Note(node)); } for (Iterator i = p_element.elementIterator("prop"); i.hasNext();) { Element node = (Element) i.next(); m_props.add(new Prop(node)); } // TODO: UDE }