Autopsy  3.1
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 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.List;
23 import java.util.logging.Level;
24 import javax.swing.JOptionPane;
25 
26 import org.openide.util.NbBundle;
27 import org.openide.util.Utilities;
37 
41 public class AddContentTagAction extends AddTagAction {
42  // This class is a singleton to support multi-selection of nodes, since
43  // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every
44  // node in the array returns a reference to the same action object from Node.getActions(boolean).
45  private static AddContentTagAction instance;
46 
47  public static synchronized AddContentTagAction getInstance() {
48  if (null == instance) {
49  instance = new AddContentTagAction();
50  }
51  return instance;
52  }
53 
54  private AddContentTagAction() {
55  super("");
56  }
57 
58  @Override
59  protected String getActionDisplayName() {
60  String singularTagFile = NbBundle.getMessage(this.getClass(), "AddContentTagAction.singularTagFile");
61  String pluralTagFile = NbBundle.getMessage(this.getClass(), "AddContentTagAction.pluralTagFile");
62  return Utilities.actionsGlobalContext().lookupAll(AbstractFile.class).size() > 1 ? pluralTagFile : singularTagFile;
63  }
64 
65  @Override
66  protected void addTag(TagName tagName, String comment) {
67  Collection<? extends AbstractFile> selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class);
68  for (AbstractFile file : selectedFiles) {
69  try {
70  // Handle the special cases of current (".") and parent ("..") directory entries.
71  if (file.getName().equals(".")) {
72  Content parentFile = file.getParent();
73  if (parentFile instanceof AbstractFile) {
74  file = (AbstractFile)parentFile;
75  }
76  else {
77  JOptionPane.showMessageDialog(null,
78  NbBundle.getMessage(this.getClass(),
79  "AddContentTagAction.unableToTag.msg",
80  parentFile.getName()),
81  NbBundle.getMessage(this.getClass(),
82  "AddContentTagAction.cannotApplyTagErr"),
83  JOptionPane.WARNING_MESSAGE);
84  continue;
85  }
86  }
87  else if (file.getName().equals("..")) {
88  Content parentFile = file.getParent();
89  if (parentFile instanceof AbstractFile) {
90  parentFile = (AbstractFile)((AbstractFile)parentFile).getParent();
91  if (parentFile instanceof AbstractFile) {
92  file = (AbstractFile)parentFile;
93  }
94  else {
95  JOptionPane.showMessageDialog(null,
96  NbBundle.getMessage(this.getClass(),
97  "AddContentTagAction.unableToTag.msg",
98  parentFile.getName()),
99  NbBundle.getMessage(this.getClass(),
100  "AddContentTagAction.cannotApplyTagErr"),
101  JOptionPane.WARNING_MESSAGE);
102  continue;
103  }
104  }
105  else {
106  JOptionPane.showMessageDialog(null,
107  NbBundle.getMessage(this.getClass(),
108  "AddContentTagAction.unableToTag.msg",
109  parentFile.getName()),
110  NbBundle.getMessage(this.getClass(),
111  "AddContentTagAction.cannotApplyTagErr"),
112  JOptionPane.WARNING_MESSAGE);
113  continue;
114  }
115  }
116  // check if the same tag is being added for the same abstract file.
118  List<ContentTag> contentTagList = tagsManager.getContentTagsByContent(file);
119  for (ContentTag contentTag : contentTagList) {
120  if (contentTag.getName().getDisplayName().equals(tagName.getDisplayName())) {
121  JOptionPane.showMessageDialog(null,
122  NbBundle.getMessage(this.getClass(),
123  "AddContentTagAction.tagExists",
124  file.getName(), tagName.getDisplayName()),
125  NbBundle.getMessage(this.getClass(),
126  "AddContentTagAction.cannotApplyTagErr"),
127  JOptionPane.WARNING_MESSAGE);
128  return;
129  }
130  }
131  tagsManager.addContentTag(file, tagName, comment);
132  }
133  catch (TskCoreException ex) {
134  Logger.getLogger(AddContentTagAction.class.getName()).log(Level.SEVERE, "Error tagging result", ex); //NON-NLS
135  JOptionPane.showMessageDialog(null,
136  NbBundle.getMessage(this.getClass(),
137  "AddContentTagAction.unableToTag.msg2",
138  file.getName()),
139  NbBundle.getMessage(this.getClass(), "AddContentTagAction.taggingErr"),
140  JOptionPane.ERROR_MESSAGE);
141  }
142  }
143  }
144 }
ContentTag addContentTag(Content content, TagName tagName)
void addTag(TagName tagName, String comment)
synchronized List< ContentTag > getContentTagsByContent(Content content)
static Logger getLogger(String name)
Definition: Logger.java:131
static synchronized AddContentTagAction getInstance()

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.