List of usage examples for org.jdom2 Document Document
public Document(List<? extends Content> content)
Document
, with the supplied list of content, and a DocType
declaration only if the content contains a DocType instance. From source file:org.esa.snap.engine_utilities.datamodel.metadata.AbstractMetadataIO.java
License:Open Source License
public static void Save(final Product product, final MetadataElement metadataElem, final File metadataFile) throws IOException { final Element root = new Element("Metadata"); final Document doc = new Document(root); if (metadataElem != null) { final Element AbstractedMetadataElem = new Element(AbstractMetadata.ABSTRACT_METADATA_ROOT); root.addContent(AbstractedMetadataElem); XMLSupport.metadataElementToDOMElement(metadataElem, AbstractedMetadataElem); }/*from ww w . ja v a2 s . c o m*/ if (product.getTiePointGrids().length > 0) { final Element tiePointGridsElem = new Element(TPG); root.addContent(tiePointGridsElem); writeTiePointGrids(product, tiePointGridsElem); } XMLSupport.SaveXML(doc, metadataFile.getAbsoluteFile().toString()); }
From source file:org.esa.snap.framework.dataop.downloadable.ftpUtils.java
License:Open Source License
private static void writeRemoteFileList(final FTPFile[] remoteFileList, final String server, final String remotePath, final File file) { final Element root = new Element("remoteFileListing"); root.setAttribute("server", server); final Document doc = new Document(root); final Element remotePathElem = new Element("remotePath"); remotePathElem.setAttribute("path", remotePath); root.addContent(remotePathElem);// w w w. ja v a2 s . c o m for (FTPFile ftpFile : remoteFileList) { final Element fileElem = new Element(ftpFile.getName()); fileElem.setAttribute("size", String.valueOf(ftpFile.getSize())); remotePathElem.addContent(fileElem); } XMLSupport.SaveXML(doc, file.getAbsolutePath()); }
From source file:org.esa.snap.productlibrary.rcp.toolviews.AOIMonitoring.model.AOI.java
License:Open Source License
public void save() { final Element root = new Element("AOI"); root.setAttribute("name", name); final Document doc = new Document(root); final Element elem = new Element("param"); elem.setAttribute("inputFolder", inputFolder); elem.setAttribute("outputFolder", outputFolder); elem.setAttribute("graph", processingGraph); elem.setAttribute("lastProcessed", lastProcessed); elem.setAttribute("findSlaves", String.valueOf(findSlaves)); elem.setAttribute("maxSlaves", String.valueOf(maxSlaves)); root.addContent(elem);//from www . j a v a 2s .c o m final Element pntsElem = new Element("points"); for (GeoPos pnt : aoiPoints) { final Element pntElem = new Element("point"); pntElem.setAttribute("lat", String.valueOf(pnt.getLat())); pntElem.setAttribute("lon", String.valueOf(pnt.getLon())); pntsElem.addContent(pntElem); } root.addContent(pntsElem); if (slaveDBQuery != null) { //todo root.addContent(slaveDBQuery.toXML()); } try { XMLSupport.SaveXML(doc, aoiFile.getAbsolutePath()); } catch (IOException e) { SystemUtils.LOG.severe("Unable to save AOI " + e.getMessage()); } }
From source file:org.fiware.cybercaptor.server.remediation.cost.GlobalParameters.java
License:Open Source License
/** * Function used to save the parameters in an xml file * * @param path the path where the xml file should be created * @throws Exception/*from w w w . j a va2 s . c om*/ */ public void saveToXMLFile(String path) throws Exception { Document document = new Document(toDomElement()); //Save the DOM element in file XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); output.output(document, new FileOutputStream(path)); }
From source file:org.fiware.cybercaptor.server.remediation.cost.OperationalCostParameters.java
License:Open Source License
/** * Function used to save the parameters in an xml file * * @param path the path where the xml file should be created * @throws Exception the exception// ww w . j a v a 2s . com */ public void saveToXMLFile(String path) throws Exception { Document document = new Document(toDomElement()); //Save the DOM element in file XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); output.output(document, new FileOutputStream(path)); }
From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
/** * This method creates a new xml document with process metadata * /*from ww w . ja va 2 s.c o m*/ * @param process the process to export * @return a new xml document * @throws ConfigurationException */ public Document createDocument(Process process, boolean addNamespace) { Element processElm = new Element("process"); Document doc = new Document(processElm); processElm.setAttribute("processID", String.valueOf(process.getId())); Namespace xmlns = Namespace.getNamespace("http://www.goobi.io/logfile"); processElm.setNamespace(xmlns); // namespace declaration if (addNamespace) { Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); processElm.addNamespaceDeclaration(xsi); Attribute attSchema = new Attribute("schemaLocation", "http://www.goobi.io/logfile" + " XML-logfile.xsd", xsi); processElm.setAttribute(attSchema); } // process information ArrayList<Element> processElements = new ArrayList<>(); Element processTitle = new Element("title", xmlns); processTitle.setText(process.getTitel()); processElements.add(processTitle); Element project = new Element("project", xmlns); project.setText(process.getProjekt().getTitel()); processElements.add(project); Element date = new Element("time", xmlns); date.setAttribute("type", "creation date"); date.setText(String.valueOf(process.getErstellungsdatum())); processElements.add(date); Element ruleset = new Element("ruleset", xmlns); ruleset.setText(process.getRegelsatz().getDatei()); processElements.add(ruleset); Element comment = new Element("comments", xmlns); List<LogEntry> log = process.getProcessLog(); for (LogEntry entry : log) { Element commentLine = new Element("comment", xmlns); commentLine.setAttribute("type", entry.getType().getTitle()); commentLine.setAttribute("user", entry.getUserName()); commentLine.setText(entry.getContent()); if (StringUtils.isNotBlank(entry.getSecondContent())) { comment.setAttribute("secondField", entry.getSecondContent()); } if (StringUtils.isNotBlank(entry.getThirdContent())) { comment.setAttribute("thirdField", entry.getThirdContent()); } comment.addContent(commentLine); } processElements.add(comment); if (process.getBatch() != null) { Element batch = new Element("batch", xmlns); batch.setText(String.valueOf(process.getBatch().getBatchId())); if (StringUtils.isNotBlank(process.getBatch().getBatchName())) { batch.setAttribute("batchName", process.getBatch().getBatchName()); } if (process.getBatch().getStartDate() != null) { batch.setAttribute("startDate", Helper.getDateAsFormattedString(process.getBatch().getStartDate())); } if (process.getBatch().getEndDate() != null) { batch.setAttribute("endDate", Helper.getDateAsFormattedString(process.getBatch().getEndDate())); } processElements.add(batch); } List<Element> processProperties = new ArrayList<>(); List<ProcessProperty> propertyList = PropertyParser.getInstance().getPropertiesForProcess(process); for (ProcessProperty prop : propertyList) { Element property = new Element("property", xmlns); property.setAttribute("propertyIdentifier", prop.getName()); if (prop.getValue() != null) { property.setAttribute("value", prop.getValue()); } else { property.setAttribute("value", ""); } Element label = new Element("label", xmlns); label.setText(prop.getName()); property.addContent(label); processProperties.add(property); } if (processProperties.size() != 0) { Element properties = new Element("properties", xmlns); properties.addContent(processProperties); processElements.add(properties); } // step information Element steps = new Element("steps", xmlns); List<Element> stepElements = new ArrayList<>(); for (Step s : process.getSchritteList()) { Element stepElement = new Element("step", xmlns); stepElement.setAttribute("stepID", String.valueOf(s.getId())); Element steptitle = new Element("title", xmlns); steptitle.setText(s.getTitel()); stepElement.addContent(steptitle); Element state = new Element("processingstatus", xmlns); state.setText(s.getBearbeitungsstatusAsString()); stepElement.addContent(state); Element begin = new Element("time", xmlns); begin.setAttribute("type", "start time"); begin.setText(s.getBearbeitungsbeginnAsFormattedString()); stepElement.addContent(begin); Element end = new Element("time", xmlns); end.setAttribute("type", "end time"); end.setText(s.getBearbeitungsendeAsFormattedString()); stepElement.addContent(end); if (s.getBearbeitungsbenutzer() != null && s.getBearbeitungsbenutzer().getNachVorname() != null) { Element user = new Element("user", xmlns); user.setText(s.getBearbeitungsbenutzer().getNachVorname()); stepElement.addContent(user); } Element editType = new Element("edittype", xmlns); editType.setText(s.getEditTypeEnum().getTitle()); stepElement.addContent(editType); stepElements.add(stepElement); } if (stepElements != null) { steps.addContent(stepElements); processElements.add(steps); } // template information Element templates = new Element("originals", xmlns); List<Element> templateElements = new ArrayList<>(); for (Template v : process.getVorlagenList()) { Element template = new Element("original", xmlns); template.setAttribute("originalID", String.valueOf(v.getId())); List<Element> templateProperties = new ArrayList<>(); for (Templateproperty prop : v.getEigenschaftenList()) { Element property = new Element("property", xmlns); property.setAttribute("propertyIdentifier", prop.getTitel()); if (prop.getWert() != null) { property.setAttribute("value", prop.getWert()); } else { property.setAttribute("value", ""); } Element label = new Element("label", xmlns); label.setText(prop.getTitel()); property.addContent(label); templateProperties.add(property); if (prop.getTitel().equals("Signatur")) { Element secondProperty = new Element("property", xmlns); secondProperty.setAttribute("propertyIdentifier", prop.getTitel() + "Encoded"); if (prop.getWert() != null) { secondProperty.setAttribute("value", "vorl:" + prop.getWert()); Element secondLabel = new Element("label", xmlns); secondLabel.setText(prop.getTitel()); secondProperty.addContent(secondLabel); templateProperties.add(secondProperty); } } } if (templateProperties.size() != 0) { Element properties = new Element("properties", xmlns); properties.addContent(templateProperties); template.addContent(properties); } templateElements.add(template); } if (templateElements != null) { templates.addContent(templateElements); processElements.add(templates); } // digital document information Element digdoc = new Element("digitalDocuments", xmlns); List<Element> docElements = new ArrayList<>(); for (Masterpiece w : process.getWerkstueckeList()) { Element dd = new Element("digitalDocument", xmlns); dd.setAttribute("digitalDocumentID", String.valueOf(w.getId())); List<Element> docProperties = new ArrayList<>(); for (Masterpieceproperty prop : w.getEigenschaftenList()) { Element property = new Element("property", xmlns); property.setAttribute("propertyIdentifier", prop.getTitel()); if (prop.getWert() != null) { property.setAttribute("value", prop.getWert()); } else { property.setAttribute("value", ""); } Element label = new Element("label", xmlns); label.setText(prop.getTitel()); property.addContent(label); docProperties.add(property); } if (docProperties.size() != 0) { Element properties = new Element("properties", xmlns); properties.addContent(docProperties); dd.addContent(properties); } docElements.add(dd); } if (docElements != null) { digdoc.addContent(docElements); processElements.add(digdoc); } // history List<HistoryEvent> eventList = HistoryManager.getHistoryEvents(process.getId()); if (eventList != null && !eventList.isEmpty()) { List<Element> eventElementList = new ArrayList<>(eventList.size()); for (HistoryEvent event : eventList) { Element element = new Element("historyEvent", xmlns); element.setAttribute("id", "" + event.getId()); element.setAttribute("date", Helper.getDateAsFormattedString(event.getDate())); element.setAttribute("type", event.getHistoryType().getTitle()); if (event.getNumericValue() != null) { element.setAttribute("numeric_value", "" + event.getNumericValue()); } if (event.getStringValue() != null) { element.setText(event.getStringValue()); } eventElementList.add(element); } if (!eventElementList.isEmpty()) { Element metadataElement = new Element("history", xmlns); metadataElement.addContent(eventElementList); processElements.add(metadataElement); } } // metadata List<StringPair> metadata = MetadataManager.getMetadata(process.getId()); if (metadata != null && !metadata.isEmpty()) { List<Element> mdlist = new ArrayList<>(); for (StringPair md : metadata) { String name = md.getOne(); String value = md.getTwo(); if (StringUtils.isNotBlank(value) && StringUtils.isNotBlank(name)) { Element element = new Element("metadata", xmlns); element.setAttribute("name", name); element.addContent(value); mdlist.add(element); } } if (!mdlist.isEmpty()) { Element metadataElement = new Element("metadatalist", xmlns); metadataElement.addContent(mdlist); processElements.add(metadataElement); } } // METS information Element metsElement = new Element("metsInformation", xmlns); List<Element> metadataElements = new ArrayList<>(); try { String filename = process.getMetadataFilePath(); Document metsDoc = new SAXBuilder().build(filename); Document anchorDoc = null; String anchorfilename = process.getMetadataFilePath().replace("meta.xml", "meta_anchor.xml"); Path anchorFile = Paths.get(anchorfilename); if (StorageProvider.getInstance().isFileExists(anchorFile) && StorageProvider.getInstance().isReadable(anchorFile)) { anchorDoc = new SAXBuilder().build(anchorfilename); } List<Namespace> namespaces = getNamespacesFromConfig(); HashMap<String, String> fields = getMetsFieldsFromConfig(false); for (String key : fields.keySet()) { List<Element> metsValues = getMetsValues(fields.get(key), metsDoc, namespaces); for (Element element : metsValues) { Element ele = new Element("property", xmlns); ele.setAttribute("name", key); ele.addContent(element.getTextTrim()); metadataElements.add(ele); } } if (anchorDoc != null) { fields = getMetsFieldsFromConfig(true); for (String key : fields.keySet()) { List<Element> metsValues = getMetsValues(fields.get(key), anchorDoc, namespaces); for (Element element : metsValues) { Element ele = new Element("property", xmlns); ele.setAttribute("name", key); ele.addContent(element.getTextTrim()); metadataElements.add(ele); } } } if (metadataElements != null) { metsElement.addContent(metadataElements); processElements.add(metsElement); } } catch (SwapException e) { logger.error(e); } catch (DAOException e) { logger.error(e); } catch (IOException e) { logger.error(e); } catch (InterruptedException e) { logger.error(e); } catch (JDOMException e) { logger.error(e); } catch (JaxenException e) { logger.error(e); } processElm.setContent(processElements); return doc; }
From source file:org.goobi.production.export.ExportXmlLog.java
License:Open Source License
/** * Creates a new xml document containing all relevant process data. It can be used to import the process into another system. * /* w w w .j av a 2 s. c om*/ * @param process the process to export * @return a new xml document * @throws ConfigurationException */ public Document createExtendedDocument(Process process) { Element rootElement = new Element("process", xmlns); Document doc = new Document(rootElement); getProcessData(process, rootElement); // prozesse.batchID if (process.getBatch() != null) { rootElement.addContent(getBatchData(process)); } // prozesse.docketID if (process.getDocket() != null) { rootElement.addContent(getDocketData(process)); // getDocketData(process, rootElement); } // ProjekteID rootElement.addContent(getProjectData(process)); // process log if (process.getProcessLog() != null && !process.getProcessLog().isEmpty()) { rootElement.addContent(getProcessLogData(process)); } // process properties if (!process.getEigenschaften().isEmpty()) { rootElement.addContent(getProcessPropertyData(process)); } // template properties if (!process.getVorlagenList().isEmpty()) { rootElement.addContent(getTemplatePropertyData(process)); } // workpiece properties if (!process.getWerkstueckeList().isEmpty()) { rootElement.addContent(getWorkpiecePropertyData(process)); } // tasks Element tasks = new Element("tasks", xmlns); rootElement.addContent(tasks); for (Step step : process.getSchritte()) { tasks.addContent(getTaskData(step)); } return doc; }
From source file:org.graphwalker.StatisticsManager.java
License:Open Source License
/** * //from w w w . j a v a 2s . com */ public StatisticsManager() { this.counters = new Hashtable<String, Statistics>(); this.progress = new Document(new Element("Statistics")); }
From source file:org.graphwalker.StatisticsManager.java
License:Open Source License
public Document getCurrentStatistic() { Element root = new Element("Statistic"); Document doc = new Document(root); for (Enumeration<String> e = counters.keys(); e.hasMoreElements();) { String key = e.nextElement(); int[] stats = getStatistic(key); Element child = new Element("Data"); child.setAttribute("type", key); child.setAttribute("value", "" + stats[0]); child.setAttribute("max", "" + stats[1]); root.addContent(child);/* ww w . jav a2 s .c o m*/ } return doc; }
From source file:org.helm.notation2.tools.xHelmNotationExporter.java
License:Open Source License
/** * method to get xhelm for the helm2 notation with the new functionality * * @param helm2notation, HELM2Notation object * @return xhelm//w w w. j a v a 2 s . com * @throws MonomerException * @throws JDOMException * @throws IOException * @throws ChemistryException */ public static String getXHELM2(HELM2Notation helm2notation) throws MonomerException, IOException, JDOMException, ChemistryException { set = new HashSet<Monomer>(); Element root = new Element(xHelmNotationExporter.XHELM_ELEMENT); Document doc = new Document(root); Element helmElement = new Element(xHelmNotationExporter.HELM_NOTATION_ELEMENT); helmElement.setText(helm2notation.toHELM2()); root.addContent(helmElement); Element monomerListElement = new Element(xHelmNotationExporter.MONOMER_LIST_ELEMENT); /* save all adhocMonomers */ for (MonomerNotation monomernotation : MethodsMonomerUtils .getListOfMonomerNotation(helm2notation.getListOfPolymers())) { /* get all elements of an rna */ if (monomernotation instanceof MonomerNotationUnitRNA) { for (MonomerNotationUnit unit : ((MonomerNotationUnitRNA) monomernotation).getContents()) { addAdHocMonomer(unit); } } else { addAdHocMonomer(monomernotation); } } /* give the adhocMonomer's information */ for (Monomer distinctmonomer : set) { Element monomerElement = MonomerParser.getMonomerElement(distinctmonomer); monomerListElement.getChildren().add(monomerElement); } root.addContent(monomerListElement); XMLOutputter xmlOutput = new XMLOutputter(); // display nice xmlOutput.setFormat(Format.getPrettyFormat()); return xmlOutput.outputString(doc); }