From d9c072103333c2ed3f4ee7615100b81b9d33e0d6 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Tue, 3 Mar 2020 18:31:25 -0500 Subject: [PATCH 1/5] 6076 api changes to introduce summary object --- .../autopsy/filequery/FileSearch.java | 13 ++-- .../autopsy/filequery/ResultsPanel.java | 7 +- .../textsummarizer/TextSummarizer.java | 4 +- .../autopsy/textsummarizer/TextSummary.java | 76 +++++++++++++++++++ 4 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java diff --git a/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java b/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java index ee5c36c8e3..87ef6bfb38 100644 --- a/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java +++ b/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java @@ -78,6 +78,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository; import org.sleuthkit.autopsy.textextractors.TextExtractor; import org.sleuthkit.autopsy.textextractors.TextExtractorFactory; import org.sleuthkit.autopsy.textsummarizer.TextSummarizer; +import org.sleuthkit.autopsy.textsummarizer.TextSummary; /** * Main class to perform the file search. @@ -258,8 +259,8 @@ class FileSearch { */ @NbBundle.Messages({"FileSearch.documentSummary.noPreview=No preview available.", "FileSearch.documentSummary.noBytes=No bytes read for document, unable to display preview."}) - static String summarize(AbstractFile file) { - String summary = null; + static TextSummary summarize(AbstractFile file) { + TextSummary summary = null; TextSummarizer localSummarizer = summarizerToUse; if (localSummarizer == null) { synchronized (searchCache) { @@ -273,12 +274,12 @@ class FileSearch { //a summary of length 40 seems to fit without vertical scroll bars summary = localSummarizer.summarize(file, 40); } catch (IOException ex) { - return Bundle.FileSearch_documentSummary_noPreview(); + return new TextSummary(Bundle.FileSearch_documentSummary_noPreview(), null); } } - if (StringUtils.isBlank(summary)) { - //no summarizer was found or summary was empty just grab the beginning of the file - summary = getFirstLines(file); + if (summary == null || StringUtils.isBlank(summary.getSummaryText())) { + //summary text was empty grab the beginning of the file + summary = new TextSummary(getFirstLines(file), null); } return summary; } diff --git a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java index 4711303123..bd84ba7eb1 100644 --- a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java @@ -55,6 +55,7 @@ import org.sleuthkit.autopsy.modules.hashdatabase.AddContentToHashDbAction; import org.sleuthkit.datamodel.AbstractFile; import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository; +import org.sleuthkit.autopsy.textsummarizer.TextSummary; /** * Panel for displaying of file discovery results and handling the paging of @@ -777,11 +778,11 @@ public class ResultsPanel extends javax.swing.JPanel { @Messages({"ResultsPanel.unableToCreate.text=Unable to create summary."}) @Override protected Void doInBackground() throws Exception { - String preview = FileSearch.summarize(documentWrapper.getResultFile().getFirstInstance()); + TextSummary preview = FileSearch.summarize(documentWrapper.getResultFile().getFirstInstance()); if (preview == null) { - preview = Bundle.ResultsPanel_unableToCreate_text(); + preview = new TextSummary(Bundle.ResultsPanel_unableToCreate_text(), null); } - documentWrapper.setPreview(preview); + documentWrapper.setPreview(preview.getSummaryText()); return null; } diff --git a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummarizer.java b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummarizer.java index 2d40d7af5b..733ad5e517 100644 --- a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummarizer.java +++ b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummarizer.java @@ -40,9 +40,9 @@ public interface TextSummarizer { * @param file The AbstractFile to summarize. * @param summarySize The size of the summary to create. * - * @return The summary as a string. + * @return The summary as a TextSummary object. * * @throws IOException */ - String summarize(AbstractFile file, int summarySize) throws IOException; + TextSummary summarize(AbstractFile file, int summarySize) throws IOException; } diff --git a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java new file mode 100644 index 0000000000..38b4c73342 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java @@ -0,0 +1,76 @@ +/* + * Autopsy + * + * Copyright 2020 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.textsummarizer; + +import java.awt.Image; +import java.util.List; + +/** + * Class to contain all information necessary to display a summary for a file.s + */ +public class TextSummary { + + private final String summaryText; + private final Image sampleImage; + private final int numberOfImages; + + /** + * Create a new TextSummary object. + * + * @param summary - The text portion of the summary. + * @param images - The Image portion of the summary + */ + public TextSummary(String summary, List images) { + summaryText = summary; + if (images == null || images.isEmpty()) { + sampleImage = null; + numberOfImages = 0; + } else { + sampleImage = selectSummaryImage(images); + numberOfImages = images.size(); + } + } + + /** + * Get the Image from the available images to include as part of the + * summary. + * + * @param images - The list of Images available to choose from. + * + * @return The selected image to include in the summary. + */ + private Image selectSummaryImage(List images) { + return images.get(0); + } + + /** + * @return the summaryText + */ + public String getSummaryText() { + return summaryText; + } + + /** + * @return the sampleImage + */ + public Image getSampleImage() { + return sampleImage; + } + +} From 516c1575d678c18dda5547d98ef2fee8697627f1 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 4 Mar 2020 13:35:19 -0500 Subject: [PATCH 2/5] 6076 textsummarizer api changes --- .../autopsy/filequery/FileSearch.java | 4 +-- .../autopsy/filequery/ResultsPanel.java | 2 +- .../autopsy/textsummarizer/TextSummary.java | 29 +++++-------------- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java b/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java index 87ef6bfb38..00ff3c083c 100644 --- a/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java +++ b/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java @@ -274,12 +274,12 @@ class FileSearch { //a summary of length 40 seems to fit without vertical scroll bars summary = localSummarizer.summarize(file, 40); } catch (IOException ex) { - return new TextSummary(Bundle.FileSearch_documentSummary_noPreview(), null); + return new TextSummary(Bundle.FileSearch_documentSummary_noPreview(), null, 0); } } if (summary == null || StringUtils.isBlank(summary.getSummaryText())) { //summary text was empty grab the beginning of the file - summary = new TextSummary(getFirstLines(file), null); + summary = new TextSummary(getFirstLines(file), null, 0); } return summary; } diff --git a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java index bd84ba7eb1..7ba0e452ca 100644 --- a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java @@ -780,7 +780,7 @@ public class ResultsPanel extends javax.swing.JPanel { protected Void doInBackground() throws Exception { TextSummary preview = FileSearch.summarize(documentWrapper.getResultFile().getFirstInstance()); if (preview == null) { - preview = new TextSummary(Bundle.ResultsPanel_unableToCreate_text(), null); + preview = new TextSummary(Bundle.ResultsPanel_unableToCreate_text(), null, 0); } documentWrapper.setPreview(preview.getSummaryText()); return null; diff --git a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java index 38b4c73342..c556f98b14 100644 --- a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java +++ b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java @@ -33,30 +33,15 @@ public class TextSummary { /** * Create a new TextSummary object. * - * @param summary - The text portion of the summary. - * @param images - The Image portion of the summary + * @param summary - The text portion of the summary. + * @param image - The Image portion of the summary + * @param countOfImages - The number of images including the one provided in + * the document. */ - public TextSummary(String summary, List images) { + public TextSummary(String summary, Image image, int countOfImages) { summaryText = summary; - if (images == null || images.isEmpty()) { - sampleImage = null; - numberOfImages = 0; - } else { - sampleImage = selectSummaryImage(images); - numberOfImages = images.size(); - } - } - - /** - * Get the Image from the available images to include as part of the - * summary. - * - * @param images - The list of Images available to choose from. - * - * @return The selected image to include in the summary. - */ - private Image selectSummaryImage(List images) { - return images.get(0); + sampleImage = image; + numberOfImages = countOfImages; } /** From 1dd59dc16d0de1968ae3c2ff35226337b45b6e68 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 4 Mar 2020 13:41:03 -0500 Subject: [PATCH 3/5] 6076 add method to get number of images from summary --- .../org/sleuthkit/autopsy/textsummarizer/TextSummary.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java index c556f98b14..27c10d4fcc 100644 --- a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java +++ b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java @@ -58,4 +58,11 @@ public class TextSummary { return sampleImage; } + /** + * @return the numberOfImages + */ + int getNumberOfImages() { + return numberOfImages; + } + } From e9dd8b1b008c99cc1e57282b3c0eafac0102f795 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 4 Mar 2020 13:41:52 -0500 Subject: [PATCH 4/5] 6076 add method to get number of images from summary --- Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java index 27c10d4fcc..04eb201580 100644 --- a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java +++ b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java @@ -61,7 +61,7 @@ public class TextSummary { /** * @return the numberOfImages */ - int getNumberOfImages() { + public int getNumberOfImages() { return numberOfImages; } From 2a84b8e596e598d5710aba80f4a0b05ac4bafa87 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 4 Mar 2020 13:45:52 -0500 Subject: [PATCH 5/5] 6076 remove unused import --- Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java index 04eb201580..86d6122188 100644 --- a/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java +++ b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java @@ -19,7 +19,6 @@ package org.sleuthkit.autopsy.textsummarizer; import java.awt.Image; -import java.util.List; /** * Class to contain all information necessary to display a summary for a file.s