List of usage examples for org.jdom2 Element getChildren
public List<Element> getChildren()
List
of all the child elements nested directly (one level deep) within this element, as Element
objects. From source file:de.sub.goobi.config.DigitalCollections.java
License:Open Source License
public static List<String> possibleDigitalCollectionsForProcess(Process process) throws JDOMException, IOException { List<String> result = new ArrayList<String>(); String filename = ConfigurationHelper.getInstance().getConfigurationFolder() + "goobi_digitalCollections.xml"; if (!Files.exists(Paths.get(filename))) { throw new FileNotFoundException("File not found: " + filename); }// w ww .j av a 2 s . c om /* Datei einlesen und Root ermitteln */ SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(filename); Element root = doc.getRootElement(); /* alle Projekte durchlaufen */ List<Element> projekte = root.getChildren(); for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) { Element projekt = iter.next(); List<Element> projektnamen = projekt.getChildren("name"); for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) { Element projektname = iterator.next(); /* * wenn der Projektname aufgefhrt wird, dann alle Digitalen Collectionen in die Liste */ if (projektname.getText().equalsIgnoreCase(process.getProjekt().getTitel())) { List<Element> myCols = projekt.getChildren("DigitalCollection"); for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) { Element col = it2.next(); result.add(col.getText()); } } } } return result; }
From source file:de.sub.goobi.config.DigitalCollections.java
License:Open Source License
public static String getDefaultDigitalCollectionForProcess(Process process) throws JDOMException, IOException { String filename = ConfigurationHelper.getInstance().getConfigurationFolder() + "goobi_digitalCollections.xml"; if (!Files.exists(Paths.get(filename))) { throw new FileNotFoundException("File not found: " + filename); }//from w ww . j a v a 2 s.c o m String firstCollection = ""; /* Datei einlesen und Root ermitteln */ SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(filename); Element root = doc.getRootElement(); /* alle Projekte durchlaufen */ List<Element> projekte = root.getChildren(); for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) { Element projekt = iter.next(); List<Element> projektnamen = projekt.getChildren("name"); for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) { Element projektname = iterator.next(); /* * wenn der Projektname aufgefhrt wird, dann alle Digitalen Collectionen in die Liste */ if (projektname.getText().equalsIgnoreCase(process.getProjekt().getTitel())) { List<Element> myCols = projekt.getChildren("DigitalCollection"); for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) { Element col = it2.next(); String collectionName = col.getText(); String defaultCollection = col.getAttributeValue("default"); if (defaultCollection.equalsIgnoreCase("true")) { return collectionName; } if (StringUtils.isBlank(firstCollection)) { firstCollection = collectionName; } } } } } return firstCollection; }
From source file:de.sub.goobi.forms.MassImportForm.java
License:Open Source License
/** * generate a list with all possible collections for given project *///from w w w .ja va2 s . c o m private void initializePossibleDigitalCollections() { this.possibleDigitalCollection = new ArrayList<>(); ArrayList<String> defaultCollections = new ArrayList<>(); String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml"; if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) { Helper.setFehlerMeldung("File not found: ", filename); return; } this.digitalCollections = new ArrayList<>(); try { /* Datei einlesen und Root ermitteln */ SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(filename); Element root = doc.getRootElement(); /* alle Projekte durchlaufen */ List<Element> projekte = root.getChildren(); for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) { Element projekt = iter.next(); // collect default collections if (projekt.getName().equals("default")) { List<Element> myCols = projekt.getChildren("DigitalCollection"); for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) { Element col = it2.next(); if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) { digitalCollections.add(col.getText()); } defaultCollections.add(col.getText()); } } else { // run through the projects List<Element> projektnamen = projekt.getChildren("name"); for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) { Element projektname = iterator.next(); // all all collections to list if (projektname.getText().equalsIgnoreCase(this.template.getProjekt().getTitel())) { List<Element> myCols = projekt.getChildren("DigitalCollection"); for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) { Element col = it2.next(); if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) { digitalCollections.add(col.getText()); } this.possibleDigitalCollection.add(col.getText()); } } } } } } catch (JDOMException e1) { log.error("error while parsing digital collections", e1); Helper.setFehlerMeldung("Error while parsing digital collections", e1); } catch (IOException e1) { log.error("error while parsing digital collections", e1); Helper.setFehlerMeldung("Error while parsing digital collections", e1); } if (this.possibleDigitalCollection.size() == 0) { this.possibleDigitalCollection = defaultCollections; } }
From source file:de.sub.goobi.forms.ProzesskopieForm.java
License:Open Source License
private void initializePossibleDigitalCollections() { this.possibleDigitalCollection = new ArrayList<>(); ArrayList<String> defaultCollections = new ArrayList<>(); String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml"; if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) { Helper.setFehlerMeldung("File not found: ", filename); return;//from ww w .j a v a2 s .c om } this.digitalCollections = new ArrayList<>(); try { /* Datei einlesen und Root ermitteln */ SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(filename); Element root = doc.getRootElement(); /* alle Projekte durchlaufen */ List<Element> projekte = root.getChildren(); for (Iterator<Element> iter = projekte.iterator(); iter.hasNext();) { Element projekt = iter.next(); // collect default collections if (projekt.getName().equals("default")) { List<Element> myCols = projekt.getChildren("DigitalCollection"); for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) { Element col = it2.next(); if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) { digitalCollections.add(col.getText()); } defaultCollections.add(col.getText()); } } else { // run through the projects List<Element> projektnamen = projekt.getChildren("name"); for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext();) { Element projektname = iterator.next(); // all all collections to list if (projektname.getText().equalsIgnoreCase(this.prozessKopie.getProjekt().getTitel())) { List<Element> myCols = projekt.getChildren("DigitalCollection"); for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext();) { Element col = it2.next(); if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) { digitalCollections.add(col.getText()); } this.possibleDigitalCollection.add(col.getText()); } } } } } } catch (JDOMException e1) { logger.error("error while parsing digital collections", e1); Helper.setFehlerMeldung("Error while parsing digital collections", e1); } catch (IOException e1) { logger.error("error while parsing digital collections", e1); Helper.setFehlerMeldung("Error while parsing digital collections", e1); } if (this.possibleDigitalCollection.size() == 0) { this.possibleDigitalCollection = defaultCollections; } // if only one collection is possible take it directly if (isSingleChoiceCollection()) { this.digitalCollections.add(getDigitalCollectionIfSingleChoice()); } }
From source file:de.sub.goobi.helper.HelperSchritte.java
License:Open Source License
private static void addMetadata(List<Element> elements, Map<String, List<String>> metadataPairs) { for (Element goobimetadata : elements) { String metadataType = goobimetadata.getAttributeValue("name"); String metadataValue = ""; if (goobimetadata.getAttributeValue("type") != null && goobimetadata.getAttributeValue("type").equals("person")) { Element displayName = goobimetadata.getChild("displayName", goobiNamespace); if (displayName != null && !displayName.getValue().equals(",")) { metadataValue = displayName.getValue(); }/*from w ww . j a v a 2 s . c o m*/ } else if (goobimetadata.getAttributeValue("type") != null && goobimetadata.getAttributeValue("type").equals("group")) { List<Element> groupMetadataList = goobimetadata.getChildren(); addMetadata(groupMetadataList, metadataPairs); } else { metadataValue = goobimetadata.getValue(); } if (!metadataValue.equals("")) { if (metadataPairs.containsKey(metadataType)) { List<String> oldValue = metadataPairs.get(metadataType); if (!oldValue.contains(metadataValue)) { oldValue.add(metadataValue); metadataPairs.put(metadataType, oldValue); } } else { List<String> list = new ArrayList<>(); list.add(metadataValue); metadataPairs.put(metadataType, list); } } } return; }
From source file:de.tor.tribes.util.xml.JDomUtils.java
License:Apache License
private static List<Element> getList(Element pElement, String path) { if (path == null) { return pElement.getChildren(); }//from w w w .j ava2 s .c om if (path.indexOf('/') != -1) { List<Element> result = new ArrayList<>(); //this is a path we can only get sub elements --> split String preparedPath = path.substring(path.indexOf('/') + 1); for (Element e : pElement.getChildren(path.substring(0, path.indexOf('/')))) { result.addAll(getList(e, preparedPath)); } return result; } return pElement.getChildren(path); }
From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java
License:Open Source License
/** * Parses Nodes/*from w ww . ja v a 2s. co m*/ */ public void readNodes() { List<Element> nodeelemlist = this.graph.getChildren("node", this.ns); int number = 1; for (Element e : nodeelemlist) { Element latitude_elem = findElementById(e.getChildren(), latitude_key); double latitude = (latitude_elem == null) ? 0 : Double.parseDouble(latitude_elem.getText()); Element longitude_elem = findElementById(e.getChildren(), longitude_key); double longitude = (longitude_elem == null) ? 0 : Double.parseDouble(longitude_elem.getText()); if (latitude == 0 || longitude == 0) { continue; } Element country_elem = findElementById(e.getChildren(), country_key); String country = (country_elem == null) ? "" : country_elem.getText(); Element city_elem = findElementById(e.getChildren(), label_key); String city = (city_elem == null) ? "" : city_elem.getText(); Element id_elem = findElementById(e.getChildren(), id_key); int id = Integer.parseInt(id_elem.getText()); Node n = findNodeByCoords(nodelist, longitude, latitude); if (n != null) { n.addId(id); } else { Node node = new Node(number, city, id, country, longitude, latitude); nodelist.add(node); number++; } } }
From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java
License:Open Source License
/** * Parses Edges//from ww w .jav a 2s. c om */ public void readEdges() { if (nodelist.isEmpty()) { logger.error("Read in Nodes first!"); System.exit(-1); } List<Element> edgeelemlist = this.graph.getChildren("edge", this.ns); for (Element e : edgeelemlist) { Attribute source_attr = e.getAttribute("source"); int source = Integer.parseInt(source_attr.getValue()); Attribute target_attr = e.getAttribute("target"); int target = Integer.parseInt(target_attr.getValue()); Element linkspeed_elem = findElementById(e.getChildren(), linklabel_key); double linkspeed = 0.0; if (linkspeed_elem != null) { Scanner scanner = new Scanner(linkspeed_elem.getText()); while (!scanner.hasNextDouble() && scanner.hasNext()) { scanner.next(); } if (scanner.hasNextDouble()) { linkspeed = scanner.nextDouble(); } if (linkspeed_elem.getText().contains("Mbps")) { linkspeed *= 1E06; } if (linkspeed_elem.getText().contains("Gbps")) { linkspeed *= 1E09; } scanner.close(); } Node sourcenode = null; Node targetnode = null; for (Node n : this.nodelist) { if (n.getIds().contains(source)) { sourcenode = n; } if (n.getIds().contains(target)) { targetnode = n; } } if (sourcenode == null || targetnode == null || sourcenode == targetnode || findEdge(edgelist, sourcenode, targetnode) != null) { continue; } Edge edge = new Edge(sourcenode, targetnode, linkspeed); this.edgelist.add(edge); } }
From source file:delfos.group.io.xml.casestudy.GroupCaseStudyXML.java
License:Open Source License
private static Map<GroupEvaluationMeasure, GroupEvaluationMeasureResult> getEvaluationMeasures( Element caseStudy) {//from ww w . j ava 2 s . c o m Map<GroupEvaluationMeasure, GroupEvaluationMeasureResult> groupEvaluationMeasures = new TreeMap<>(); Element aggregateValues = caseStudy.getChild(AGGREGATE_VALUES_ELEMENT_NAME); if (aggregateValues == null) { throw new IllegalStateException( "Unable to load a case study description only, the XML must have results details."); } for (Element groupEvaluationMeasureResultElement : aggregateValues.getChildren()) { String name = groupEvaluationMeasureResultElement.getName(); GroupEvaluationMeasure groupEvaluationMeasure = GroupEvaluationMeasuresFactory.getInstance() .getClassByName(name); if (groupEvaluationMeasure == null) { throw new IllegalStateException( "The group evaluation measure '" + name + "' does not exists in delfos' factory"); } else { groupEvaluationMeasures.put(groupEvaluationMeasure, groupEvaluationMeasure .getGroupEvaluationMeasureResultFromXML(groupEvaluationMeasureResultElement)); } } return groupEvaluationMeasures; }
From source file:delfos.io.xml.casestudy.CaseStudyXML.java
License:Open Source License
static EvaluationMeasuresResults getAggregateEvaluationMeasures(Element element) { if (!element.getName().equals("Aggregate_values")) { throw new IllegalArgumentException("The XML element is not an aggregate values element."); }/* w ww . j a v a 2s. c o m*/ Map<EvaluationMeasure, Double> ret = new TreeMap<>(); long buildTime = -1; long recommendationTime = -1; for (Element child : element.getChildren()) { String evaluationMeasureName = child.getName(); EvaluationMeasure evaluationMeasure = EvaluationMeasuresFactory.getInstance() .getClassByName(evaluationMeasureName); String valueString = child.getAttributeValue("value"); if (valueString == null) { continue; } double measureValue = new Double(valueString); if (evaluationMeasure == null) { throw new IllegalStateException("Evaluation measure cannot be null."); } ret.put(evaluationMeasure, measureValue); } return new EvaluationMeasuresResults(ret, buildTime, recommendationTime); }