List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:de.sub.goobi.helper.HelperSchritte.java
License:Open Source License
public static void extractAuthorityMetadata(Path metadataFile, Map<String, List<String>> metadataPairs) { XPathFactory xFactory = XPathFactory.instance(); XPathExpression<Element> authorityMetaXpath = xFactory.compile( "//mets:xmlData/mods:mods/mods:extension/goobi:goobi/goobi:metadata[goobi:authorityValue]", Filters.element(), null, mods, mets, goobiNamespace); SAXBuilder builder = new SAXBuilder(); Document doc;/*from www . jav a 2 s.c o m*/ try { doc = builder.build(metadataFile.toString()); } catch (JDOMException | IOException e1) { return; } for (Element meta : authorityMetaXpath.evaluate(doc)) { String name = meta.getAttributeValue("name"); if (name == null) { continue; } else { String key = name + "_authority"; List<String> values = metadataPairs.get(key); if (values == null) { values = new ArrayList<>(); metadataPairs.put(key, values); } values.add(meta.getChildText("authorityValue", goobiNamespace)); } } }
From source file:de.sub.goobi.helper.HelperSchritte.java
License:Open Source License
public static void extractMetadata(Path metadataFile, Map<String, List<String>> metadataPairs) { SAXBuilder builder = new SAXBuilder(); Document doc;// w w w.j a v a2 s . c o m try { doc = builder.build(metadataFile.toString()); } catch (JDOMException | IOException e1) { return; } Element root = doc.getRootElement(); try { Element goobi = root.getChildren("dmdSec", mets).get(0).getChild("mdWrap", mets) .getChild("xmlData", mets).getChild("mods", mods).getChild("extension", mods) .getChild("goobi", goobiNamespace); List<Element> metadataList = goobi.getChildren(); addMetadata(metadataList, metadataPairs); for (Element el : root.getChildren("dmdSec", mets)) { if (el.getAttributeValue("ID").equals("DMDPHYS_0000")) { Element phys = el.getChild("mdWrap", mets).getChild("xmlData", mets).getChild("mods", mods) .getChild("extension", mods).getChild("goobi", goobiNamespace); List<Element> physList = phys.getChildren(); addMetadata(physList, metadataPairs); } } // create field for "DocStruct" String docType = root.getChildren("structMap", mets).get(0).getChild("div", mets) .getAttributeValue("TYPE"); metadataPairs.put("DocStruct", Collections.singletonList(docType)); } catch (Exception e) { logger.error(e); logger.error("Cannot extract metadata from " + metadataFile.toString()); } }
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 . co 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.unigoettingen.sub.search.opac.ConfigOpacCatalogue.java
License:Open Source License
/** * Beautifier fr ein JDom-Object durchfhren ================================================================ *//*from w w w .j a v a 2s .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.unirostock.sems.comodi.ChangeFactory.java
License:Open Source License
/** * Gets the subject id of an Element.// w w w. j a va 2 s . c o m * * The subject id if will effectively be the element's <code>id</code> * attribute value. * That means, this node is supposed to have an <code>id</code> attribute. * * @param node * the document node * @return the subject id * @see org.jdom2.Element */ public static String getSubjectId(Element node) { return node.getAttributeValue("id"); }
From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java
License:Open Source License
/** * Constructor//from w w w . j a v a2 s. c om * * @param graphml_filename the GraphML Filenam */ public GraphmlParser(String graphml_filename) { try { Document doc = new SAXBuilder().build(graphml_filename); Element graphml = doc.getRootElement(); this.ns = graphml.getNamespace(); this.graph = graphml.getChild("graph", this.ns); List<Element> list = graphml.getChildren("key", ns); for (Element e : list) { String s = e.getAttributeValue("attr.name"); switch (s) { case "Latitude": latitude_key = e.getAttributeValue("id"); break; case "Country": country_key = e.getAttributeValue("id"); break; case "Internal": internal_key = e.getAttributeValue("id"); break; case "id": if (e.getAttributeValue("for").equals("node")) { id_key = e.getAttributeValue("id"); } break; case "Longitude": longitude_key = e.getAttributeValue("id"); break; case "label": if (e.getAttributeValue("for").equals("node")) { label_key = e.getAttributeValue("id"); } break; case "LinkLabel": linklabel_key = e.getAttributeValue("id"); break; default: break; } } } catch (JDOMException | IOException e) { logger.error("Error in GraphmlParser"); System.exit(-1); } }
From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java
License:Open Source License
/** * finds Element in List by Key//from w ww .j av a2s. co m * * @param list the List * @param key the Key * @return the Element */ private Element findElementById(List<Element> list, String key) { for (Element e : list) { if (e.getAttributeValue("key").equals(key)) { return e; } } return null; }
From source file:delfos.configuration.ConfigurationScope.java
License:Open Source License
public String getProperty(String propertyName) { loadConfigurationScope();/*w w w . jav a 2s . co m*/ List<String> path = new ArrayList<>(Arrays.asList(propertyName.split("\\."))); Element root = document.getRootElement(); if (root == null) { throw new IllegalStateException("Root element cannot be null"); } Element targetElement = root.getChild(path.remove(0)); for (String node : path) { if (targetElement == null) { break; } targetElement = targetElement.getChild(node); } if (targetElement == null) { return null; } else { return targetElement.getAttributeValue("value"); } }
From source file:delfos.configuration.scopes.ConfiguredDatasetsScope.java
License:Open Source License
private synchronized Collection<ConfiguredDataset> loadConfiguredDatasets() { File fileOfConfiguredDatasets = ConfigurationManager.getConfigurationFile(this); Collection<ConfiguredDataset> configuredDatasets = new ArrayList<>(); if (!fileOfConfiguredDatasets.exists()) { Global.showWarning("The configured datasets file for this machine does not exists-"); Global.showWarning("\tFile '" + fileOfConfiguredDatasets.getAbsolutePath() + "': not found."); Global.showWarning("The configured datasets file for this machine does not exists."); saveConfigurationScope();//from w w w .jav a 2 s. c o m } else { if (Global.isVerboseAnnoying()) { Global.showInfoMessage("Loading configured datasets from file '" + fileOfConfiguredDatasets.getAbsolutePath() + "'\n"); } try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(fileOfConfiguredDatasets); Element rootElement = doc.getRootElement(); if (!rootElement.getName().equals(CONFIGURED_DATASETS_ROOT_ELEMENT_NAME)) { IllegalArgumentException ex = new IllegalArgumentException( "The XML does not contains the configured datasets."); ERROR_CODES.CANNOT_READ_CONFIGURED_DATASETS_FILE.exit(ex); } for (Element configuredDataset : rootElement.getChildren(CONFIGURED_DATASET_ELEMENT_NAME)) { String name = configuredDataset.getAttributeValue(CONFIGURED_DATASET_ELEMENT_NAME_ATTRIBUTE); String description = configuredDataset .getAttributeValue(CONFIGURED_DATASET_ELEMENT_DESCRIPTION_ATTRIBUTE); Element datasetLoaderElement = configuredDataset.getChild(DatasetLoaderXML.ELEMENT_NAME); if (datasetLoaderElement == null) { IllegalStateException ex = new IllegalStateException( "Cannot retrieve configured dataset loader '" + name + "'"); ERROR_CODES.CANNOT_READ_CONFIGURED_DATASETS_FILE.exit(ex); } DatasetLoader<? extends Rating> datasetLoader = DatasetLoaderXML .getDatasetLoader(datasetLoaderElement); if (Global.isVerboseAnnoying()) { Global.showInfoMessage("\tConfigured dataset '" + name + "' loaded.\n"); } configuredDatasets.add(new ConfiguredDataset(name, description, datasetLoader)); } if (configuredDatasets.isEmpty()) { Global.showWarning("No configured datasets found, check configuration file."); } } catch (JDOMException | IOException ex) { ERROR_CODES.CANNOT_READ_CONFIGURED_DATASETS_FILE.exit(ex); } } return configuredDatasets; }
From source file:delfos.group.grs.consensus.ConsensusOfIndividualRecommendationsToXML.java
License:Open Source License
public static ConsensusOutputModel readConsensusOutputXML(File consensusIntputXML) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(consensusIntputXML); Element root = doc.getRootElement(); if (!root.getName().equals(CONSENSUS_OUTPUT_ROOT_NAME)) { throw new IllegalArgumentException( "The XML does not contains a Case Study (" + consensusIntputXML.getAbsolutePath() + ")"); }//from www. j ava 2 s .c o m Element consensus = root.getChild(CONSENSUS_OUTPUT_CONSENSUS_ELEMENT_NAME); int round = Integer.parseInt(consensus.getAttributeValue(CONSENSUS_OUTPUT_CONSENSUS_ATTRIBUTE_ROUND)); double consensusDegree = Double .parseDouble(consensus.getAttributeValue(CONSENSUS_OUTPUT_CONSENSUS_ATTRIBUTE_CONSENSUS_DEGREE)); Collection<Recommendation> consensusRecommendations = new ArrayList<>(); for (Element alternative : consensus.getChildren(CONSENSUS_OUTPUT_ALTERNATVE_ELEMENT_NAME)) { int idItem = Integer .parseInt(alternative.getAttributeValue(CONSENSUS_OUTPUT_ALTERNATVE_ATTRIBUTE_ID_ITEM)); double rank = Double .parseDouble(alternative.getAttributeValue(CONSENSUS_OUTPUT_ALTERNATVE_ATTRIBUTE_RANK)); double preference = 1 / rank; consensusRecommendations.add(new Recommendation(idItem, preference)); } return new ConsensusOutputModel(consensusDegree, round, consensusRecommendations); }