diff --git a/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java b/Core/src/org/sleuthkit/autopsy/filequery/FileSearch.java index fbf8356e16..c1323d32b1 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, 0); } } - 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, 0); } return summary; } diff --git a/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java b/Core/src/org/sleuthkit/autopsy/filequery/ResultsPanel.java index 4711303123..7ba0e452ca 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, 0); } - 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..86d6122188 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/textsummarizer/TextSummary.java @@ -0,0 +1,67 @@ +/* + * 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; + +/** + * 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 image - The Image portion of the summary + * @param countOfImages - The number of images including the one provided in + * the document. + */ + public TextSummary(String summary, Image image, int countOfImages) { + summaryText = summary; + sampleImage = image; + numberOfImages = countOfImages; + } + + /** + * @return the summaryText + */ + public String getSummaryText() { + return summaryText; + } + + /** + * @return the sampleImage + */ + public Image getSampleImage() { + return sampleImage; + } + + /** + * @return the numberOfImages + */ + public int getNumberOfImages() { + return numberOfImages; + } + +}