Autopsy  4.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-2016 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;
30 import org.sleuthkit.datamodel.BlackboardArtifact;
31 import org.sleuthkit.datamodel.TagName;
32 import org.sleuthkit.datamodel.TskCoreException;
33 
37 public class AddBlackboardArtifactTagAction extends AddTagAction {
38 
39  // This class is a singleton to support multi-selection of nodes, since
40  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
41  // node in the array returns a reference to the same action object from Node.getActions(boolean).
43 
44  public static synchronized AddBlackboardArtifactTagAction getInstance() {
45  if (null == instance) {
46  instance = new AddBlackboardArtifactTagAction();
47  }
48  return instance;
49  }
50 
52  super("");
53  }
54 
55  @Override
56  protected String getActionDisplayName() {
57  String singularTagResult = NbBundle.getMessage(this.getClass(),
58  "AddBlackboardArtifactTagAction.singularTagResult");
59  String pluralTagResult = NbBundle.getMessage(this.getClass(),
60  "AddBlackboardArtifactTagAction.pluralTagResult");
61  return Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class).size() > 1 ? pluralTagResult : singularTagResult;
62  }
63 
64  @Override
65  protected void addTag(TagName tagName, String comment) {
66  /*
67  * The documentation for Lookup.lookupAll() explicitly says that the
68  * collection it returns may contain duplicates. Within this invocation
69  * of addTag(), we don't want to tag the same BlackboardArtifact more
70  * than once, so we dedupe the BlackboardArtifacts by stuffing them into
71  * a HashSet.
72  */
73  final Collection<BlackboardArtifact> selectedArtifacts = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class));
74 
75  new Thread(() -> {
76  for (BlackboardArtifact artifact : selectedArtifacts) {
77  try {
78  Case.getCurrentCase().getServices().getTagsManager().addBlackboardArtifactTag(artifact, tagName, comment);
79  } catch (TskCoreException ex) {
80  Logger.getLogger(AddBlackboardArtifactTagAction.class.getName()).log(Level.SEVERE, "Error tagging result", ex); //NON-NLS
81  SwingUtilities.invokeLater(() -> {
82  JOptionPane.showMessageDialog(null,
83  NbBundle.getMessage(this.getClass(),
84  "AddBlackboardArtifactTagAction.unableToTag.msg",
85  artifact.getDisplayName()),
86  NbBundle.getMessage(this.getClass(),
87  "AddBlackboardArtifactTagAction.taggingErr"),
88  JOptionPane.ERROR_MESSAGE);
89  });
90  break;
91  }
92  }
93  }).start();
94  }
95 }
static synchronized AddBlackboardArtifactTagAction getInstance()
synchronized BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.