20 package org.sleuthkit.autopsy.report;
22 import javax.swing.JPanel;
24 import org.openide.util.NbBundle;
30 import java.io.BufferedReader;
31 import java.io.BufferedWriter;
33 import java.io.FileOutputStream;
34 import java.io.FileReader;
35 import java.io.FileWriter;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.io.OutputStream;
39 import java.util.logging.Level;
40 import org.jdom2.Document;
41 import org.jdom2.Element;
42 import org.jdom2.Namespace;
43 import org.jdom2.output.Format;
44 import org.jdom2.output.XMLOutputter;
45 import org.apache.commons.lang.StringEscapeUtils;
50 class ReportKML
implements GeneralReportModule {
52 private static final Logger logger = Logger.getLogger(ReportKML.class.getName());
53 private static ReportKML instance = null;
54 private Case currentCase;
56 private String reportPath;
63 public static synchronized ReportKML getDefault() {
64 if (instance == null) {
65 instance =
new ReportKML();
77 public void generateReport(String baseReportDir, ReportProgressPanel progressPanel) {
80 progressPanel.setIndeterminate(
false);
81 progressPanel.start();
82 progressPanel.updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportKML.progress.querying"));
83 reportPath = baseReportDir +
"ReportKML.kml";
84 String reportPath2 = baseReportDir +
"ReportKML.txt";
85 currentCase = Case.getCurrentCase();
86 skCase = currentCase.getSleuthkitCase();
88 progressPanel.updateStatusLabel(NbBundle.getMessage(
this.getClass(),
"ReportKML.progress.loading"));
90 String ingestwarning =
"";
91 if (IngestManager.getInstance().isIngestRunning()) {
92 ingestwarning = NbBundle.getMessage(this.getClass(),
"ReportBodyFile.ingestWarning.text");
94 progressPanel.setMaximumProgress(5);
95 progressPanel.increment();
103 BufferedWriter out = null;
105 out =
new BufferedWriter(
new FileWriter(reportPath2));
111 String imageName =
"";
119 String extractedToPath;
124 lat = attribute.getValueDouble();
128 lon = attribute.getValueDouble();
131 if (lon != 0 && lat != 0) {
135 extractedToPath = reportPath + aFile.
getName();
136 geoPath = extractedToPath;
137 f =
new File(extractedToPath);
139 copyFileUsingStream(aFile, f);
142 out.write(String.valueOf(lat));
144 out.write(String.valueOf(lon));
146 out.write(String.valueOf(geoPath));
148 out.write(String.valueOf(imageName));
160 lat = attribute.getValueDouble();
164 lon = attribute.getValueDouble();
167 if (lon != 0 && lat != 0) {
168 out.write(lat +
";" + lon +
"\n");
178 String location =
"";
182 lat = attribute.getValueDouble();
185 destlat = attribute.getValueDouble();
188 lon = attribute.getValueDouble();
191 destlon = attribute.getValueDouble();
194 name = attribute.getValueString();
197 location = attribute.getValueString();
202 String display = name;
203 if (display.isEmpty())
206 if (lon != 0 && lat != 0) {
207 out.write(NbBundle.getMessage(
this.getClass(),
"ReportKML.latLongStartPoint", lat, lon, display));
209 if (destlat != 0 && destlon != 0) {
210 out.write(NbBundle.getMessage(
this.getClass(),
"ReportKML.latLongEndPoint", destlat, destlon,
218 progressPanel.increment();
222 Namespace ns = Namespace.getNamespace(
"",
"http://earth.google.com/kml/2.2");
224 Element kml =
new Element(
"kml", ns);
225 Document kmlDocument =
new Document(kml);
228 Element document =
new Element(
"Document", ns);
229 kml.addContent(document);
232 Element name =
new Element(
"name", ns);
233 name.setText(
"Java Generated KML Document");
234 document.addContent(name);
241 Element style =
new Element(
"Style", ns);
242 style.setAttribute(
"id",
"redIcon");
243 document.addContent(style);
246 Element iconStyle =
new Element(
"IconStyle", ns);
247 style.addContent(iconStyle);
250 Element color =
new Element(
"color", ns);
251 color.setText(
"990000ff");
252 iconStyle.addContent(color);
255 Element icon =
new Element(
"Icon", ns);
256 iconStyle.addContent(icon);
259 Element href =
new Element(
"href", ns);
260 href.setText(
"http://www.cs.mun.ca/~hoeber/teaching/cs4767/notes/02.1-kml/circle.png");
261 icon.addContent(href);
262 progressPanel.increment();
269 BufferedReader reader;
271 reader =
new BufferedReader(
new FileReader(file));
273 String line = reader.readLine();
274 while (line != null) {
275 String[] lineParts = line.split(
";");
276 if (lineParts.length > 1) {
277 String coordinates = lineParts[1].trim() +
"," + lineParts[0].trim();
279 Element placemark =
new Element(
"Placemark", ns);
280 document.addContent(placemark);
282 if (lineParts.length == 4) {
284 Element pmName =
new Element(
"name", ns);
285 pmName.setText(lineParts[3].trim());
286 placemark.addContent(pmName);
288 String savedPath = lineParts[2].trim();
289 if (savedPath.isEmpty() ==
false) {
291 Element pmPath =
new Element(
"Path", ns);
292 pmPath.setText(savedPath);
293 placemark.addContent(pmPath);
296 Element pmDescription =
new Element(
"description", ns);
297 String xml =
"<![CDATA[ \n" +
" <img src='file:///" + savedPath +
"' width='400' /><br/> \n";
298 StringEscapeUtils.unescapeXml(xml);
299 pmDescription.setText(xml);
300 placemark.addContent(pmDescription);
305 Element pmStyleUrl =
new Element(
"styleUrl", ns);
306 pmStyleUrl.setText(
"#redIcon");
307 placemark.addContent(pmStyleUrl);
310 Element pmPoint =
new Element(
"Point", ns);
311 placemark.addContent(pmPoint);
314 Element pmCoordinates =
new Element(
"coordinates", ns);
316 pmCoordinates.setText(coordinates);
317 pmPoint.addContent(pmCoordinates);
322 line = reader.readLine();
324 progressPanel.increment();
329 XMLOutputter outputter =
new XMLOutputter(Format.getPrettyFormat());
330 FileOutputStream writer =
new FileOutputStream(reportPath);
331 outputter.output(kmlDocument, writer);
333 Case.getCurrentCase().addReport(reportPath, NbBundle.getMessage(
this.getClass(),
334 "ReportKML.genReport.srcModuleName.text"),
"");
335 }
catch (IOException ex) {
336 logger.log(Level.WARNING,
"Could not write the KML file.", ex);
338 String errorMessage = String.format(
"Error adding %s to case as a report", reportPath);
339 logger.log(Level.SEVERE, errorMessage, ex);
341 }
catch (IOException ex) {
342 logger.log(Level.WARNING,
"Could not write the KML report.", ex);
344 progressPanel.complete(ReportProgressPanel.ReportStatus.ERROR);
346 logger.log(Level.WARNING,
"Failed to get the unique path.", ex);
348 progressPanel.increment();
349 progressPanel.complete(ReportProgressPanel.ReportStatus.COMPLETE);
352 public static void copyFileUsingStream(
AbstractFile file,
File jFile)
throws IOException {
354 OutputStream os =
new FileOutputStream(jFile);
355 byte[] buffer =
new byte[8192];
358 while ((length = is.read(buffer)) != -1) {
359 os.write(buffer, 0, length);
369 public String getName() {
370 String name = NbBundle.getMessage(this.getClass(),
"ReportKML.getName.text");
375 public String getRelativeFilePath() {
376 return "ReportKML.kml";
380 public String getDescription() {
381 String desc = NbBundle.getMessage(this.getClass(),
"ReportKML.getDesc.text");
386 public JPanel getConfigurationPanel() {
ArrayList< BlackboardArtifact > getBlackboardArtifacts(int artifactTypeID)
AbstractFile getAbstractFileById(long id)
SleuthkitCase getSleuthkitCase()