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;
 
   43 final class AddContentToHashDbAction 
extends AbstractAction implements Presenter.Popup {
 
   45     private static AddContentToHashDbAction instance;
 
   46     private final static String SINGLE_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   47             "AddContentToHashDbAction.singleSelectionName");
 
   48     private final static String MULTIPLE_SELECTION_NAME = NbBundle.getMessage(AddContentToHashDbAction.class,
 
   49             "AddContentToHashDbAction.multipleSelectionName");
 
   57     public static synchronized AddContentToHashDbAction getInstance() {
 
   58         if (null == instance) {
 
   59             instance = 
new AddContentToHashDbAction();
 
   64     private AddContentToHashDbAction() {
 
   68     public JMenuItem getPopupPresenter() {
 
   69         return new AddContentToHashDbMenu();
 
   73     public void actionPerformed(ActionEvent event) {
 
   81             super(SINGLE_SELECTION_NAME);
 
   90             final Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
 
   91             if (selectedFiles.isEmpty()) {
 
   94             } 
else if (selectedFiles.size() > 1) {
 
   95                 setText(MULTIPLE_SELECTION_NAME);
 
   99             for (AbstractFile file : selectedFiles) {
 
  100                 if (null == file.getMd5Hash()) {
 
  110             if (!hashDatabases.isEmpty()) {
 
  111                 for (
final HashDb database : hashDatabases) {
 
  112                     JMenuItem databaseItem = add(database.getHashSetName());
 
  113                     databaseItem.addActionListener(
new ActionListener() {
 
  115                         public void actionPerformed(ActionEvent e) {
 
  121                 JMenuItem empty = 
new JMenuItem(
 
  122                         NbBundle.getMessage(
this.getClass(),
 
  123                                 "AddContentToHashDbAction.ContentMenu.noHashDbsConfigd"));
 
  124                 empty.setEnabled(
false);
 
  132             JMenuItem newHashSetItem = 
new JMenuItem(NbBundle.getMessage(
this.getClass(),
 
  133                     "AddContentToHashDbAction.ContentMenu.createDbItem"));
 
  134             newHashSetItem.addActionListener(
new ActionListener() {
 
  136                 public void actionPerformed(ActionEvent e) {
 
  137                     HashDb hashDb = 
new HashDbCreateDatabaseDialog().getHashDatabase();
 
  138                     if (null != hashDb) {
 
  147             for (AbstractFile file : files) {
 
  148                 String md5Hash = file.getMd5Hash();
 
  149                 if (null != md5Hash) {
 
  151                     if (HashUtility.isNoDataMd5(md5Hash)) { 
 
  152                         Logger.
getLogger(AddContentToHashDbAction.class.getName()).log(Level.INFO, 
"Not adding " + file.getName() + 
" to database (empty content)"); 
 
  153                         JOptionPane.showMessageDialog(null,
 
  154                                 NbBundle.getMessage(
this.getClass(),
 
  155                                         "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileEmptyMsg",
 
  157                                 NbBundle.getMessage(
this.getClass(),
 
  158                                         "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr1.text"),
 
  159                                 JOptionPane.ERROR_MESSAGE);
 
  164                     } 
catch (TskCoreException ex) {
 
  165                         Logger.
getLogger(AddContentToHashDbAction.class.getName()).log(Level.SEVERE, 
"Error adding to hash database", ex); 
 
  166                         JOptionPane.showMessageDialog(null,
 
  167                                 NbBundle.getMessage(
this.getClass(),
 
  168                                         "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileMsg",
 
  170                                 NbBundle.getMessage(
this.getClass(),
 
  171                                         "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr2.text"),
 
  172                                 JOptionPane.ERROR_MESSAGE);
 
  175                     JOptionPane.showMessageDialog(null,
 
  176                             NbBundle.getMessage(
this.getClass(),
 
  177                                     "AddContentToHashDbAction.addFilesToHashSet.unableToAddFileSzMsg",
 
  178                                     files.size() > 1 ? NbBundle
 
  179                                             .getMessage(this.getClass(),
 
  180                                                     "AddContentToHashDbAction.addFilesToHashSet.files") : NbBundle
 
  181                                             .getMessage(this.getClass(),
 
  182                                                     "AddContentToHashDbAction.addFilesToHashSet.file")),
 
  183                             NbBundle.getMessage(
this.getClass(),
 
  184                                     "AddContentToHashDbAction.addFilesToHashSet.addToHashDbErr3.text"),
 
  185                             JOptionPane.ERROR_MESSAGE);
 
static synchronized IngestManager getInstance()
boolean isIngestRunning()
static synchronized HashDbManager getInstance()
void addHashes(Content content)
synchronized List< HashDb > getUpdateableHashSets()
synchronized static Logger getLogger(String name)