List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
From source file:de.smartics.maven.alias.domain.AliasesProcessor.java
License:Apache License
private AliasExtension createExtension(final Element extensionElement) { final AliasExtension.Builder builder = new AliasExtension.Builder(); final Attribute env = extensionElement.getAttribute("env"); if (env != null) { builder.withEnv(env.getValue()); }/*from w ww . ja v a 2s . c om*/ final String name = extensionElement.getChildTextNormalize("name", nsAlias); final String template = extensionElement.getChildTextNormalize("template", nsAlias); final String comment = readComment(extensionElement); final Element commentElement = extensionElement.getChild("comment", nsAlias); if (commentElement != null) { final String mnemonic = commentElement.getAttributeValue("mnemonic"); builder.withMnemonic(mnemonic); } builder.withName(name).withTemplate(template).withComment(comment); appendApplyTos(extensionElement, builder); return builder.build(); }
From source file:de.smartics.maven.alias.domain.AliasesProcessor.java
License:Apache License
private Alias createAlias(final Element aliasElement) { final Alias.Builder builder = new Alias.Builder(); final Attribute env = aliasElement.getAttribute("env"); final Element command = aliasElement.getChild("command", nsAlias); final String normalizedCommandText = command.getTextNormalize(); builder.withName(aliasElement.getChildTextNormalize("name", nsAlias)).withCommand(normalizedCommandText); final String comment = readComment(aliasElement); builder.withComment(comment);/*from w w w . j a v a 2 s . c om*/ if (env != null) { builder.withEnv(env.getValue()); } final Attribute args = command.getAttribute("passArgs"); if (args != null && !Boolean.parseBoolean(args.getValue())) { builder.withPassArgs(false); } return builder.build(); }
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 .j a va 2s.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;// w w w. ja v a 2 s . co m } 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.tasks.ProcessSwapInTask.java
License:Open Source License
/** * Aufruf als Thread ================================================================ *//* w w w . j a v a2 s . c o m*/ @SuppressWarnings("deprecation") @Override public void run() { setStatusProgress(5); String swapPath = null; // ProzessDAO dao = new ProzessDAO(); String processDirectory = ""; if (ConfigurationHelper.getInstance().isUseSwapping()) { swapPath = ConfigurationHelper.getInstance().getSwapPath(); } else { setStatusMessage("swapping not activated"); setStatusProgress(-1); return; } if (swapPath == null || swapPath.length() == 0) { setStatusMessage("no swappingPath defined"); setStatusProgress(-1); return; } Path swapFile = Paths.get(swapPath); if (!StorageProvider.getInstance().isFileExists(swapFile)) { setStatusMessage("Swap folder does not exist or is not mounted"); setStatusProgress(-1); return; } try { processDirectory = getProzess().getProcessDataDirectoryIgnoreSwapping(); // TODO: Don't catch Exception (the super class) } catch (Exception e) { logger.warn("Exception:", e); setStatusMessage( "Error while getting process data folder: " + e.getClass().getName() + " - " + e.getMessage()); setStatusProgress(-1); return; } Path fileIn = Paths.get(processDirectory); Path fileOut = Paths.get(swapPath + getProzess().getId() + FileSystems.getDefault().getSeparator()); if (!StorageProvider.getInstance().isFileExists(fileOut)) { setStatusMessage(getProzess().getTitel() + ": swappingOutTarget does not exist"); setStatusProgress(-1); return; } if (!StorageProvider.getInstance().isFileExists(fileIn)) { setStatusMessage(getProzess().getTitel() + ": process data folder does not exist"); setStatusProgress(-1); return; } SAXBuilder builder = new SAXBuilder(); Document docOld; try { Path swapLogFile = Paths.get(processDirectory, "swapped.xml"); docOld = builder.build(swapLogFile.toFile()); // TODO: Don't catch Exception (the super class) } catch (Exception e) { logger.warn("Exception:", e); setStatusMessage("Error while reading swapped.xml in process data folder: " + e.getClass().getName() + " - " + e.getMessage()); setStatusProgress(-1); return; } /* * --------------------- alte Checksummen in HashMap schreiben ------------------- */ setStatusMessage("reading checksums"); Element rootOld = docOld.getRootElement(); HashMap<String, String> crcMap = new HashMap<String, String>(); // TODO: Don't use Iterators for (Iterator<Element> it = rootOld.getChildren("file").iterator(); it.hasNext();) { Element el = it.next(); crcMap.put(el.getAttribute("path").getValue(), el.getAttribute("crc32").getValue()); } StorageProvider.getInstance().deleteDataInDir(fileIn); /* * --------------------- Dateien kopieren und Checksummen ermitteln ------------------- */ Document doc = new Document(); Element root = new Element("goobiArchive"); doc.setRootElement(root); /* * --------------------- Verzeichnisse und Dateien kopieren und anschliessend den Ordner leeren ------------------- */ setStatusProgress(50); try { setStatusMessage("copying process files"); Helper.copyDirectoryWithCrc32Check(fileOut, fileIn, swapPath.length(), root); } catch (IOException e) { logger.warn("IOException:", e); setStatusMessage("IOException in copyDirectory: " + e.getMessage()); setStatusProgress(-1); return; } setStatusProgress(80); /* * --------------------- Checksummen vergleichen ------------------- */ setStatusMessage("checking checksums"); // TODO: Don't use Iterators for (Iterator<Element> it = root.getChildren("file").iterator(); it.hasNext();) { Element el = it.next(); String newPath = el.getAttribute("path").getValue(); String newCrc = el.getAttribute("crc32").getValue(); if (crcMap.containsKey(newPath)) { if (!crcMap.get(newPath).equals(newCrc)) { setLongMessage(getLongMessage() + "File " + newPath + " has different checksum<br/>"); } crcMap.remove(newPath); } } setStatusProgress(85); /* * --------------------- prfen, ob noch Dateien fehlen ------------------- */ setStatusMessage("checking missing files"); if (crcMap.size() > 0) { for (String myFile : crcMap.keySet()) { setLongMessage(getLongMessage() + "File " + myFile + " is missing<br/>"); } } setStatusProgress(90); /* in Prozess speichern */ StorageProvider.getInstance().deleteDir(fileOut); try { setStatusMessage("saving process"); Process myProzess = ProcessManager.getProcessById(getProzess().getId()); myProzess.setSwappedOutGui(false); ProcessManager.saveProcess(myProzess); } catch (DAOException e) { setStatusMessage("DAOException while saving process: " + e.getMessage()); logger.warn("DAOException:", e); setStatusProgress(-1); return; } setStatusMessage("done"); setStatusProgress(100); }
From source file:de.uniwuerzburg.info3.ofcprobe.vswitch.graphml.GraphmlParser.java
License:Open Source License
/** * Parses Edges// w w w . j av a 2s. co 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:delfos.io.xml.dataset.DatasetLoaderXML.java
License:Open Source License
public static DatasetLoader<? extends Rating> getDatasetLoader(Element datasetLoaderElement) { if (!datasetLoaderElement.getName().equals(ELEMENT_NAME)) { throw new IllegalArgumentException("The element does not contains a dataset loader. [Element name '" + datasetLoaderElement.getName() + "']"); }// w w w .ja v a 2 s. c o m String name = datasetLoaderElement.getAttributeValue(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_NAME); String parameterOwnerType = datasetLoaderElement .getAttributeValue(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_TYPE); if (parameterOwnerType == null) { datasetLoaderElement.setAttribute(ParameterOwnerXML.PARAMETER_OWNER_ATTRIBUTE_TYPE, ParameterOwnerType.DATASET_LOADER.name()); } if (datasetLoaderElement.getAttribute(CONFIGURED_DATASET_ATTRIBUTE) != null && "true".equals(datasetLoaderElement.getAttributeValue(CONFIGURED_DATASET_ATTRIBUTE))) { //Es un dataset configurado, hay que recuperarlo de la factora de dataset configurados. DatasetLoader<? extends Rating> datasetLoader = ConfiguredDatasetsFactory.getInstance() .getDatasetLoader(name); return datasetLoader; } else { //Un dataset de toda la vida. ParameterOwner parameterOwner = ParameterOwnerXML.getParameterOwner(datasetLoaderElement); if (parameterOwner instanceof DatasetLoader) { DatasetLoader<? extends Rating> datasetLoader = (DatasetLoader) parameterOwner; return datasetLoader; } else { IllegalStateException ex = new IllegalStateException( "The XML does not have the expected structure: The loaded parameter owner is not a dataset loader [" + parameterOwner + "]"); ERROR_CODES.CANNOT_LOAD_CONFIG_FILE.exit(ex); throw ex; } } }
From source file:delfos.io.xml.dataset.RelevanceCriteriaXML.java
License:Open Source License
/** * Recupera el criterio de relevancia a partir del elemento XML que contiene * la informacin del mismo./*from w w w . java 2 s . co m*/ * * @param relevanceCriteriaElement Elemento que describe el criterio de * relevancia * * @return Criterio de relevancia descrito por el elemento XML */ public static RelevanceCriteria getRelevanceCriteria(Element relevanceCriteriaElement) { Number threshold = 4; try { threshold = relevanceCriteriaElement.getAttribute(TRESHOLD_ATTRIBUTE).getDoubleValue(); } catch (DataConversionException ex) { Global.showError(ex); } return new RelevanceCriteria(threshold); }
From source file:delfos.io.xml.parameterowner.parameter.BooleanParameterXML.java
License:Open Source License
/** * Asigna el valor del parmetro especificado en el objeto XML al * {@link ParameterOwner} especificado/* w ww. j a va 2s. com*/ * * @param parameterOwner Objeto al que asignar el parmetro * @param parameterElement Elemento que describe el parmetro y su valor * @return Valor del parmetro. Si ha habido algun error, devuelve null */ public static Object getParameterValue(ParameterOwner parameterOwner, Element parameterElement) { if (parameterOwner == null) { throw new IllegalArgumentException("The parameterOwner cannot be null."); } if (parameterElement == null) { throw new IllegalArgumentException("The parameterElement cannot be null."); } String parameterName = parameterElement.getAttributeValue(ParameterXML.PARAMETER_NAME); Parameter parameter = parameterOwner.getParameterByName(parameterName); if (parameter == null) { Global.showWarning(parameterOwner.getName() + " doesn't have the parameter '" + parameterName + "'\n"); } Object value; value = parameterElement.getAttribute(VALUE_ATTRIBUTE).getValue(); parameterOwner.setParameterValue(parameter, value); return value; }
From source file:delfos.io.xml.parameterowner.parameter.DirectoryParameterXML.java
License:Open Source License
/** * Asigna el valor del parmetro especificado en el objeto XML al {@link ParameterOwner} especificado * * @param parameterOwner Objeto al que asignar el parmetro * @param parameterElement Elemento que describe el parmetro y su valor * @return Valor del parmetro. Si ha habido algun error, devuelve null *//*from w w w . j a va2 s . com*/ public static Object getParameterValue(ParameterOwner parameterOwner, Element parameterElement) { String parameterName = parameterElement.getAttributeValue(ParameterXML.PARAMETER_NAME); Parameter parameter = parameterOwner.getParameterByName(parameterName); if (parameter == null) { Global.showWarning(parameterOwner.getName() + " doesn't have the parameter '" + parameterName + "'\n"); } Object value; value = parameterElement.getAttribute(ParameterXML.PARAMETER_VALUE).getValue(); parameterOwner.setParameterValue(parameter, value); return value; }