Autopsy  4.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 2014 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 org.openide.util.NbBundle;
22 import java.awt.event.ActionEvent;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.HashMap;
26 import javax.swing.AbstractAction;
27 import javax.swing.JOptionPane;
28 
33 class AddFileExtensionAction extends AbstractAction {
34 
35  private String extStr;
36  private String mimeTypeStr;
37 
38  public AddFileExtensionAction(String menuItemStr, String extStr, String mimeTypeStr) {
39  super(menuItemStr);
40  this.mimeTypeStr = mimeTypeStr;
41  this.extStr = extStr;
42  }
43 
44  @Override
45  public void actionPerformed(ActionEvent event) {
46  HashMap<String, String[]> editableMap = FileExtMismatchXML.getDefault().load();
47  ArrayList<String> editedExtensions = new ArrayList<>(Arrays.asList(editableMap.get(mimeTypeStr)));
48  editedExtensions.add(extStr);
49 
50  // Old array will be replaced by new array for this key
51  editableMap.put(mimeTypeStr, editedExtensions.toArray(new String[0]));
52 
53  if (!FileExtMismatchXML.getDefault().save(editableMap)) {
54  //error
55  JOptionPane.showMessageDialog(null,
56  NbBundle.getMessage(this.getClass(), "AddFileExtensionAction.msgDlg.msg"),
57  NbBundle.getMessage(this.getClass(), "AddFileExtensionAction.msgDlg.title"),
58  JOptionPane.ERROR_MESSAGE);
59  } // else //in the future we might want to update the statusbar to give feedback to the user
60  }
61 }

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