Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileExtMismatchContextMenuActionsProvider.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.fileextmismatch;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Set;
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;
37 
42 @ServiceProvider(service = ContextMenuActionsProvider.class)
44  private static final Logger logger = Logger.getLogger(FileExtMismatchContextMenuActionsProvider.class.getName());
45 
46  @Override
47  public List<Action> getActions() {
48  ArrayList<Action> actions = new ArrayList<>();
49 
50  // Ignore if file ingest is in progress.
52 
53  final Collection<? extends BlackboardArtifact> selectedArts = Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class);
54 
55  // Prevent multiselect
56  if (selectedArts.size() == 1) {
57 
58  for (BlackboardArtifact nodeArt : selectedArts) {
59 
60  // Only for mismatch results
61  if (nodeArt.getArtifactTypeName().equals("TSK_EXT_MISMATCH_DETECTED")) { //NON-NLS
62  String mimeTypeStr = "";
63  String extStr = "";
64 
65  AbstractFile af = Utilities.actionsGlobalContext().lookup(AbstractFile.class);
66 
67  if (af != null) {
68  int i = af.getName().lastIndexOf(".");
69  if ((i > -1) && ((i + 1) < af.getName().length())) {
70  extStr = af.getName().substring(i + 1).toLowerCase();
71  }
72  mimeTypeStr = af.getMIMEType();
73  if (mimeTypeStr == null) {
74  mimeTypeStr = "";
75  }
76 
77  if (!extStr.isEmpty() && !mimeTypeStr.isEmpty()) {
78  // Limit max size so the context window doesn't get ridiculously wide
79  if (extStr.length() > 10) {
80  extStr = extStr.substring(0, 9);
81  }
82  if (mimeTypeStr.length() > 40) {
83  mimeTypeStr = mimeTypeStr.substring(0, 39);
84  }
85  String menuItemStr = NbBundle.getMessage(this.getClass(),
86  "FileExtMismatchContextMenuActionsProvider.menuItemStr",
87  extStr, mimeTypeStr);
88 
89  // Check if already added
90  HashMap<String, Set<String>> editableMap;
91  try {
92  FileExtMismatchSettings settings = FileExtMismatchSettings.readSettings();
93  editableMap = settings.getMimeTypeToExtsMap();
94  actions.add(new AddFileExtensionAction(menuItemStr, extStr, mimeTypeStr, settings));
95  Set<String> editedExtensions = editableMap.get(mimeTypeStr);
96  if (editedExtensions.contains(extStr)) {
97  // Informs the user that they have already added this extension to this MIME type
98  actions.get(0).setEnabled(false);
99  }
100  } catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
101  JOptionPane.showMessageDialog(null,
102  NbBundle.getMessage(this.getClass(), "AddFileExtensionAction.msgDlg.msg2"),
103  NbBundle.getMessage(this.getClass(), "AddFileExtensionAction.msgDlg.title"),
104  JOptionPane.ERROR_MESSAGE);
105  logger.log(Level.WARNING, "File extension mismatch settings could not be read, extensions update not available.", ex);
106  }
107  }
108  }
109  }
110  }
111  }
112  }
113 
114  return actions;
115  }
116 }
static synchronized IngestManager getInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.