List of usage examples for org.jdom2 Element getText
public String getText()
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 v a2 s .co 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;/* ww w. j a v a 2 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.tor.tribes.util.report.ReportRule.java
License:Apache License
public ReportRule(Element pElm) throws IllegalArgumentException { try {// www . j a v a 2 s . co m type = RuleType.valueOf(pElm.getChildText("type")); targetSet = pElm.getChildText("targetSet"); Element settings = pElm.getChild("settings"); //check arguments and throw Exception if illigal switch (type) { case AGE: Long maxAge = Long.parseLong(settings.getText()); filterComponent = maxAge; break; case ATTACKER_ALLY: List<Ally> attAllyList = new ArrayList<>(); for (Element e : settings.getChildren("ally")) { int id = Integer.parseInt(e.getText()); attAllyList.add(DataHolder.getSingleton().getAllies().get(id)); } filterComponent = attAllyList; break; case ATTACKER_TRIBE: List<Tribe> attTribeList = new ArrayList<>(); for (Element e : settings.getChildren("tribe")) { int id = Integer.parseInt(e.getText()); attTribeList.add(DataHolder.getSingleton().getTribes().get(id)); } filterComponent = attTribeList; break; case COLOR: Integer color = Integer.parseInt(settings.getText()); filterComponent = color; break; case DATE: String dates[] = settings.getText().split("-"); Long start = Long.parseLong(dates[0]); Long end = Long.parseLong(dates[1]); Range<Long> dateSpan = Range.between(start, end); filterComponent = dateSpan; break; case DEFENDER_ALLY: List<Ally> defAllyList = new ArrayList<>(); for (Element e : settings.getChildren("ally")) { int id = Integer.parseInt(e.getText()); defAllyList.add(DataHolder.getSingleton().getAllies().get(id)); } filterComponent = defAllyList; break; case DEFENDER_TRIBE: List<Tribe> defTribeList = new ArrayList<>(); for (Element e : settings.getChildren("tribe")) { int id = Integer.parseInt(e.getText()); defTribeList.add(DataHolder.getSingleton().getTribes().get(id)); } filterComponent = defTribeList; break; case CATA: case CONQUERED: case FAKE: case FARM: case OFF: case WALL: filterComponent = null; break; } } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:de.unigoettingen.sub.search.opac.ConfigOpacCatalogue.java
License:Open Source License
/** * Beautifier fr ein JDom-Object durchfhren ================================================================ *//*from w w w.j a va2 s .co m*/ private void executeBeautifierForElement(Element el) { String matchedValue = ""; for (ConfigOpacCatalogueBeautifier beautifier : this.beautifySetList) { Element subfieldToChange = null; Element mainFieldToChange = null; /* eine Kopie der zu prfenden Elemente anlegen (damit man darin lschen kann */ ArrayList<ConfigOpacCatalogueBeautifierElement> prooflist = new ArrayList<ConfigOpacCatalogueBeautifierElement>( beautifier.getTagElementsToProof()); /* von jedem Record jedes Field durchlaufen */ List<Element> elements = el.getChildren("field"); boolean foundValue = false; for (Element field : elements) { String tag = field.getAttributeValue("tag"); if (beautifier.getTagElementToChange().getTag().equals(tag)) { mainFieldToChange = field; } /* von jedem Field alle Subfelder durchlaufen */ List<Element> subelements = field.getChildren("subfield"); for (Element subfield : subelements) { String subtag = subfield.getAttributeValue("code"); String value = subfield.getText(); if (beautifier.getTagElementToChange().getTag().equals(tag) && beautifier.getTagElementToChange().getSubtag().equals(subtag)) { subfieldToChange = subfield; } /* * wenn die Werte des Subfeldes in der Liste der zu prfenden Beutifier-Felder stehen, dieses aus der Liste der Beautifier * entfernen */ if (!prooflist.isEmpty()) { for (ConfigOpacCatalogueBeautifierElement cocbe : beautifier.getTagElementsToProof()) { if (cocbe.getValue().equals("*")) { if (cocbe.getTag().equals(tag) && cocbe.getSubtag().equals(subtag)) { if (!foundValue) { matchedValue = value; foundValue = true; } prooflist.remove(cocbe); } } else if (cocbe.getTag().equals(tag) && cocbe.getSubtag().equals(subtag) && value.matches(cocbe.getValue())) { if (!foundValue) { matchedValue = value; } prooflist.remove(cocbe); } } } } } /* * --------------------- wenn in der Kopie der zu prfenden Elemente keine Elemente mehr enthalten sind, kann der zu ndernde Wert * wirklich gendert werden ------------------- */ // check main field if (prooflist.size() == 0 && mainFieldToChange == null) { mainFieldToChange = new Element("field"); mainFieldToChange.setAttribute("tag", beautifier.getTagElementToChange().getTag()); elements.add(mainFieldToChange); } // check subfield if (prooflist.size() == 0 && subfieldToChange == null) { // Element field = new Element("field"); // field.setAttribute("tag", beautifier.getTagElementToChange().getTag()); subfieldToChange = new Element("subfield"); subfieldToChange.setAttribute("code", beautifier.getTagElementToChange().getSubtag()); mainFieldToChange.addContent(subfieldToChange); // elements.add(field); } if (prooflist.size() == 0) { if (beautifier.getTagElementToChange().getValue().equals("*")) { subfieldToChange.setText(matchedValue); } else { subfieldToChange.setText(beautifier.getTagElementToChange().getValue()); } } } }
From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java
License:Open Source License
/** * Parses Nodes//from www .j a v a 2 s . c o 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. j a va 2 s .c o m */ 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:de.weichand.inspire.inspirerome.io.InspireDlsModuleParser.java
License:Apache License
public Module parse(Element element, Locale locale) { final InspireDlsModuleImpl inspireDlsModuleImpl = new InspireDlsModuleImpl(); final SpatialDatasetIdentifier spatialDatasetIdentifier = new SpatialDatasetIdentifier(); Element code = element.getChild("spatial_dataset_identifier_code", NS); Element namespace = element.getChild("spatial_dataset_identifier_namespace", NS); if (code != null && namespace != null) { spatialDatasetIdentifier.setCode(code.getText().trim()); spatialDatasetIdentifier.setNamespace(namespace.getText().trim()); inspireDlsModuleImpl.setSpatialDatasetIdentifier(spatialDatasetIdentifier); return inspireDlsModuleImpl; } else {/*from w w w . jav a 2 s . c om*/ return null; } }
From source file:diuf.diva.dia.ms.script.command.AbstractCommand.java
License:Open Source License
/** * This method return the text contained into the tag. Example <a>hello</a> returns "hello". * Note that this applies also if the element 'e' has children. * * @param e the element from which we want to read * @return the text value contained into the element *//*from w w w . jav a 2 s . c o m*/ public String readElement(Element e) { String result = e.getText(); if (result == null) { throw new Error(tagName() + ": Element " + e.getName() + " has no content."); } return script.preprocess(result); }
From source file:diuf.diva.dia.ms.script.command.Define.java
License:Open Source License
@Override public String execute(Element element) throws Exception { String key = element.getAttributeValue("id"); if (key == null) { error("an id attribute is required"); }/* ww w . j ava 2 s . c o m*/ String val = element.getText(); if (val == null || val.length() == 0) { if (!script.definitions.containsKey(key)) { error(key + " was not defined"); } return ""; } script.definitions.put(key, val); return ""; }
From source file:edd.practica1_201504480.leerxml.java
Lista_Simple datos(File tipo1) { SAXBuilder builder = new SAXBuilder(); try {/*ww w . java 2s . c om*/ //Se obtiene la lista de hijos de la raiz 'tables' Document document = builder.build(tipo1); Element rootNode = document.getRootElement(); // JOptionPane.showMessageDialog(null," e1: "+(rootNode.getChildText("dimension"))); tam = Integer.parseInt(rootNode.getChildText("dimension")); Element dobles = rootNode.getChild("dobles"); List list = dobles.getChildren("casilla"); for (int i = 0; i < list.size(); i++) { Element tabla = (Element) list.get(i); d1.enlistar(tabla.getChildTextTrim("x")); d1.enlistar(tabla.getChildTextTrim("y")); // JOptionPane.showMessageDialog(null,""+tabla.getChildTextTrim("x").toString()); // JOptionPane.showMessageDialog(null,""+tabla.getChildTextTrim("y").toString()); } Element triples = rootNode.getChild("triples"); List listt = triples.getChildren("casilla"); for (int i = 0; i < listt.size(); i++) { Element tabla = (Element) listt.get(i); d2.enlistar(tabla.getChildTextTrim("x")); d2.enlistar(tabla.getChildTextTrim("y")); // JOptionPane.showMessageDialog(null,""+tabla.getChildTextTrim("x").toString()); // JOptionPane.showMessageDialog(null,""+tabla.getChildTextTrim("y").toString()); } Element dicc = rootNode.getChild("diccionario"); List dic = dicc.getChildren(); for (int i = 0; i < dic.size(); i++) { Element tabla = (Element) dic.get(i); //JOptionPane.showMessageDialog(null,""+tabla.getText().toString()); d.enlistar(tabla.getText().toString()); } } catch (JDOMException | IOException | NumberFormatException | HeadlessException e) { JOptionPane.showMessageDialog(null, " error de archivo"); } return d; }