List of usage examples for org.jdom2 Element getName
public String getName()
From source file:delfos.main.managers.experiment.join.xml.AggregateResultsXML.java
License:Open Source License
public Map<String, Object> extractMapFromFile(File inputFile) throws JDOMException, IOException { Element caseStudy; long fileSize = FileUtils.sizeOf(inputFile); if (fileSize > Math.pow(2, 20)) { File smallerFile = new File(inputFile.getPath() + "_smaller"); BufferedWriter writer;//from w ww .ja v a 2s .c o m try (BufferedReader reader = new BufferedReader(new FileReader(inputFile))) { writer = new BufferedWriter(new FileWriter(smallerFile)); String line = reader.readLine(); while (line != null) { if (!line.contains("ndcg_value=")) { writer.write(line); } line = reader.readLine(); } } writer.close(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(smallerFile); caseStudy = doc.getRootElement(); smallerFile.delete(); } else { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(inputFile); caseStudy = doc.getRootElement(); } Map<String, Object> valuesByColumnName = new TreeMap<>(); if (!caseStudy.getName().equals(CASE_ROOT_ELEMENT_NAME)) { throw new IllegalArgumentException( "The XML does not contains a Case Study (" + inputFile.getAbsolutePath() + ")"); } valuesByColumnName.putAll(extractCaseParametersMapFromElement(caseStudy)); valuesByColumnName.putAll(extractCaseResultsMapFromElement(caseStudy)); return valuesByColumnName; }
From source file:delfos.main.managers.experiment.join.xml.AggregateResultsXML.java
License:Open Source License
public Map<String, Object> extractCaseParametersMapFromElement(Element element) { Map<String, Object> valuesByColumnName = new TreeMap<>(); String elementName = element.getName(); if (element.getAttribute("name") != null) { elementName = elementName + "." + element.getAttributeValue("name"); }/*from w ww . ja v a2 s. c o m*/ if (elementName.equals(CASE_ROOT_ELEMENT_NAME)) { for (Attribute attribute : element.getAttributes()) { String name = CaseStudyXML.CASE_ROOT_ELEMENT_NAME + "." + attribute.getName(); String value = attribute.getValue(); valuesByColumnName.put(name, value); } } if (elementName.equals(RelevanceCriteriaXML.ELEMENT_NAME)) { double threshold = RelevanceCriteriaXML.getRelevanceCriteria(element).getThreshold().doubleValue(); valuesByColumnName.put(RelevanceCriteriaXML.ELEMENT_NAME, threshold); } else if (element.getChildren().isEmpty()) { String columnName; String value; if (!element.hasAttributes()) { throw new IllegalArgumentException("arg"); } if (element.getAttribute("name") != null) { columnName = elementName; value = element.getAttributeValue("name"); } else if (element.getAttribute("parameterName") != null) { columnName = element.getAttributeValue("parameterName"); value = element.getAttributeValue("parameterValue"); } else { throw new IllegalStateException("arg"); } valuesByColumnName.put(columnName, value); } else { for (Element child : element.getChildren()) { if (child.getName().equals(AGGREGATE_VALUES_ELEMENT_NAME)) { continue; } if (child.getName().equals(EXECUTIONS_RESULTS_ELEMENT_NAME)) { throw new IllegalArgumentException("The file is a full results file!"); } Map<String, Object> extractCaseParametersMapFromElement = extractCaseParametersMapFromElement( child); for (Map.Entry<String, Object> entry : extractCaseParametersMapFromElement.entrySet()) { String columnNameWithPrefix = elementName + "." + entry.getKey(); Object value = entry.getValue(); valuesByColumnName.put(columnNameWithPrefix, value); } } } return valuesByColumnName; }
From source file:delfos.main.managers.experiment.join.xml.AggregateResultsXML.java
License:Open Source License
private Map<String, Object> extractCaseResultsMapFromElement(Element caseStudy) { Map<String, Object> ret = new TreeMap<>(); Element aggregateValues = caseStudy.getChild(AGGREGATE_VALUES_ELEMENT_NAME); for (Element measureResult : aggregateValues.getChildren()) { if (measureResult.getName().equals(AreaUnderROC.class.getSimpleName()) || measureResult.getName().equals(AreaUnderRoc.class.getSimpleName())) { Element curveElement = measureResult .getChild(ConfusionMatricesCurveXML.CONFUSION_MATRIX_CURVE_ELEMENT_NAME); try { ConfusionMatricesCurve curve = ConfusionMatricesCurveXML .getConfusionMatricesCurve(curveElement); for (int index = 1; index < curve.size(); index++) { double precisionAt = curve.getPrecisionAt(index); DecimalFormat format = new DecimalFormat("000"); ret.put("Precision@" + format.format(index), precisionAt); if (index == 20) { break; }// w w w . j av a2 s . com } } catch (UnrecognizedElementException ex) { Logger.getLogger(AggregateResultsXML.class.getName()).log(Level.SEVERE, null, ex); } } if (measureResult.getName().equals(ParameterOwnerXML.PARAMETER_OWNER_ELEMENT_NAME)) { String measureName = measureResult.getAttributeValue("name"); String measureValue = measureResult.getAttributeValue("value"); ret.put(measureName, measureValue); } else { String measureName = measureResult.getName(); String measureValue = measureResult.getAttributeValue("value"); ret.put(measureName, measureValue); } } return ret; }
From source file:devicemodel.conversions.XmlConversions.java
public static DeviceNode xmlToNode(Element e, String id) { String[] ids = new String[] { "" }; if (e.getAttribute("ids") != null) { ids = e.getAttributeValue("ids").split(","); e.removeAttribute("ids"); }/*from w w w. jav a 2s .c om*/ DeviceNode node = new DeviceNode(e.getName() + id); node.setValue(e.getTextTrim()); for (Attribute a : e.getAttributes()) { node.getAttributes().put(a.getName(), a.getValue()); } for (String cid : ids) { for (Element c : e.getChildren()) { try { node.addChild(xmlToNode(c, cid)); } catch (Exception ex) { } } } return node; }
From source file:devicerestmodel.representations.DevicePropertyNode.java
/** * Checks if the argument XML tag matches the tag name for this property * * @param element/*w w w. ja va 2 s .c o m*/ * @return */ public boolean isXmlValid(Element element) { if (element != null && element.getName().equalsIgnoreCase(getName())) { return true; } else { return false; } }
From source file:devicerestmodel.types.DeviceProperty.java
/** * Checks if the argument XML tag matches the tag name for this property * * @param element/*from w ww.ja va 2 s . com*/ * @return */ public boolean isXmlValid(Element element) { if (element.getName().equals(name)) { return true; } else { return false; } }
From source file:devicerestservice.ExampleApp.java
public static void main(String[] args) throws IOException { if (args.length != 2) { System.out.println("Must specify configuration file and device description"); System.exit(1);//from w w w. j a v a 2 s . c o m } File xmlConfig = new File(args[0]); File xmlDeviceDesc = new File(args[1]); if (!xmlConfig.exists()) { System.out.println("Configuration file not found."); System.exit(2); } if (!xmlDeviceDesc.exists()) { System.out.println("Device description file not found."); System.exit(3); } SAXBuilder builder = new SAXBuilder(); Element configurationElement = null; Element deviceDescriptionElement = null; try { Document document = (Document) builder.build(xmlConfig); configurationElement = document.getRootElement(); } catch (JDOMException ex) { System.out.println("Can't parse configuration file."); System.exit(4); } try { Document document = (Document) builder.build(xmlDeviceDesc); deviceDescriptionElement = document.getRootElement(); } catch (JDOMException ex) { System.out.println("Can't parse device description file."); System.exit(5); } if (configurationElement == null || !configurationElement.getName().equals("Device")) { System.out.println("Not a proper configuration XML file."); System.out.println( "Ensure XML has elements in Pascal Case (i.e. DeviceName not deviceName or devicename)"); System.exit(6); } new ExampleApp(configurationElement, deviceDescriptionElement); }
From source file:dibl.diagrams.Template.java
License:Open Source License
private void collectTileElements() { final XPathFactory f = XPathFactory.instance(); // TODO extend xpath with condition inside for-loop final XPathExpression<Element> xpath = f.compile("//*[@inkscape:label='base tile']/*", Filters.element(), null, NS_INKSCAPE);/*from ww w . j a v a 2 s . co m*/ for (final Element el : xpath.evaluate(doc)) { if (el.getName().equals("use")) { final String cellID = el.getAttributeValue("label", NS_INKSCAPE); if (cellID != null && cellID.trim().length() > 0) { if (!tileElements.containsKey(cellID.trim())) tileElements.put(cellID.trim(), new HashSet<Element>()); tileElements.get(cellID.trim()).add((el)); } final int r = cellID.toCharArray()[1] - '1'; final int c = cellID.toCharArray()[0] - 'A'; if (r >= getNrOfRows()) nrOfRows = r + 1; if (c >= getNrOfCols()) nrOfCols = c + 1; } } }
From source file:ditatools.translate.DitaTranslator.java
License:Apache License
/** * /*from w w w . j a v a2 s .com*/ * @param xmlFile * the xml file to be translated * @param outputXmlFile * the output file */ public void translateXML(File xmlFile, File outputXmlFile) { try { Document doc = builder.build(xmlFile); Element rootElement = doc.getRootElement(); String rootElementName = rootElement.getName(); if (rootElementName.equalsIgnoreCase("concept") || rootElementName.equalsIgnoreCase("task") || rootElementName.equalsIgnoreCase("reference")) { translateTopicXML(doc, outputXmlFile); } else if (rootElementName.equalsIgnoreCase("map")) { translateDitaMap(doc, outputXmlFile); } else { System.err.println("Skipping file; Unknown element: " + rootElementName); } } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:diuf.diva.dia.ms.script.command.AbstractCommand.java
License:Open Source License
/** * Read an attribute of a tag.//w w w. jav a2 s . c om * * @param e the element from which we want to read * @param name the name of the attribute field * @return the value of the attribute */ public String readAttribute(Element e, String name) { String result = e.getAttributeValue(name); if (result == null) { throw new Error(tagName() + ": Cannot find attribute " + name + " in element " + e.getName()); } return script.preprocess(result); }