Autopsy  4.16.0
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-2019 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.Content;
34 import org.sleuthkit.datamodel.TagName;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
40 @NbBundle.Messages({
41  "AddBlackboardArtifactTagAction.singularTagResult=Add Result Tag",
42  "AddBlackboardArtifactTagAction.pluralTagResult=Add Result Tags",
43  "# {0} - artifactName",
44  "AddBlackboardArtifactTagAction.unableToTag.msg=Unable to tag {0}.",
45  "AddBlackboardArtifactTagAction.taggingErr=Tagging Error"
46 })
47 public class AddBlackboardArtifactTagAction extends AddTagAction {
48 
49  // This class is a singleton to support multi-selection of nodes, since
50  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
51  // node in the array returns a reference to the same action object from Node.getActions(boolean).
53 
54  public static synchronized AddBlackboardArtifactTagAction getInstance() {
55  if (null == instance) {
56  instance = new AddBlackboardArtifactTagAction();
57  }
58  return instance;
59  }
60 
62  super("");
63  }
64 
65  @Override
66  protected String getActionDisplayName() {
67  String singularTagResult = NbBundle.getMessage(this.getClass(),
68  "AddBlackboardArtifactTagAction.singularTagResult");
69  String pluralTagResult = NbBundle.getMessage(this.getClass(),
70  "AddBlackboardArtifactTagAction.pluralTagResult");
71  return Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class).size() > 1 ? pluralTagResult : singularTagResult;
72  }
73 
74  @Override
75  protected void addTag(TagName tagName, String comment) {
76  final Collection<BlackboardArtifact> selectedArtifacts = new HashSet<>();
77  //If the contentToTag is empty look up the selected content
78  if (getContentToTag().isEmpty()) {
79  /*
80  * The documentation for Lookup.lookupAll() explicitly says that the
81  * collection it returns may contain duplicates. Within this
82  * invocation of addTag(), we don't want to tag the same
83  * BlackboardArtifact more than once, so we dedupe the
84  * BlackboardArtifacts by stuffing them into a HashSet.
85  */
86  selectedArtifacts.addAll(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
87  } else {
88  for (Content content : getContentToTag()) {
89  if (content instanceof BlackboardArtifact) {
90  selectedArtifacts.add((BlackboardArtifact) content);
91  }
92  }
93  }
94  new Thread(() -> {
95  for (BlackboardArtifact artifact : selectedArtifacts) {
96  try {
98  } catch (TskCoreException | NoCurrentCaseException ex) {
99  Logger.getLogger(AddBlackboardArtifactTagAction.class.getName()).log(Level.SEVERE, "Error tagging result", ex); //NON-NLS
100  SwingUtilities.invokeLater(() -> {
101  JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
102  NbBundle.getMessage(this.getClass(),
103  "AddBlackboardArtifactTagAction.unableToTag.msg",
104  artifact.getDisplayName()),
105  NbBundle.getMessage(this.getClass(),
106  "AddBlackboardArtifactTagAction.taggingErr"),
107  JOptionPane.ERROR_MESSAGE);
108  });
109  break;
110  }
111  }
112  }).start();
113  }
114 }
static synchronized AddBlackboardArtifactTagAction getInstance()
BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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