19package org.sleuthkit.autopsy.modules.hashdatabase;
21import java.awt.event.ActionEvent;
22import java.awt.event.ActionListener;
23import java.util.Collection;
24import java.util.HashSet;
26import java.util.logging.Level;
27import javax.swing.AbstractAction;
28import javax.swing.JMenu;
29import javax.swing.JMenuItem;
30import javax.swing.JOptionPane;
31import org.apache.commons.lang3.StringUtils;
32import org.openide.util.NbBundle;
33import org.openide.util.Utilities;
34import org.openide.util.actions.Presenter;
35import org.openide.windows.WindowManager;
36import org.sleuthkit.autopsy.coreutils.Logger;
37import org.sleuthkit.autopsy.ingest.IngestManager;
38import static org.sleuthkit.autopsy.modules.hashdatabase.HashDbManager.HashDb;
39import org.sleuthkit.datamodel.AbstractFile;
40import org.sleuthkit.datamodel.HashUtility;
41import org.sleuthkit.datamodel.TskCoreException;
51 "AddContentToHashDbAction.singleSelectionName");
53 "AddContentToHashDbAction.multipleSelectionName");
57 "AddContentToHashDbAction.singleSelectionNameDuringIngest");
59 "AddContentToHashDbAction.multipleSelectionNameDuringIngest");
63 "AddContentToHashDbAction.singleSelectionNameEmpty");
65 "AddContentToHashDbAction.multipleSelectionNameEmpty");
67 "AddContentToHashDbAction.singleSelectionNameNoMD5");
69 "AddContentToHashDbAction.multipleSelectionNameNoMD5");
115 private final class AddContentToHashDbMenu
extends JMenu {
123 AddContentToHashDbMenu(Collection<AbstractFile> selectedFiles) {
125 int numberOfFilesSelected = selectedFiles.size();
134 }
else if (numberOfFilesSelected == 0) {
144 for (AbstractFile file : selectedFiles) {
145 if (file.getSize() == 0) {
151 }
else if (
null == file.getMd5Hash() || StringUtils.isBlank(file.getMd5Hash())) {
164 JMenuItem newHashSetItem =
new JMenuItem(NbBundle.getMessage(
this.getClass(),
165 "AddContentToHashDbAction.ContentMenu.createDbItem"));
166 newHashSetItem.addActionListener(
new ActionListener() {
169 HashDb hashDb =
new HashDbCreateDatabaseDialog().getHashDatabase();
170 if (
null != hashDb) {
183 if (!hashDatabases.isEmpty()) {
184 for (
final HashDb database : hashDatabases) {
185 JMenuItem databaseItem = add(database.getHashSetName());
186 databaseItem.addActionListener(
new ActionListener() {
194 JMenuItem empty =
new JMenuItem(
195 NbBundle.getMessage(
this.getClass(),
196 "AddContentToHashDbAction.ContentMenu.noHashDbsConfigd"));
197 empty.setEnabled(
false);
208 this(
new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class)));
221 String singleSelection, String multiSelection) {
222 if (numberOfFilesSelected > 1) {
223 setText(multiSelection);
225 setText(singleSelection);
230 for (AbstractFile file : files) {
231 String md5Hash = file.getMd5Hash();
232 if (
null != md5Hash) {
234 if (HashUtility.isNoDataMd5(md5Hash)) {
236 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
237 NbBundle.getMessage(
this.getClass(),
238 "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileEmptyMsg",
240 NbBundle.getMessage(
this.getClass(),
241 "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr1.text"),
242 JOptionPane.ERROR_MESSAGE);
247 }
catch (TskCoreException ex) {
249 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
250 NbBundle.getMessage(
this.getClass(),
251 "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileMsg",
253 NbBundle.getMessage(
this.getClass(),
254 "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr2.text"),
255 JOptionPane.ERROR_MESSAGE);
258 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
259 NbBundle.getMessage(
this.getClass(),
260 "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileSzMsg",
261 files.size() > 1 ? NbBundle
262 .getMessage(
this.getClass(),
263 "AddContentToHashDbAction.addFilesToHashSet.files") : NbBundle
264 .getMessage(
this.getClass(),
265 "AddContentToHashDbAction.addFilesToHashSet.file")),
266 NbBundle.getMessage(
this.getClass(),
267 "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr3.text"),
268 JOptionPane.ERROR_MESSAGE);
synchronized static Logger getLogger(String name)
static synchronized IngestManager getInstance()
boolean isIngestRunning()
JMenuItem getPopupPresenter()
static final long serialVersionUID
static final String MULTI_SELECTION_NAME_EMPTY_FILE
static final String MULTI_SELECTION_NAME_NO_MD5
static final String SINGLE_SELECTION_NAME_DURING_INGEST
void actionPerformed(ActionEvent event)
AddContentToHashDbAction()
static AddContentToHashDbAction instance
static final String MULTI_SELECTION_NAME_DURING_INGEST
static final String SINGLE_SELECTION_NAME_NO_MD5
static synchronized AddContentToHashDbAction getInstance()
static final String SINGLE_SELECTION_NAME_EMPTY_FILE
static final String SINGLE_SELECTION_NAME
JMenuItem getMenuForFiles(Collection< AbstractFile > selectedFiles)
static final String MULTI_SELECTION_NAME
abstract void addHashes(Content content)
synchronized List< HashDb > getUpdateableHashSets()
static synchronized HashDbManager getInstance()