19 package org.sleuthkit.autopsy.modules.hashdatabase;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.AbstractAction;
27 import javax.swing.JMenu;
28 import javax.swing.JMenuItem;
29 import javax.swing.JOptionPane;
30 import org.openide.util.NbBundle;
31 import org.openide.util.Utilities;
32 import org.openide.util.actions.Presenter;
33 import org.openide.windows.WindowManager;
44 final class AddContentToHashDbAction
extends AbstractAction implements Presenter.Popup {
46 private static AddContentToHashDbAction instance;
47 private final static String SINGLE_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
48 "AddContentToHashDbAction.singleSelectionName");
49 private final static String MULTIPLE_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
50 "AddContentToHashDbAction.multipleSelectionName");
58 public static synchronized AddContentToHashDbAction getInstance() {
59 if (null == instance) {
60 instance =
new AddContentToHashDbAction();
65 private AddContentToHashDbAction() {
69 public JMenuItem getPopupPresenter() {
70 return new AddContentToHashDbMenu();
74 public void actionPerformed(ActionEvent event) {
82 super(SINGLE_SELECTION_NAME);
91 final Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
92 if (selectedFiles.isEmpty()) {
95 }
else if (selectedFiles.size() > 1) {
96 setText(MULTIPLE_SELECTION_NAME);
100 for (AbstractFile file : selectedFiles) {
101 if (null == file.getMd5Hash()) {
111 if (!hashDatabases.isEmpty()) {
112 for (
final HashDb database : hashDatabases) {
113 JMenuItem databaseItem = add(database.getHashSetName());
114 databaseItem.addActionListener(
new ActionListener() {
116 public void actionPerformed(ActionEvent e) {
122 JMenuItem empty =
new JMenuItem(
123 NbBundle.getMessage(
this.getClass(),
124 "AddContentToHashDbAction.ContentMenu.noHashDbsConfigd"));
125 empty.setEnabled(
false);
133 JMenuItem newHashSetItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
134 "AddContentToHashDbAction.ContentMenu.createDbItem"));
135 newHashSetItem.addActionListener(
new ActionListener() {
137 public void actionPerformed(ActionEvent e) {
138 HashDb hashDb =
new HashDbCreateDatabaseDialog().getHashDatabase();
139 if (null != hashDb) {
148 for (AbstractFile file : files) {
149 String md5Hash = file.getMd5Hash();
150 if (null != md5Hash) {
152 if (HashUtility.isNoDataMd5(md5Hash)) {
153 Logger.
getLogger(AddContentToHashDbAction.class.getName()).log(Level.INFO,
"Not adding " + file.getName() +
" to hash set (empty content)");
154 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
155 NbBundle.getMessage(this.getClass(),
156 "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileEmptyMsg",
158 NbBundle.getMessage(
this.getClass(),
159 "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr1.text"),
160 JOptionPane.ERROR_MESSAGE);
165 }
catch (TskCoreException ex) {
166 Logger.
getLogger(AddContentToHashDbAction.class.getName()).log(Level.SEVERE,
"Error adding to hash set", ex);
167 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
168 NbBundle.getMessage(this.getClass(),
169 "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileMsg",
171 NbBundle.getMessage(
this.getClass(),
172 "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr2.text"),
173 JOptionPane.ERROR_MESSAGE);
176 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
177 NbBundle.getMessage(this.getClass(),
178 "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileSzMsg",
179 files.size() > 1 ? NbBundle
180 .getMessage(this.getClass(),
181 "AddContentToHashDbAction.addFilesToHashSet.files") : NbBundle
182 .getMessage(this.getClass(),
183 "AddContentToHashDbAction.addFilesToHashSet.file")),
184 NbBundle.getMessage(
this.getClass(),
185 "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr3.text"),
186 JOptionPane.ERROR_MESSAGE);
static synchronized IngestManager getInstance()
boolean isIngestRunning()
static synchronized HashDbManager getInstance()
synchronized List< HashDb > getUpdateableHashSets()
synchronized static Logger getLogger(String name)
abstract void addHashes(Content content)