19 package org.sleuthkit.autopsy.modules.fileextmismatch;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.Action;
28 import javax.swing.JOptionPane;
29 import org.openide.util.NbBundle;
30 import org.openide.util.Utilities;
31 import org.openide.util.lookup.ServiceProvider;
32 import org.openide.windows.WindowManager;
43 @ServiceProvider(service = ContextMenuActionsProvider.class)
49 ArrayList<Action> actions =
new ArrayList<>();
54 final Collection<? extends BlackboardArtifact> selectedArts = Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class);
57 if (selectedArts.size() == 1) {
59 for (BlackboardArtifact nodeArt : selectedArts) {
62 if (nodeArt.getArtifactTypeName().equals(
"TSK_EXT_MISMATCH_DETECTED")) {
63 String mimeTypeStr =
"";
66 AbstractFile af = Utilities.actionsGlobalContext().lookup(AbstractFile.class);
69 int i = af.getName().lastIndexOf(
".");
70 if ((i > -1) && ((i + 1) < af.getName().length())) {
71 extStr = af.getName().substring(i + 1).toLowerCase();
73 mimeTypeStr = af.getMIMEType();
74 if (mimeTypeStr == null) {
78 if (!extStr.isEmpty() && !mimeTypeStr.isEmpty()) {
80 if (extStr.length() > 10) {
81 extStr = extStr.substring(0, 9);
83 if (mimeTypeStr.length() > 40) {
84 mimeTypeStr = mimeTypeStr.substring(0, 39);
86 String menuItemStr = NbBundle.getMessage(this.getClass(),
87 "FileExtMismatchContextMenuActionsProvider.menuItemStr",
91 HashMap<String, Set<String>> editableMap;
93 FileExtMismatchSettings settings = FileExtMismatchSettings.readSettings();
94 editableMap = settings.getMimeTypeToExtsMap();
95 actions.add(
new AddFileExtensionAction(menuItemStr, extStr, mimeTypeStr, settings));
96 Set<String> editedExtensions = editableMap.get(mimeTypeStr);
97 if (editedExtensions.contains(extStr)) {
99 actions.get(0).setEnabled(
false);
101 }
catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
102 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
103 NbBundle.getMessage(this.getClass(),
"AddFileExtensionAction.msgDlg.msg2"),
104 NbBundle.getMessage(this.getClass(),
"AddFileExtensionAction.msgDlg.title"),
105 JOptionPane.ERROR_MESSAGE);
106 logger.log(Level.WARNING,
"File extension mismatch settings could not be read, extensions update not available.", ex);
static synchronized IngestManager getInstance()
boolean isIngestRunning()
synchronized static Logger getLogger(String name)