19 package org.sleuthkit.autopsy.timeline.actions;
22 import java.io.FileNotFoundException;
23 import java.io.FileWriter;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.Writer;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.function.Consumer;
32 import java.util.logging.Level;
33 import javafx.embed.swing.SwingFXUtils;
34 import javafx.event.ActionEvent;
35 import javafx.scene.image.WritableImage;
36 import javafx.stage.DirectoryChooser;
37 import javafx.util.Pair;
38 import javax.imageio.ImageIO;
39 import org.controlsfx.control.action.Action;
40 import org.openide.util.NbBundle;
51 private static final String
HTML_EXT =
".html";
62 super(NbBundle.getMessage(
SaveSnapshot.class,
"SaveSnapshot.action.name.text"));
65 setEventHandler(
new Consumer<ActionEvent>() {
68 public void accept(ActionEvent t) {
70 DirectoryChooser fileChooser =
new DirectoryChooser();
71 fileChooser.setTitle(NbBundle.getMessage(
this.getClass(),
"SaveSnapshot.fileChoose.title.text"));
73 File outFolder = fileChooser.showDialog(null);
74 if (outFolder == null) {
78 String name = outFolder.getName();
81 List<Pair<String, String>> reportMetaData =
new ArrayList<>();
85 ZoomParams get = controller.getEventsModel().getRequestedZoomParamters().get();
86 reportMetaData.add(
new Pair<>(
"Time Range",
get.getTimeRange().toString()));
87 reportMetaData.add(
new Pair<>(
"Description Level of Detail",
get.getDescrLOD().getDisplayName()));
88 reportMetaData.add(
new Pair<>(
"Event Type Zoom Level",
get.getTypeZoomLevel().getDisplayName()));
89 reportMetaData.add(
new Pair<>(
"Filters",
get.getFilter().getHTMLReportString()));
93 ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null),
"png",
new File(outFolder.getPath() + File.separator + outFolder.getName() +
REPORT_IMAGE_EXTENSION));
94 }
catch (IOException ex) {
95 LOGGER.log(Level.WARNING,
"failed to write snapshot to disk", ex);
100 StringBuilder wrapper =
new StringBuilder();
101 wrapper.append(
"<html>\n<head>\n\t<title>").append(
"timeline snapshot").append(
"</title>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"index.css\" />\n</head>\n<body>\n");
102 wrapper.append(
"<div id=\"content\">\n<h1>").append(outFolder.getName()).append(
"</h1>\n");
103 wrapper.append(
"<img src = \"").append(outFolder.getName()).append(REPORT_IMAGE_EXTENSION +
"\" alt = \"snaphot\">");
104 wrapper.append(
"<table>\n");
105 for (Pair<String, String> pair : reportMetaData) {
106 wrapper.append(
"<tr><td>").append(pair.getKey()).append(
": </td><td>").append(pair.getValue()).append(
"</td></tr>\n");
108 wrapper.append(
"</table>\n");
109 wrapper.append(
"</div>\n</body>\n</html>");
112 try (Writer htmlWriter =
new FileWriter(
new File(outFolder, name + HTML_EXT))) {
113 htmlWriter.write(wrapper.toString());
114 }
catch (FileNotFoundException ex) {
115 LOGGER.log(Level.WARNING,
"failed to open html wrapper file for writing ", ex);
117 }
catch (IOException ex) {
118 LOGGER.log(Level.WARNING,
"failed to write html wrapper file", ex);
123 try (InputStream resource = this.getClass().getResourceAsStream(
"/org/sleuthkit/autopsy/timeline/index.css")) {
124 Files.copy(resource, Paths.get(outFolder.getPath(),
"index.css"));
125 }
catch (IOException ex) {
126 LOGGER.log(Level.WARNING,
"failed to copy css file", ex);
133 LOGGER.log(Level.WARNING,
"failed add html wrapper as a report", ex);
final TimeLineController controller
static final String HTML_EXT
SaveSnapshot(TimeLineController controller, WritableImage snapshot)
String getCaseDirectory()
static final String REPORT_IMAGE_EXTENSION
void addReport(String localPath, String srcModuleName, String reportName)
final WritableImage snapshot
static Case getCurrentCase()
static final Logger LOGGER
static Logger getLogger(String name)