Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddBlackboardArtifactTagAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.actions;
20 
21 import java.util.Collection;
22 import java.util.HashSet;
23 import java.util.logging.Level;
24 import javax.swing.JOptionPane;
25 import javax.swing.SwingUtilities;
26 import org.openide.util.NbBundle;
27 import org.openide.util.Utilities;
28 import org.openide.windows.WindowManager;
32 import org.sleuthkit.datamodel.BlackboardArtifact;
33 import org.sleuthkit.datamodel.TagName;
34 import org.sleuthkit.datamodel.TskCoreException;
35 
39 @NbBundle.Messages({
40  "AddBlackboardArtifactTagAction.singularTagResult=Add Result Tag",
41  "AddBlackboardArtifactTagAction.pluralTagResult=Add Result Tags",
42  "# {0} - artifactName",
43  "AddBlackboardArtifactTagAction.unableToTag.msg=Unable to tag {0}.",
44  "AddBlackboardArtifactTagAction.taggingErr=Tagging Error"
45 })
46 public class AddBlackboardArtifactTagAction extends AddTagAction {
47 
48  // This class is a singleton to support multi-selection of nodes, since
49  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
50  // node in the array returns a reference to the same action object from Node.getActions(boolean).
52 
53  public static synchronized AddBlackboardArtifactTagAction getInstance() {
54  if (null == instance) {
55  instance = new AddBlackboardArtifactTagAction();
56  }
57  return instance;
58  }
59 
61  super("");
62  }
63 
64  @Override
65  protected String getActionDisplayName() {
66  String singularTagResult = NbBundle.getMessage(this.getClass(),
67  "AddBlackboardArtifactTagAction.singularTagResult");
68  String pluralTagResult = NbBundle.getMessage(this.getClass(),
69  "AddBlackboardArtifactTagAction.pluralTagResult");
70  return Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class).size() > 1 ? pluralTagResult : singularTagResult;
71  }
72 
73  @Override
74  protected void addTag(TagName tagName, String comment) {
75  /*
76  * The documentation for Lookup.lookupAll() explicitly says that the
77  * collection it returns may contain duplicates. Within this invocation
78  * of addTag(), we don't want to tag the same BlackboardArtifact more
79  * than once, so we dedupe the BlackboardArtifacts by stuffing them into
80  * a HashSet.
81  */
82  final Collection<BlackboardArtifact> selectedArtifacts = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
83 
84  new Thread(() -> {
85  for (BlackboardArtifact artifact : selectedArtifacts) {
86  try {
88  } catch (TskCoreException | NoCurrentCaseException ex) {
89  Logger.getLogger(AddBlackboardArtifactTagAction.class.getName()).log(Level.SEVERE, "Error tagging result", ex); //NON-NLS
90  SwingUtilities.invokeLater(() -> {
91  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
92  NbBundle.getMessage(this.getClass(),
93  "AddBlackboardArtifactTagAction.unableToTag.msg",
94  artifact.getDisplayName()),
95  NbBundle.getMessage(this.getClass(),
96  "AddBlackboardArtifactTagAction.taggingErr"),
97  JOptionPane.ERROR_MESSAGE);
98  });
99  break;
100  }
101  }
102  }).start();
103  }
104 }
static synchronized AddBlackboardArtifactTagAction getInstance()
BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.