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

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