Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddContentTagAction.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2015 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.logging.Level;
23 import javax.swing.JOptionPane;
24 import javax.swing.SwingUtilities;
25 import org.openide.util.NbBundle;
26 import org.openide.util.Utilities;
30 import org.sleuthkit.datamodel.AbstractFile;
31 import org.sleuthkit.datamodel.Content;
32 import org.sleuthkit.datamodel.TagName;
33 import org.sleuthkit.datamodel.TskCoreException;
34 
38 public class AddContentTagAction extends AddTagAction {
39 
40  // This class is a singleton to support multi-selection of nodes, since
41  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
42  // node in the array returns a reference to the same action object from Node.getActions(boolean).
43 
44  private static AddContentTagAction instance;
45 
46  public static synchronized AddContentTagAction getInstance() {
47  if (null == instance) {
48  instance = new AddContentTagAction();
49  }
50  return instance;
51  }
52 
53  private AddContentTagAction() {
54  super("");
55  }
56 
57  @Override
58  protected String getActionDisplayName() {
59  String singularTagFile = NbBundle.getMessage(this.getClass(), "AddContentTagAction.singularTagFile");
60  String pluralTagFile = NbBundle.getMessage(this.getClass(), "AddContentTagAction.pluralTagFile");
61  return Utilities.actionsGlobalContext().lookupAll(AbstractFile.class).size() > 1 ? pluralTagFile : singularTagFile;
62  }
63 
64  @Override
65  protected void addTag(TagName tagName, String comment) {
66  final Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
67 
68  new Thread(() -> {
69  for (AbstractFile file : selectedFiles) {
70  try {
71  // Handle the special cases of current (".") and parent ("..") directory entries.
72  if (file.getName().equals(".")) {
73  Content parentFile = file.getParent();
74  if (parentFile instanceof AbstractFile) {
75  file = (AbstractFile) parentFile;
76  } else {
77  SwingUtilities.invokeLater(() -> {
78  JOptionPane.showMessageDialog(null,
79  NbBundle.getMessage(this.getClass(),
80  "AddContentTagAction.unableToTag.msg",
81  parentFile.getName()),
82  NbBundle.getMessage(this.getClass(),
83  "AddContentTagAction.cannotApplyTagErr"),
84  JOptionPane.WARNING_MESSAGE);
85  });
86  continue;
87  }
88  } else if (file.getName().equals("..")) {
89  Content parentFile = file.getParent();
90  if (parentFile instanceof AbstractFile) {
91  parentFile = (AbstractFile) ((AbstractFile) parentFile).getParent();
92  if (parentFile instanceof AbstractFile) {
93  file = (AbstractFile) parentFile;
94  } else {
95  final Content parentFileCopy = parentFile;
96  SwingUtilities.invokeLater(() -> {
97  JOptionPane.showMessageDialog(null,
98  NbBundle.getMessage(this.getClass(),
99  "AddContentTagAction.unableToTag.msg",
100  parentFileCopy.getName()),
101  NbBundle.getMessage(this.getClass(),
102  "AddContentTagAction.cannotApplyTagErr"),
103  JOptionPane.WARNING_MESSAGE);
104  });
105  continue;
106  }
107  } else {
108  final Content parentFileCopy = parentFile;
109  SwingUtilities.invokeLater(() -> {
110  JOptionPane.showMessageDialog(null,
111  NbBundle.getMessage(this.getClass(),
112  "AddContentTagAction.unableToTag.msg",
113  parentFileCopy.getName()),
114  NbBundle.getMessage(this.getClass(),
115  "AddContentTagAction.cannotApplyTagErr"),
116  JOptionPane.WARNING_MESSAGE);
117  });
118  continue;
119  }
120  }
121 
122  Case.getCurrentCase().getServices().getTagsManager().addContentTag(file, tagName, comment);
123  } catch (TskCoreException ex) {
124  Logger.getLogger(AddContentTagAction.class.getName()).log(Level.SEVERE, "Error tagging result", ex); //NON-NLS
125  AbstractFile fileCopy = file;
126  SwingUtilities.invokeLater(() -> {
127  JOptionPane.showMessageDialog(null,
128  NbBundle.getMessage(this.getClass(),
129  "AddContentTagAction.unableToTag.msg2",
130  fileCopy.getName()),
131  NbBundle.getMessage(this.getClass(), "AddContentTagAction.taggingErr"),
132  JOptionPane.ERROR_MESSAGE);
133  });
134  }
135  }
136  }).start();
137  }
138 }
ContentTag addContentTag(Content content, TagName tagName)
void addTag(TagName tagName, String comment)
synchronized static Logger getLogger(String name)
Definition: Logger.java:166
static synchronized AddContentTagAction getInstance()

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.