Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddFileExtensionAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.awt.event.ActionEvent;
22 import java.util.HashMap;
23 import java.util.Set;
24 import java.util.logging.Level;
25 import javax.swing.AbstractAction;
26 import javax.swing.JOptionPane;
27 import org.openide.util.NbBundle;
28 import org.openide.util.NbBundle.Messages;
29 import org.openide.windows.WindowManager;
31 
36 class AddFileExtensionAction extends AbstractAction {
37 
38  private static final long serialVersionUID = 1L;
39  private static final Logger logger = Logger.getLogger(AddFileExtensionAction.class.getName());
40  private final String extStr;
41  private final String mimeTypeStr;
42  private final FileExtMismatchSettings settings;
43 
44  AddFileExtensionAction(String menuItemStr, String extStr, String mimeTypeStr, FileExtMismatchSettings settings) {
45  super(menuItemStr);
46  this.mimeTypeStr = mimeTypeStr;
47  this.extStr = extStr;
48  this.settings = settings;
49  }
50 
51  @Override
52  @Messages({"AddFileExtensionAction.writeError.message=Could not write file extension settings."})
53  public void actionPerformed(ActionEvent event) {
54  HashMap<String, Set<String>> editableMap;
55  editableMap = settings.getMimeTypeToExtsMap();
56  Set<String> editedExtensions = editableMap.get(mimeTypeStr);
57  editedExtensions.add(extStr);
58 
59  try {
60  FileExtMismatchSettings.writeSettings(new FileExtMismatchSettings(editableMap));
61  } catch (FileExtMismatchSettings.FileExtMismatchSettingsException ex) {
62  //error
63  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
64  Bundle.AddFileExtensionAction_writeError_message(),
65  NbBundle.getMessage(this.getClass(), "AddFileExtensionAction.msgDlg.title"),
66  JOptionPane.ERROR_MESSAGE);
67  logger.log(Level.SEVERE, "Could not write file extension settings.", ex);
68  }
69  }
70 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.