From 44f6f1494419ede8c7e6240e0d159dac2969d632 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 10 Apr 2019 19:10:59 -0400 Subject: [PATCH 1/5] 4943 add option to choose delimiter for text file report --- .../autopsy/report/Bundle.properties | 2 + .../autopsy/report/Bundle.properties-MERGED | 1 + .../autopsy/report/FileReportText.java | 31 ++++--- .../ReportFileTextConfigurationPanel.form | 68 ++++++++++++++ .../ReportFileTextConfigurationPanel.java | 89 +++++++++++++++++++ 5 files changed, 181 insertions(+), 10 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.form create mode 100644 Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties index 8d6e81e3ef..aaae95edae 100644 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties @@ -258,3 +258,5 @@ CreatePortableCasePanel.outputFolderTextField.text=jTextField1 CreatePortableCasePanel.chooseOutputFolderButton.text=Choose folder CreatePortableCasePanel.jLabel1.text=Export files tagged as: CreatePortableCasePanel.jLabel2.text=Select output folder: +ReportFileTextConfigurationPanel.tabDelimitedButton.text=Tab delimited +ReportFileTextConfigurationPanel.commaDelimitedButton.text=Comma delimited diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED index 3111ffbe6d..f433b5c7d2 100755 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED @@ -306,4 +306,5 @@ CreatePortableCasePanel.outputFolderTextField.text=jTextField1 CreatePortableCasePanel.chooseOutputFolderButton.text=Choose folder CreatePortableCasePanel.jLabel1.text=Export files tagged as: CreatePortableCasePanel.jLabel2.text=Select output folder: +ReportFileTextConfigurationPanel.delimiterLabel.text=Delimiter: TableReportGenerator.StatusColumn.Header=Review Status diff --git a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java index f96bad446b..036ead4019 100644 --- a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java +++ b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2013 - 2018 Basis Technology Corp. + * Copyright 2013 - 2019 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.report; import java.io.BufferedWriter; +import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; @@ -27,6 +28,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.logging.Level; +import javax.swing.JPanel; import org.sleuthkit.autopsy.coreutils.Logger; import org.openide.util.NbBundle; @@ -43,11 +45,11 @@ import org.sleuthkit.datamodel.TskCoreException; class FileReportText implements FileReportModule { private static final Logger logger = Logger.getLogger(FileReportText.class.getName()); + private static final String FILE_NAME = "file-report.txt"; //NON-NLS + private static FileReportText instance; private String reportPath; private Writer out; - private static final String FILE_NAME = "file-report.txt"; //NON-NLS - - private static FileReportText instance; + private ReportFileTextConfigurationPanel configPanel; // Get the default implementation of this report public static synchronized FileReportText getDefault() { @@ -62,7 +64,7 @@ class FileReportText implements FileReportModule { this.reportPath = baseReportDir + FILE_NAME; try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(this.reportPath))); - } catch (IOException ex) { + } catch (FileNotFoundException ex) { logger.log(Level.WARNING, "Failed to create report text file", ex); //NON-NLS } } @@ -85,11 +87,12 @@ class FileReportText implements FileReportModule { } } - private String getTabDelimitedList(List list) { - StringBuilder output = new StringBuilder(); + private String getDelimitedList(List list, String delimiter) { + StringBuilder output; + output = new StringBuilder(); Iterator it = list.iterator(); while (it.hasNext()) { - output.append(it.next()).append((it.hasNext() ? "\t" : System.lineSeparator())); + output.append(it.next()).append((it.hasNext() ? delimiter : System.lineSeparator())); } return output.toString(); } @@ -101,7 +104,7 @@ class FileReportText implements FileReportModule { titles.add(col.getName()); } try { - out.write(getTabDelimitedList(titles)); + out.write(getDelimitedList(titles, configPanel.getDelimiter())); } catch (IOException ex) { logger.log(Level.WARNING, "Error when writing headers to report file: {0}", ex); //NON-NLS } @@ -114,7 +117,7 @@ class FileReportText implements FileReportModule { cells.add(type.getValue(toAdd)); } try { - out.write(getTabDelimitedList(cells)); + out.write(getDelimitedList(cells, configPanel.getDelimiter())); } catch (IOException ex) { logger.log(Level.WARNING, "Error when writing row to report file: {0}", ex); //NON-NLS } @@ -143,4 +146,12 @@ class FileReportText implements FileReportModule { public String getRelativeFilePath() { return FILE_NAME; } + + @Override + public JPanel getConfigurationPanel() { + if (configPanel == null) { + configPanel = new ReportFileTextConfigurationPanel(); + } + return configPanel; + } } diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.form b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.form new file mode 100644 index 0000000000..d0c59f7bdd --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.form @@ -0,0 +1,68 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java new file mode 100644 index 0000000000..18a26ff453 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java @@ -0,0 +1,89 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2019 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.report; + +class ReportFileTextConfigurationPanel extends javax.swing.JPanel { + + private static final long serialVersionUID = 1L; + + /** + * Creates new form ReportFileTextConfigurationPanel + */ + ReportFileTextConfigurationPanel() { + initComponents(); + } + + String getDelimiter() { + if (commaDelimitedButton.isSelected()) { + return ","; + } else { + //if the comma button is not selected default to tab since it was previously the only option + return "\t"; + } + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + delimiterGroup = new javax.swing.ButtonGroup(); + tabDelimitedButton = new javax.swing.JRadioButton(); + commaDelimitedButton = new javax.swing.JRadioButton(); + + delimiterGroup.add(tabDelimitedButton); + tabDelimitedButton.setSelected(true); + org.openide.awt.Mnemonics.setLocalizedText(tabDelimitedButton, org.openide.util.NbBundle.getMessage(ReportFileTextConfigurationPanel.class, "ReportFileTextConfigurationPanel.tabDelimitedButton.text")); // NOI18N + + delimiterGroup.add(commaDelimitedButton); + org.openide.awt.Mnemonics.setLocalizedText(commaDelimitedButton, org.openide.util.NbBundle.getMessage(ReportFileTextConfigurationPanel.class, "ReportFileTextConfigurationPanel.commaDelimitedButton.text")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(tabDelimitedButton, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(commaDelimitedButton, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(166, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(tabDelimitedButton) + .addComponent(commaDelimitedButton)) + .addContainerGap(78, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JRadioButton commaDelimitedButton; + private javax.swing.ButtonGroup delimiterGroup; + private javax.swing.JRadioButton tabDelimitedButton; + // End of variables declaration//GEN-END:variables +} From fb91ac3384979f6e6e4adcd3f74deb92f4381e37 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 10 Apr 2019 19:15:02 -0400 Subject: [PATCH 2/5] 4943 adjust description and cleanup --- Core/src/org/sleuthkit/autopsy/report/Bundle.properties | 2 +- .../org/sleuthkit/autopsy/report/Bundle.properties-MERGED | 3 ++- Core/src/org/sleuthkit/autopsy/report/FileReportText.java | 2 +- .../autopsy/report/ReportFileTextConfigurationPanel.java | 6 ++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties index aaae95edae..20f16e4ac6 100644 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties @@ -37,7 +37,7 @@ FileReportDataTypes.knownStatus.text=Known Status FileReportDataTypes.perms.text=Permissions FileReportDataTypes.path.text=Full Path FileReportText.getName.text=Files - Text -FileReportText.getDesc.text=A tab delimited text file containing information about individual files in the case. +FileReportText.getDesc.text=A delimited text file containing information about individual files in the case. ReportBodyFile.progress.querying=Querying files... ReportBodyFile.ingestWarning.text=Warning, this report was run before ingest services completed\! ReportBodyFile.progress.loading=Loading files... diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED index f433b5c7d2..853455b01e 100755 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED @@ -306,5 +306,6 @@ CreatePortableCasePanel.outputFolderTextField.text=jTextField1 CreatePortableCasePanel.chooseOutputFolderButton.text=Choose folder CreatePortableCasePanel.jLabel1.text=Export files tagged as: CreatePortableCasePanel.jLabel2.text=Select output folder: -ReportFileTextConfigurationPanel.delimiterLabel.text=Delimiter: +ReportFileTextConfigurationPanel.tabDelimitedButton.text=Tab delimited +ReportFileTextConfigurationPanel.commaDelimitedButton.text=Comma delimited TableReportGenerator.StatusColumn.Header=Review Status diff --git a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java index 036ead4019..a6eb2dd1a1 100644 --- a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java +++ b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java @@ -38,7 +38,7 @@ import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TskCoreException; /** - * A Tab-delimited text report of the files in the case. + * A delimited text report of the files in the case. * * @author jwallace */ diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java index 18a26ff453..6f9b2ec799 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java @@ -21,6 +21,8 @@ package org.sleuthkit.autopsy.report; class ReportFileTextConfigurationPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; + private static final String TAB_DELIMITER = "\t"; //NON-NLS + private static final String COMMA_DELIMITER = ","; //NON-NLS /** * Creates new form ReportFileTextConfigurationPanel @@ -31,10 +33,10 @@ class ReportFileTextConfigurationPanel extends javax.swing.JPanel { String getDelimiter() { if (commaDelimitedButton.isSelected()) { - return ","; + return COMMA_DELIMITER; } else { //if the comma button is not selected default to tab since it was previously the only option - return "\t"; + return TAB_DELIMITER; } } From 48250a49a4e91550e08a014352245440d5003e11 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 10 Apr 2019 19:29:01 -0400 Subject: [PATCH 3/5] 4943 update merged file and comment --- .../org/sleuthkit/autopsy/report/Bundle.properties-MERGED | 2 +- .../autopsy/report/ReportFileTextConfigurationPanel.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED index 853455b01e..1187fe8e81 100755 --- a/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/report/Bundle.properties-MERGED @@ -85,7 +85,7 @@ FileReportDataTypes.knownStatus.text=Known Status FileReportDataTypes.perms.text=Permissions FileReportDataTypes.path.text=Full Path FileReportText.getName.text=Files - Text -FileReportText.getDesc.text=A tab delimited text file containing information about individual files in the case. +FileReportText.getDesc.text=A delimited text file containing information about individual files in the case. ReportBodyFile.progress.querying=Querying files... ReportBodyFile.ingestWarning.text=Warning, this report was run before ingest services completed\! ReportBodyFile.progress.loading=Loading files... diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java index 6f9b2ec799..351b8ff432 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java @@ -31,6 +31,11 @@ class ReportFileTextConfigurationPanel extends javax.swing.JPanel { initComponents(); } + /** + * Get the delimiter that was selected on this panel + * + * @return the selected delimiter + */ String getDelimiter() { if (commaDelimitedButton.isSelected()) { return COMMA_DELIMITER; From 9d5aa7fc632ba3dc86570f34b57f3d4fd5885a36 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Thu, 11 Apr 2019 12:21:07 -0400 Subject: [PATCH 4/5] 4943 wrap fields in quotes to avoid delimiter in field from being used as delimiter --- Core/src/org/sleuthkit/autopsy/report/FileReportText.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java index a6eb2dd1a1..f9413169f2 100644 --- a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java +++ b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java @@ -92,7 +92,7 @@ class FileReportText implements FileReportModule { output = new StringBuilder(); Iterator it = list.iterator(); while (it.hasNext()) { - output.append(it.next()).append((it.hasNext() ? delimiter : System.lineSeparator())); + output.append("\"").append(it.next()).append("\"").append((it.hasNext() ? delimiter : System.lineSeparator())); } return output.toString(); } From 616fa5484018e502995b0520edc2bc085d01cf5d Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 12 Apr 2019 10:47:23 -0400 Subject: [PATCH 5/5] 4943 address codacy complaints --- Core/src/org/sleuthkit/autopsy/report/FileReportText.java | 2 +- .../autopsy/report/ReportFileTextConfigurationPanel.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java index f9413169f2..9d3de2c945 100644 --- a/Core/src/org/sleuthkit/autopsy/report/FileReportText.java +++ b/Core/src/org/sleuthkit/autopsy/report/FileReportText.java @@ -92,7 +92,7 @@ class FileReportText implements FileReportModule { output = new StringBuilder(); Iterator it = list.iterator(); while (it.hasNext()) { - output.append("\"").append(it.next()).append("\"").append((it.hasNext() ? delimiter : System.lineSeparator())); + output.append('"').append(it.next()).append('"').append((it.hasNext() ? delimiter : System.lineSeparator())); } return output.toString(); } diff --git a/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java index 351b8ff432..e1b9de2df2 100644 --- a/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java +++ b/Core/src/org/sleuthkit/autopsy/report/ReportFileTextConfigurationPanel.java @@ -18,6 +18,9 @@ */ package org.sleuthkit.autopsy.report; +/** + * Panel for configuring settings for the file text report + */ class ReportFileTextConfigurationPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L;