19package org.sleuthkit.autopsy.report.modules.file;
21import org.sleuthkit.autopsy.report.infrastructure.FileReportDataTypes;
22import org.sleuthkit.autopsy.report.NoReportModuleSettings;
23import org.sleuthkit.autopsy.report.ReportModuleSettings;
24import java.io.BufferedWriter;
25import java.io.FileNotFoundException;
26import java.io.FileOutputStream;
27import java.io.IOException;
28import java.io.OutputStreamWriter;
30import java.nio.charset.StandardCharsets;
31import java.util.ArrayList;
32import java.util.Iterator;
34import java.util.logging.Level;
35import javax.swing.JPanel;
36import org.sleuthkit.autopsy.coreutils.Logger;
37import org.openide.util.NbBundle;
38import org.sleuthkit.autopsy.casemodule.Case;
39import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
40import org.sleuthkit.autopsy.report.infrastructure.FileReportModule;
41import org.sleuthkit.datamodel.AbstractFile;
42import org.sleuthkit.datamodel.TskCoreException;
51 private static final Logger logger = Logger.getLogger(FileReportText.class.getName());
52 private static final String FILE_NAME =
"file-report.txt";
53 private static FileReportText instance;
54 private String reportPath;
56 private ReportFileTextConfigurationPanel configPanel;
59 public static synchronized FileReportText getDefault() {
60 if (instance ==
null) {
61 instance =
new FileReportText();
73 return new FileReportModuleSettings();
84 return configPanel.getConfiguration();
93 public void setConfiguration(ReportModuleSettings settings) {
95 if (settings ==
null || settings instanceof NoReportModuleSettings) {
100 if (settings instanceof FileReportModuleSettings) {
101 configPanel.setConfiguration((FileReportModuleSettings) settings);
105 throw new IllegalArgumentException(
"Expected settings argument to be an instance of FileReportModuleSettings");
109 public void startReport(String baseReportDir) {
110 this.reportPath = baseReportDir + FILE_NAME;
112 out =
new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(this.reportPath), StandardCharsets.UTF_8));
114 }
catch (FileNotFoundException ex) {
115 logger.log(Level.WARNING,
"Failed to create report text file", ex);
116 }
catch (IOException ex) {
117 logger.log(Level.WARNING,
"Failed to write BOM to report text file", ex);
126 Case.getCurrentCaseThrows().addReport(reportPath, NbBundle.getMessage(
this.getClass(),
127 "FileReportText.getName.text"),
"");
128 }
catch (IOException ex) {
129 logger.log(Level.WARNING,
"Could not close output writer when ending report.", ex);
130 }
catch (TskCoreException ex) {
131 String errorMessage = String.format(
"Error adding %s to case as a report", reportPath);
132 logger.log(Level.SEVERE, errorMessage, ex);
133 }
catch (NoCurrentCaseException ex) {
134 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
139 private String getDelimitedList(List<String> list, String delimiter) {
140 StringBuilder output;
141 output =
new StringBuilder();
142 Iterator<String> it = list.iterator();
143 while (it.hasNext()) {
144 output.append(
'"').append(it.next()).append(
'"').append((it.hasNext() ? delimiter : System.lineSeparator()));
146 return output.toString();
150 public void startTable(List<FileReportDataTypes> headers) {
151 List<String> titles =
new ArrayList<>();
152 for (FileReportDataTypes col : headers) {
153 titles.add(col.getName());
156 out.write(getDelimitedList(titles, configPanel.getDelimiter()));
157 }
catch (IOException ex) {
158 logger.log(Level.WARNING,
"Error when writing headers to report file: {0}", ex);
163 public void addRow(AbstractFile toAdd, List<FileReportDataTypes> columns) {
164 List<String> cells =
new ArrayList<>();
165 for (FileReportDataTypes type : columns) {
166 cells.add(type.getValue(toAdd));
169 out.write(getDelimitedList(cells, configPanel.getDelimiter()));
170 }
catch (IOException ex) {
171 logger.log(Level.WARNING,
"Error when writing row to report file: {0}", ex);
178 out.write(System.lineSeparator());
179 }
catch (IOException ex) {
180 logger.log(Level.WARNING,
"Error when closing table: {0}", ex);
186 return NbBundle.getMessage(this.getClass(),
"FileReportText.getName.text");
191 return NbBundle.getMessage(this.getClass(),
"FileReportText.getDesc.text");
205 private void initializePanel() {
206 if (configPanel ==
null) {
207 configPanel =
new ReportFileTextConfigurationPanel();
default ReportModuleSettings getConfiguration()
default JPanel getConfigurationPanel()
String getRelativeFilePath()
default ReportModuleSettings getDefaultConfiguration()