From 5ca2fa1931b45b9d1b3edbe664a0e1884ded389c Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Thu, 6 Aug 2020 13:31:08 -0400 Subject: [PATCH] update to enum --- .../PhotoRecCarverFileIngestModule.java | 24 ++-- .../PhotoRecCarverIngestJobSettings.java | 106 ++++++++---------- .../PhotoRecCarverIngestJobSettingsPanel.java | 25 +++-- 3 files changed, 79 insertions(+), 76 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java index eb8729c8c4..c5e6c496ad 100644 --- a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverFileIngestModule.java @@ -81,7 +81,9 @@ import org.sleuthkit.datamodel.TskData; final class PhotoRecCarverFileIngestModule implements FileIngestModule { static final boolean DEFAULT_CONFIG_KEEP_CORRUPTED_FILES = false; - static final boolean DEFAULT_CONFIG_FILE_OPT_OPTIONS = false; + static final PhotoRecCarverIngestJobSettings.ExtensionFilterOption DEFAULT_CONFIG_EXTENSION_FILTER = + PhotoRecCarverIngestJobSettings.ExtensionFilterOption.NO_FILTER; + static final boolean DEFAULT_CONFIG_INCLUDE_ELSE_EXCLUDE = false; private static final String PHOTOREC_DIRECTORY = "photorec_exec"; //NON-NLS @@ -139,7 +141,9 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule { toRet.addAll(Arrays.asList("options", "keep_corrupted_file")); } - if (settings.hasFileOptOption()) { + if (settings.getExtensionFilterOption() != + PhotoRecCarverIngestJobSettings.ExtensionFilterOption.NO_FILTER) { + // add the file opt menu item toRet.add("fileopt"); @@ -148,15 +152,17 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule { // if we are including file extensions, then we are excluding // everything else and vice-versa. - String everythingEnable = settings.isIncludeElseExclude() + String everythingEnable = settings.getExtensionFilterOption() == + PhotoRecCarverIngestJobSettings.ExtensionFilterOption.INCLUDE ? disable : enable; toRet.addAll(Arrays.asList("everything", everythingEnable)); - final String itemEnable = settings.isIncludeElseExclude() + final String itemEnable = settings.getExtensionFilterOption() == + PhotoRecCarverIngestJobSettings.ExtensionFilterOption.INCLUDE ? enable : disable; - settings.getIncludeExcludeExtensions().forEach((extension) -> { + settings.getExtensions().forEach((extension) -> { toRet.addAll(Arrays.asList(extension, itemEnable)); }); } @@ -190,13 +196,15 @@ final class PhotoRecCarverFileIngestModule implements FileIngestModule { }) public void startUp(IngestJobContext context) throws IngestModule.IngestModuleException { // validate settings - if (this.settings.hasFileOptOption()) { - if (this.settings.getIncludeExcludeExtensions().isEmpty() && this.settings.isIncludeElseExclude()) { + if (this.settings.getExtensionFilterOption() != PhotoRecCarverIngestJobSettings.ExtensionFilterOption.NO_FILTER) { + if (this.settings.getExtensions().isEmpty() && + this.settings.getExtensionFilterOption() == PhotoRecCarverIngestJobSettings.ExtensionFilterOption.INCLUDE) { + throw new IngestModule.IngestModuleException( Bundle.PhotoRecCarverFileIngestModule_startUp_noExtensionsProvided_description()); } - List invalidExtensions = this.settings.getIncludeExcludeExtensions().stream() + List invalidExtensions = this.settings.getExtensions().stream() .filter((ext) -> !PhotoRecCarverFileOptExtensions.isValidExtension(ext)) .collect(Collectors.toList()); diff --git a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettings.java b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettings.java index 40e929cb75..38c2d49082 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettings.java +++ b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettings.java @@ -28,20 +28,37 @@ import java.util.List; */ final class PhotoRecCarverIngestJobSettings implements IngestModuleIngestJobSettings { + /** + * What kind of filtering should occur for the extension list. + */ + static enum ExtensionFilterOption { + /** + * The file extensions should be included (and others should be + * filtered). + */ + INCLUDE, + /** + * The extensions should be excluded from the results list. + */ + EXCLUDE, + /** + * No extension filtering should take place. + */ + NO_FILTER + }; + private static final long serialVersionUID = 1L; private boolean keepCorruptedFiles; - private List includeExcludeExtensions; - private boolean fileOptOption; - private boolean includeElseExclude; + private List extensions; + private ExtensionFilterOption extensionFilterOption; /** * Instantiate the ingest job settings with default values. */ PhotoRecCarverIngestJobSettings() { this(PhotoRecCarverFileIngestModule.DEFAULT_CONFIG_KEEP_CORRUPTED_FILES, - PhotoRecCarverFileIngestModule.DEFAULT_CONFIG_FILE_OPT_OPTIONS, - PhotoRecCarverFileIngestModule.DEFAULT_CONFIG_INCLUDE_ELSE_EXCLUDE, + PhotoRecCarverFileIngestModule.DEFAULT_CONFIG_EXTENSION_FILTER, null); } @@ -50,19 +67,16 @@ final class PhotoRecCarverIngestJobSettings implements IngestModuleIngestJobSett * * @param keepCorruptedFiles Whether or not to keep corrupted files. * @param fileOptOption Whether or not the file opt options - * should be enabled (whether or not to - * include/exclude file extensions). - * @param includeElseExclude If file opt options is enabled, whether - * to include only the extensions listed or - * exclude extensions from output. + * @param extensionFilterOption How the includeExcludeExtensions should + * be filtered. * @param includeExcludeExtensions The extensions to include or exclude * (i.e. jpg, gif) */ - PhotoRecCarverIngestJobSettings(boolean keepCorruptedFiles, boolean fileOptOption, boolean includeElseExclude, List includeExcludeExtensions) { + PhotoRecCarverIngestJobSettings(boolean keepCorruptedFiles, ExtensionFilterOption extensionFilterOption, List includeExcludeExtensions) { this.keepCorruptedFiles = keepCorruptedFiles; - this.fileOptOption = fileOptOption; - this.includeElseExclude = includeElseExclude; - setIncludeExcludeExtensions(includeExcludeExtensions); + setExtensionFilterOption(extensionFilterOption); + setExtensions(includeExcludeExtensions); + } @Override @@ -94,10 +108,10 @@ final class PhotoRecCarverIngestJobSettings implements IngestModuleIngestJobSett * * @return The extension names. */ - List getIncludeExcludeExtensions() { - return includeExcludeExtensions == null + List getExtensions() { + return extensions == null ? Collections.emptyList() - : Collections.unmodifiableList(includeExcludeExtensions); + : Collections.unmodifiableList(extensions); } /** @@ -106,58 +120,30 @@ final class PhotoRecCarverIngestJobSettings implements IngestModuleIngestJobSett * * @param includeExcludeExtensions The extension names. */ - void setIncludeExcludeExtensions(List includeExcludeExtensions) { - this.includeExcludeExtensions = new ArrayList<>(); + void setExtensions(List includeExcludeExtensions) { + this.extensions = new ArrayList<>(); if (includeExcludeExtensions != null) { - this.includeExcludeExtensions.addAll(includeExcludeExtensions); + this.extensions.addAll(includeExcludeExtensions); } } /** - * Returns whether or not the fileopt option (and subsequent file extension - * filtering) should be enabled. - * - * @return Whether or not the fileopt option (and subsequent file extension - * filtering) should be enabled. + * How extension filtering should be handled. + * @return How extension filtering should be handled. */ - boolean hasFileOptOption() { - return fileOptOption; + ExtensionFilterOption getExtensionFilterOption() { + return (this.extensionFilterOption == null) ? + ExtensionFilterOption.NO_FILTER : + extensionFilterOption; } /** - * Returns whether or not the fileopt option (and subsequent file extension - * filtering) should be enabled. - * - * @param fileOptOption Whether or not the fileopt option (and subsequent - * file extension filtering) should be enabled. + * Sets how extension filtering should be handled. + * @param extensionFilterOption How extension filtering should be handled. */ - void setFileOptOption(boolean fileOptOption) { - this.fileOptOption = fileOptOption; - } - - /** - * If the hasFileOptOption is true, this determines whether - * includeExcludeExtensions will be included in the results (excluding all - * others) or includeExcludeExtensions will be excluded from results - * (including all others). - * - * @return Whether to include or exclude includeExcludeExtensions. - */ - boolean isIncludeElseExclude() { - return includeElseExclude; - } - - /** - * Sets whether or not to include or exclude files. If the hasFileOptOption - * is true, this determines whether includeExcludeExtensions will be - * included in the results (excluding all others) or - * includeExcludeExtensions will be excluded from results (including all - * others). - * - * @param includeElseExclude Whether to include or exclude - * includeExcludeExtensions. - */ - void setIncludeElseExclude(boolean includeElseExclude) { - this.includeElseExclude = includeElseExclude; + void setExtensionFilterOption(ExtensionFilterOption extensionFilterOption) { + this.extensionFilterOption = (extensionFilterOption == null) ? + ExtensionFilterOption.NO_FILTER : + extensionFilterOption; } } diff --git a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java index a0f72cd31c..1efafafd24 100755 --- a/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/modules/photoreccarver/PhotoRecCarverIngestJobSettingsPanel.java @@ -62,10 +62,10 @@ final class PhotoRecCarverIngestJobSettingsPanel extends IngestModuleIngestJobSe * @param settings The ingest job settings. */ private void customizeComponents(PhotoRecCarverIngestJobSettings settings) { - includeExcludeCheckbox.setSelected(settings.hasFileOptOption()); - extensionListTextfield.setText(String.join(EXTENSION_LIST_SEPARATOR, settings.getIncludeExcludeExtensions())); - includeRadioButton.setSelected(!settings.isIncludeElseExclude()); - excludeRadioButton.setSelected(!settings.isIncludeElseExclude()); + includeExcludeCheckbox.setSelected(settings.getExtensionFilterOption() != PhotoRecCarverIngestJobSettings.ExtensionFilterOption.NO_FILTER); + extensionListTextfield.setText(String.join(EXTENSION_LIST_SEPARATOR, settings.getExtensions())); + includeRadioButton.setSelected(settings.getExtensionFilterOption() == PhotoRecCarverIngestJobSettings.ExtensionFilterOption.INCLUDE); + excludeRadioButton.setSelected(settings.getExtensionFilterOption() == PhotoRecCarverIngestJobSettings.ExtensionFilterOption.EXCLUDE); keepCorruptedFilesCheckbox.setSelected(settings.isKeepCorruptedFiles()); setupTypesHyperlink(); setIncludePanelEnabled(); @@ -117,12 +117,21 @@ final class PhotoRecCarverIngestJobSettingsPanel extends IngestModuleIngestJobSe @Override public IngestModuleIngestJobSettings getSettings() { - - + PhotoRecCarverIngestJobSettings.ExtensionFilterOption filterOption = + PhotoRecCarverIngestJobSettings.ExtensionFilterOption.NO_FILTER; + + if (includeExcludeCheckbox.isSelected()) { + if (includeRadioButton.isSelected()) { + filterOption = PhotoRecCarverIngestJobSettings.ExtensionFilterOption.INCLUDE; + } else { + filterOption = PhotoRecCarverIngestJobSettings.ExtensionFilterOption.EXCLUDE; + } + } + + return new PhotoRecCarverIngestJobSettings( keepCorruptedFilesCheckbox.isSelected(), - includeExcludeCheckbox.isSelected(), - includeRadioButton.isSelected(), + filterOption, getExtensions(extensionListTextfield.getText()) ); }