Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CaseOpenAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.casemodule;
20 
21 import java.awt.Component;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.File;
25 import java.util.logging.Level;
26 import javax.swing.JFileChooser;
27 import javax.swing.JOptionPane;
28 import javax.swing.filechooser.FileFilter;
29 import javax.swing.filechooser.FileNameExtensionFilter;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.ServiceProvider;
35 
39 @ServiceProvider(service = CaseOpenAction.class)
40 public final class CaseOpenAction implements ActionListener {
41 
42  private static final Logger logger = Logger.getLogger(CaseOpenAction.class.getName());
43  private static final String PROP_BASECASE = "LBL_BaseCase_PATH"; //NON-NLS
44  private final JFileChooser fc = new JFileChooser();
45  private FileFilter autFilter;
46 
50  public CaseOpenAction() {
51  autFilter = new FileNameExtensionFilter(
52  NbBundle.getMessage(CaseOpenAction.class, "CaseOpenAction.autFilter.title", Version.getName(),
53  Case.CASE_DOT_EXTENSION),
54  Case.CASE_EXTENSION);
55  fc.setDragEnabled(false);
56  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
57  fc.setMultiSelectionEnabled(false);
58  fc.setFileFilter(autFilter);
59  try {
60  if (ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE) != null) {
61  fc.setCurrentDirectory(new File(ModuleSettings.getConfigSetting("Case", PROP_BASECASE))); //NON-NLS
62  }
63  } catch (Exception e) {
64  }
65  }
66 
72  @Override
73  public void actionPerformed(ActionEvent e) {
74  int retval = fc.showOpenDialog((Component) e.getSource());
75 
76  if (retval == JFileChooser.APPROVE_OPTION) {
77  String path = fc.getSelectedFile().getPath();
78  String dirPath = fc.getSelectedFile().getParent();
79  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, dirPath.substring(0, dirPath.lastIndexOf(File.separator)));
80  // check if the file exists
81  if (!new File(path).exists()) {
82  JOptionPane.showMessageDialog(null,
83  NbBundle.getMessage(this.getClass(),
84  "CaseOpenAction.msgDlg.fileNotExist.msg"),
85  NbBundle.getMessage(this.getClass(),
86  "CaseOpenAction.msgDlg.fileNotExist.title"),
87  JOptionPane.ERROR_MESSAGE);
88  this.actionPerformed(e); // show the dialog box again
89  } else {
90  // try to close Startup window if there's one
91  try {
93  } catch (Exception ex) {
94  // no need to show the error message to the user.
95  logger.log(Level.WARNING, "Error closing startup window.", ex); //NON-NLS
96  }
97  try {
98  Case.open(path); // open the case
99  } catch (CaseActionException ex) {
100  JOptionPane.showMessageDialog(null,
101  NbBundle.getMessage(this.getClass(),
102  "CaseOpenAction.msgDlg.cantOpenCase.msg", path,
103  ex.getMessage()),
104  NbBundle.getMessage(this.getClass(),
105  "CaseOpenAction.msgDlg.cantOpenCase.title"),
106  JOptionPane.ERROR_MESSAGE);
107  logger.log(Level.WARNING, "Error opening case in folder " + path, ex); //NON-NLS
108 
110  }
111  }
112  }
113  }
114 }
static void open(String configFilePath)
Definition: Case.java:318
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static String getConfigSetting(String moduleName, String settingName)
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.