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.apache.commons.lang3.StringUtils;
 
   31 import org.openide.util.NbBundle;
 
   32 import org.openide.util.Utilities;
 
   33 import org.openide.util.actions.Presenter;
 
   34 import org.openide.windows.WindowManager;
 
   45 final class AddContentToHashDbAction 
extends AbstractAction implements Presenter.Popup {
 
   47     private static AddContentToHashDbAction instance;
 
   49     private final static String SINGLE_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   50             "AddContentToHashDbAction.singleSelectionName");
 
   51     private final static String MULTI_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   52             "AddContentToHashDbAction.multipleSelectionName");
 
   55     private final static String SINGLE_SELECTION_NAME_DURING_INGEST = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   56             "AddContentToHashDbAction.singleSelectionNameDuringIngest");
 
   57     private final static String MULTI_SELECTION_NAME_DURING_INGEST = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   58             "AddContentToHashDbAction.multipleSelectionNameDuringIngest");
 
   61     private final static String SINGLE_SELECTION_NAME_EMPTY_FILE = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   62             "AddContentToHashDbAction.singleSelectionNameEmpty");
 
   63     private final static String MULTI_SELECTION_NAME_EMPTY_FILE = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   64             "AddContentToHashDbAction.multipleSelectionNameEmpty");
 
   65     private final static String SINGLE_SELECTION_NAME_NO_MD5 = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   66             "AddContentToHashDbAction.singleSelectionNameNoMD5");
 
   67     private final static String MULTI_SELECTION_NAME_NO_MD5 = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   68             "AddContentToHashDbAction.multipleSelectionNameNoMD5");
 
   76     public static synchronized AddContentToHashDbAction getInstance() {
 
   77         if (null == instance) {
 
   78             instance = 
new AddContentToHashDbAction();
 
   83     private AddContentToHashDbAction() {
 
   87     public JMenuItem getPopupPresenter() {
 
   88         return new AddContentToHashDbMenu();
 
   92     public void actionPerformed(ActionEvent event) {
 
  100             super(SINGLE_SELECTION_NAME);
 
  102             final Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
 
  103             int numberOfFilesSelected = selectedFiles.size();
 
  109                         SINGLE_SELECTION_NAME_DURING_INGEST,
 
  110                         MULTI_SELECTION_NAME_DURING_INGEST);
 
  114             if (selectedFiles.isEmpty()) {
 
  119                         SINGLE_SELECTION_NAME,
 
  120                         MULTI_SELECTION_NAME);
 
  125             for (AbstractFile file : selectedFiles) {
 
  126                 if (file.getSize() == 0) {
 
  129                             SINGLE_SELECTION_NAME_EMPTY_FILE,
 
  130                             MULTI_SELECTION_NAME_EMPTY_FILE);
 
  132                 } 
else if (null == file.getMd5Hash() || StringUtils.isBlank(file.getMd5Hash())) {
 
  135                             SINGLE_SELECTION_NAME_NO_MD5,
 
  136                             MULTI_SELECTION_NAME_NO_MD5);
 
  145             if (!hashDatabases.isEmpty()) {
 
  146                 for (
final HashDb database : hashDatabases) {
 
  147                     JMenuItem databaseItem = add(database.getHashSetName());
 
  148                     databaseItem.addActionListener(
new ActionListener() {
 
  150                         public void actionPerformed(ActionEvent e) {
 
  156                 JMenuItem empty = 
new JMenuItem(
 
  157                         NbBundle.getMessage(
this.getClass(),
 
  158                                 "AddContentToHashDbAction.ContentMenu.noHashDbsConfigd"));
 
  159                 empty.setEnabled(
false);
 
  167             JMenuItem newHashSetItem = 
new JMenuItem(NbBundle.getMessage(
this.getClass(),
 
  168                     "AddContentToHashDbAction.ContentMenu.createDbItem"));
 
  169             newHashSetItem.addActionListener(
new ActionListener() {
 
  171                 public void actionPerformed(ActionEvent e) {
 
  172                     HashDb hashDb = 
new HashDbCreateDatabaseDialog().getHashDatabase();
 
  173                     if (null != hashDb) {
 
  190                 String singleSelection, String multiSelection) {
 
  191             if (numberOfFilesSelected > 1) {
 
  192                 setText(multiSelection);
 
  194                 setText(singleSelection);
 
  199             for (AbstractFile file : files) {
 
  200                 String md5Hash = file.getMd5Hash();
 
  201                 if (null != md5Hash) {
 
  203                     if (HashUtility.isNoDataMd5(md5Hash)) { 
 
  204                         Logger.
getLogger(AddContentToHashDbAction.class.getName()).log(Level.INFO, 
"Not adding " + file.getName() + 
" to hash set (empty content)"); 
 
  205                         JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
 
  206                                 NbBundle.getMessage(this.getClass(),
 
  207                                         "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileEmptyMsg",
 
  209                                 NbBundle.getMessage(
this.getClass(),
 
  210                                         "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr1.text"),
 
  211                                 JOptionPane.ERROR_MESSAGE);
 
  216                     } 
catch (TskCoreException ex) {
 
  217                         Logger.
getLogger(AddContentToHashDbAction.class.getName()).log(Level.SEVERE, 
"Error adding to hash set", ex); 
 
  218                         JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
 
  219                                 NbBundle.getMessage(this.getClass(),
 
  220                                         "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileMsg",
 
  222                                 NbBundle.getMessage(
this.getClass(),
 
  223                                         "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr2.text"),
 
  224                                 JOptionPane.ERROR_MESSAGE);
 
  227                     JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
 
  228                             NbBundle.getMessage(this.getClass(),
 
  229                                     "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileSzMsg",
 
  230                                     files.size() > 1 ? NbBundle
 
  231                                     .getMessage(this.getClass(),
 
  232                                             "AddContentToHashDbAction.addFilesToHashSet.files") : NbBundle
 
  233                                             .getMessage(this.getClass(),
 
  234                                                     "AddContentToHashDbAction.addFilesToHashSet.file")),
 
  235                             NbBundle.getMessage(
this.getClass(),
 
  236                                     "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr3.text"),
 
  237                             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)