List of usage examples for org.jdom2.output Format getPrettyFormat
public static Format getPrettyFormat()
From source file:org.roda.core.common.MetadataFileUtils.java
public static ContentPayload getMetadataPayload(TransferredResource transferredResource) { try {//from w w w. j a v a2s .c o m Element root = new Element("metadata"); org.jdom2.Document doc = new org.jdom2.Document(); Element child = new Element("field"); child.setAttribute("name", "title"); child.addContent(transferredResource.getName()); root.addContent(child); doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.outputString(doc); return new StringContentPayload(outter.outputString(doc)); } catch (IllegalDataException e) { LOGGER.debug("Error generating TransferredResource metadata file {}", e.getMessage()); return new StringContentPayload(""); } }
From source file:org.roda.core.plugins.plugins.characterization.TikaFullTextPluginUtils.java
private static String generateMetadataFile(Metadata metadata) throws IOException { try {//from ww w . j a v a2s .co m String[] names = metadata.names(); Element root = new Element("metadata"); org.jdom2.Document doc = new org.jdom2.Document(); for (String name : names) { String[] values = metadata.getValues(name); if (values != null && values.length > 0) { for (String value : values) { Element child = new Element("field"); child.setAttribute("name", MetadataFileUtils.escapeAttribute(name)); child.addContent(MetadataFileUtils.escapeContent(value)); root.addContent(child); } } } doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); outter.outputString(doc); return outter.outputString(doc); } catch (IllegalDataException e) { LOGGER.debug("Error generating Tika metadata file {}", e.getMessage()); return ""; } }
From source file:org.roda_project.commons_ip.model.impl.bagit.BagitUtils.java
public static String generateMetadataFile(Path metadataPath) throws IllegalDataException { Map<String, String> bagInfo = getBagitInfo(metadataPath); Element root = new Element(IPConstants.BAGIT_METADATA); org.jdom2.Document doc = new org.jdom2.Document(); for (Map.Entry<String, String> entry : bagInfo.entrySet()) { if (!IPConstants.BAGIT_PARENT.equalsIgnoreCase(entry.getKey())) { Element child = new Element(IPConstants.BAGIT_FIELD); child.setAttribute(IPConstants.BAGIT_NAME, XmlEscapers.xmlAttributeEscaper().escape(entry.getKey())); child.addContent(entry.getValue()); root.addContent(child);//from w w w .j av a 2 s . c o m } } doc.setRootElement(root); XMLOutputter outter = new XMLOutputter(); outter.setFormat(Format.getPrettyFormat()); return outter.outputString(doc); }
From source file:org.shaman.rpg.editor.project.elements.JdomElements.java
public synchronized void save() { root.update();// w w w . j ava2 s.c o m XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); try (OutputStream stream = file.getOutputStream()) { out.output(doc, stream); } catch (FileAlreadyLockedException ex) { Exceptions.printStackTrace(ex); return; } catch (IOException ex) { Exceptions.printStackTrace(ex); return; } //debug LOG.fine("elements saved"); // try { // for (String line : file.asLines()) { // System.out.println(line); // } // } catch (IOException ex) { // Exceptions.printStackTrace(ex); // } }
From source file:org.shaman.rpg.editor.project.impl.ModuleBuildFileGenerator.java
public void writeBuildFile(FileObject file) { Document doc = generateDoc(); try (OutputStream out = file.getOutputStream();) { XMLOutputter o = new XMLOutputter(Format.getPrettyFormat()); o.output(doc, out);// w w w.j av a2s . co m } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
From source file:org.sleuthkit.autopsy.report.ReportKML.java
License:Open Source License
/** * Generates a body file format report for use with the MAC time tool. * * @param path path to save the report//from w w w .j a v a 2 s.c om * @param progressPanel panel to update the report's progress */ @Override public void generateReport(String path, ReportProgressPanel progressPanel) { // Start the progress bar and setup the report progressPanel.setIndeterminate(false); progressPanel.start(); progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportKML.progress.querying")); reportPath = path + "ReportKML.kml"; //NON-NLS String reportPath2 = path + "ReportKML.txt"; //NON-NLS currentCase = Case.getCurrentCase(); skCase = currentCase.getSleuthkitCase(); progressPanel.updateStatusLabel(NbBundle.getMessage(this.getClass(), "ReportKML.progress.loading")); // Check if ingest has finished String ingestwarning = ""; if (IngestManager.getInstance().isIngestRunning()) { ingestwarning = NbBundle.getMessage(this.getClass(), "ReportBodyFile.ingestWarning.text"); } progressPanel.setMaximumProgress(5); progressPanel.increment(); // @@@ BC: I don't get why we do this in two passes. // Why not just print the coordinates as we find them and make some utility methods to do the printing? // Should pull out time values for all of these points and store in TimeSpan element try { BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(reportPath2)); double lat = 0; // temp latitude double lon = 0; //temp longitude AbstractFile aFile; String geoPath = ""; // will hold values of images to put in kml String imageName = ""; File f; for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_METADATA_EXIF)) { lat = 0; lon = 0; geoPath = ""; String extractedToPath; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE .getTypeID()) //latitude { lat = attribute.getValueDouble(); } if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE .getTypeID()) //longitude { lon = attribute.getValueDouble(); } } if (lon != 0 && lat != 0) { aFile = artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID()); extractedToPath = reportPath + aFile.getName(); geoPath = extractedToPath; f = new File(extractedToPath); f.createNewFile(); copyFileUsingStream(aFile, f); imageName = aFile.getName(); out.write(String.valueOf(lat)); out.write(";"); out.write(String.valueOf(lon)); out.write(";"); out.write(String.valueOf(geoPath)); out.write(";"); out.write(String.valueOf(imageName)); out.write("\n"); // lat lon path name } } for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT)) { lat = 0; lon = 0; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE .getTypeID()) //latitude { lat = attribute.getValueDouble(); } if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE .getTypeID()) //longitude { lon = attribute.getValueDouble(); } } if (lon != 0 && lat != 0) { out.write(lat + ";" + lon + "\n"); } } for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE)) { lat = 0; lon = 0; double destlat = 0; double destlon = 0; String name = ""; String location = ""; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START .getTypeID()) //latitude { lat = attribute.getValueDouble(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_END .getTypeID()) //longitude { destlat = attribute.getValueDouble(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_START .getTypeID()) //longitude { lon = attribute.getValueDouble(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_END .getTypeID()) //longitude { destlon = attribute.getValueDouble(); } else if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME .getTypeID()) //longitude { name = attribute.getValueString(); } else if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION .getTypeID()) //longitude { location = attribute.getValueString(); } } // @@@ Should do something more fancy with these in KML and store them as a single point. String display = name; if (display.isEmpty()) display = location; if (lon != 0 && lat != 0) { out.write(NbBundle.getMessage(this.getClass(), "ReportKML.latLongStartPoint", lat, lon, display)); } if (destlat != 0 && destlon != 0) { out.write(NbBundle.getMessage(this.getClass(), "ReportKML.latLongEndPoint", destlat, destlon, display)); } } out.flush(); out.close(); progressPanel.increment(); /* * Step 1: generate XML stub */ Namespace ns = Namespace.getNamespace("", "http://earth.google.com/kml/2.2"); //NON-NLS // kml Element kml = new Element("kml", ns); //NON-NLS Document kmlDocument = new Document(kml); // Document Element document = new Element("Document", ns); //NON-NLS kml.addContent(document); // name Element name = new Element("name", ns); //NON-NLS name.setText("Java Generated KML Document"); //NON-NLS document.addContent(name); /* * Step 2: add in Style elements */ // Style Element style = new Element("Style", ns); //NON-NLS style.setAttribute("id", "redIcon"); //NON-NLS document.addContent(style); // IconStyle Element iconStyle = new Element("IconStyle", ns); //NON-NLS style.addContent(iconStyle); // color Element color = new Element("color", ns); //NON-NLS color.setText("990000ff"); //NON-NLS iconStyle.addContent(color); // Icon Element icon = new Element("Icon", ns); //NON-NLS iconStyle.addContent(icon); // href Element href = new Element("href", ns); //NON-NLS href.setText("http://www.cs.mun.ca/~hoeber/teaching/cs4767/notes/02.1-kml/circle.png"); //NON-NLS icon.addContent(href); progressPanel.increment(); /* * Step 3: read data from source location and * add in a Placemark for each data element */ File file = new File(reportPath2); BufferedReader reader; reader = new BufferedReader(new FileReader(file)); String line = reader.readLine(); while (line != null) { String[] lineParts = line.split(";"); if (lineParts.length > 1) { String coordinates = lineParts[1].trim() + "," + lineParts[0].trim(); //lat,lon // Placemark Element placemark = new Element("Placemark", ns); //NON-NLS document.addContent(placemark); if (lineParts.length == 4) { // name Element pmName = new Element("name", ns); //NON-NLS pmName.setText(lineParts[3].trim()); placemark.addContent(pmName); String savedPath = lineParts[2].trim(); if (savedPath.isEmpty() == false) { // Path Element pmPath = new Element("Path", ns); //NON-NLS pmPath.setText(savedPath); placemark.addContent(pmPath); // description Element pmDescription = new Element("description", ns); //NON-NLS String xml = "<![CDATA[ \n" + " <img src='file:///" + savedPath + "' width='400' /><br/> \n"; //NON-NLS StringEscapeUtils.unescapeXml(xml); pmDescription.setText(xml); placemark.addContent(pmDescription); } } // styleUrl Element pmStyleUrl = new Element("styleUrl", ns); //NON-NLS pmStyleUrl.setText("#redIcon"); //NON-NLS placemark.addContent(pmStyleUrl); // Point Element pmPoint = new Element("Point", ns); //NON-NLS placemark.addContent(pmPoint); // coordinates Element pmCoordinates = new Element("coordinates", ns); //NON-NLS pmCoordinates.setText(coordinates); pmPoint.addContent(pmCoordinates); } // read the next line line = reader.readLine(); } progressPanel.increment(); /* * Step 4: write the XML file */ try { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); FileOutputStream writer = new FileOutputStream(reportPath); outputter.output(kmlDocument, writer); writer.close(); Case.getCurrentCase().addReport(reportPath, NbBundle.getMessage(this.getClass(), "ReportKML.genReport.srcModuleName.text"), ""); } catch (IOException ex) { logger.log(Level.WARNING, "Could not write the KML file.", ex); //NON-NLS } catch (TskCoreException ex) { String errorMessage = String.format("Error adding %s to case as a report", reportPath); //NON-NLS logger.log(Level.SEVERE, errorMessage, ex); } } catch (IOException ex) { logger.log(Level.WARNING, "Could not write the KML report.", ex); //NON-NLS } progressPanel.complete(); } catch (TskCoreException ex) { logger.log(Level.WARNING, "Failed to get the unique path.", ex); //NON-NLS } progressPanel.increment(); progressPanel.complete(); }
From source file:org.sleuthkit.openmobileforensics.android.KMLFileCreator.java
License:Open Source License
public void CreateKML() { reportPath = Case.getCurrentCase().getTempDirectory() + "ReportKML.kml"; //NON-NLS String reportPath2 = Case.getCurrentCase().getTempDirectory() + "ReportKML.txt"; //NON-NLS currentCase = Case.getCurrentCase(); skCase = currentCase.getSleuthkitCase(); try {// www .ja va 2 s . co m BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(reportPath2)); String lat = ""; // temp latitude String lon = ""; //temp longitude String destlon = ""; String destlat = ""; for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_TRACKPOINT)) { lat = ""; lon = ""; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE .getTypeID()) //latitude { lat = attribute.getValueString(); } if (attribute.getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE .getTypeID()) //longitude { lon = attribute.getValueString(); } } if (!lon.isEmpty() && !lat.isEmpty()) { out.write(lat + ";" + lon + "\n"); } } for (BlackboardArtifact artifact : skCase .getBlackboardArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE)) { lat = ""; lon = ""; for (BlackboardAttribute attribute : artifact.getAttributes()) { if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START .getTypeID()) //latitude { lat = attribute.getValueString(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_END .getTypeID()) //longitude { destlat = attribute.getValueString(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_START .getTypeID()) //longitude { lon = attribute.getValueString(); } else if (attribute .getAttributeTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_END .getTypeID()) //longitude { destlon = attribute.getValueString(); } } if (!lon.isEmpty() && !lat.isEmpty()) { out.write(lat + ";" + lon + "\n"); } if (!destlon.isEmpty() && !destlat.isEmpty()) { out.write(destlat + ";" + destlon + "\n"); } } out.flush(); out.close(); /* * Step 1: generate XML stub */ Namespace ns = Namespace.getNamespace("", "http://earth.google.com/kml/2.2"); //NON-NLS // kml Element kml = new Element("kml", ns); //NON-NLS Document kmlDocument = new Document(kml); // Document Element document = new Element("Document", ns); //NON-NLS kml.addContent(document); // name Element name = new Element("name", ns); //NON-NLS name.setText("Java Generated KML Document"); //NON-NLS document.addContent(name); /* * Step 2: add in Style elements */ // Style Element style = new Element("Style", ns); //NON-NLS style.setAttribute("id", "redIcon"); //NON-NLS document.addContent(style); // IconStyle Element iconStyle = new Element("IconStyle", ns); //NON-NLS style.addContent(iconStyle); // color Element color = new Element("color", ns); //NON-NLS color.setText("990000ff"); //NON-NLS iconStyle.addContent(color); // Icon Element icon = new Element("Icon", ns); //NON-NLS iconStyle.addContent(icon); // href Element href = new Element("href", ns); //NON-NLS href.setText("http://www.cs.mun.ca/~hoeber/teaching/cs4767/notes/02.1-kml/circle.png"); //NON-NLS icon.addContent(href); /* * Step 3: read data from source location and * add in a Placemark for each data element */ File file = new File(reportPath2); BufferedReader reader; reader = new BufferedReader(new FileReader(file)); String line = reader.readLine(); while (line != null) { String[] lineParts = line.split(";"); if (lineParts.length == 2) { String coordinates = lineParts[1].trim() + "," + lineParts[0].trim(); //lat,lon // Placemark Element placemark = new Element("Placemark", ns); //NON-NLS document.addContent(placemark); // styleUrl Element pmStyleUrl = new Element("styleUrl", ns); //NON-NLS pmStyleUrl.setText("#redIcon"); //NON-NLS placemark.addContent(pmStyleUrl); // Point Element pmPoint = new Element("Point", ns); //NON-NLS placemark.addContent(pmPoint); // coordinates Element pmCoordinates = new Element("coordinates", ns); //NON-NLS pmCoordinates.setText(coordinates); pmPoint.addContent(pmCoordinates); } // read the next line line = reader.readLine(); } /* * Step 4: write the XML file */ try { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); FileOutputStream writer = new FileOutputStream(reportPath); outputter.output(kmlDocument, writer); writer.close(); } catch (IOException ex) { } } catch (IOException ex) { } } catch (TskCoreException ex) { } }
From source file:org.t3.metamediamanager.FieldsConfig.java
License:Apache License
public void save() { Element root = new Element("fields"); Document doc = new Document(root); for (Entry<String, String> fieldEntry : _fieldsAssociation.entrySet()) { Element elemField = new Element("field"); elemField.setAttribute("name", fieldEntry.getKey()); elemField.setAttribute("markup", fieldEntry.getValue()); root.addContent(elemField);/*from w w w . jav a2s. c o m*/ } //Save XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); try { out.output(doc, new FileOutputStream(_configFile)); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.t3.metamediamanager.M3Config.java
License:Apache License
/** * Saves all parameters in "config.xml" file located in the user directory *//*from ww w . ja v a 2s . co m*/ public void save() { try { Element root = new Element("config"); Document doc = new Document(root); for (Entry<String, String> entry : _params.entrySet()) { Element p = new Element("param"); p.setAttribute("name", entry.getKey()); p.setAttribute("value", entry.getValue()); root.addContent(p); } //Film directories for (String dir : _filmsDirectories) { Element d = new Element("dir"); d.setAttribute("type", "films"); d.setAttribute("url", dir); root.addContent(d); } //Series directories for (String dir : _seriesDirectories) { Element d = new Element("dir"); d.setAttribute("type", "series"); d.setAttribute("url", dir); root.addContent(d); } //Enabled savers for (String s : _enabledSavers) { Element d = new Element("enabledSaver"); d.setText(s); root.addContent(d); } //Enabled providers for (String s : _enabledProviders) { Element d = new Element("enabledProvider"); d.setText(s); root.addContent(d); } //Save XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat()); sortie.output(doc, new FileOutputStream(_fileConfig)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { } }
From source file:org.t3.metamediamanager.MediaCenterDataMediaBrowser.java
License:Apache License
/******************************************************************** ********************************************************************* ******************************SERIES********************************* ********************************************************************* *********************************************************************/ @Override// ww w.ja v a 2 s. c o m public void saveSeries(MediaInfo mediainfo, String directory) { HashMap<String, String> hashinfo = _saverconfig.getFieldsAssociation(); Element root = new Element("Data"); Element series = new Element("Series"); for (Entry<String, String> entry : mediainfo.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); for (Entry<String, String> entry2 : hashinfo.entrySet()) { String key2 = entry2.getKey(); String value2 = entry2.getValue(); if (key.equals(key2)) { Element newchild = new Element(value2); newchild.setText(value); series.addContent(newchild); } } } //actors Element allactorselement = new Element("Actors"); String allactors = ""; ActorInfo[] actors = mediainfo.getActors(); Element actorselement = new Element("Actors"); for (int i = 0; i < actors.length; i++) { Element actorelement = new Element("Actor"); Element name = new Element("Name"); name.setText(actors[i].getName()); Element role = new Element("Role"); role.setText(actors[i].getRole()); actorelement.addContent(name); actorelement.addContent(role); actorselement.addContent(actorelement); allactors += actors[i].getName() + " | "; } if (allactors != "" && allactors.length() >= 2) { allactorselement.setText(allactors.substring(0, allactors.length() - 2)); } series.addContent(allactorselement); series.addContent(actorselement); root.addContent(series); Document document = new Document(root); XMLOutputter exit = new XMLOutputter(Format.getPrettyFormat()); String newFileNameNfo = new File(directory, "Series.xml").getAbsolutePath(); System.out.println(newFileNameNfo); try { exit.output(document, new FileOutputStream(newFileNameNfo)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //images String images[]; images = mediainfo.getImages("img_banner"); if (images[0] != "") { copy_images(images[0], new File(directory, "banner.jpg").getAbsolutePath()); } images = mediainfo.getImages("img_poster"); if (images[0] != "") { copy_images(images[0], new File(directory, "folder.jpg").getAbsolutePath()); } images = mediainfo.getImages("img_fanart"); if (images[0] != "") { for (int i = 0; i < images.length; i++) { int j = i + 1; copy_images(images[i], new File(directory, "backdrop" + j + ".jpg").getAbsolutePath()); } } }