Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
Tags.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.datamodel;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Observable;
26 import java.util.Observer;
27 import java.util.logging.Level;
28 import org.openide.nodes.ChildFactory;
29 import org.openide.nodes.Children;
30 import org.openide.nodes.Node;
31 import org.openide.nodes.Sheet;
32 import org.openide.util.NbBundle;
33 import org.openide.util.lookup.Lookups;
44 
50 public class Tags implements AutopsyVisitableItem {
51  // Creation of a RootNode object corresponding to a Tags object is done
52  // by a CreateAutopsyNodeVisitor dispatched from the AbstractContentChildren
53  // override of Children.Keys<T>.createNodes().
54 
55  private final TagResults tagResults = new TagResults();
56  private final String DISPLAY_NAME = NbBundle.getMessage(RootNode.class, "TagsNode.displayName.text");
57  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
58 
59 
60  @Override
61  public <T> T accept(AutopsyItemVisitor<T> v) {
62  return v.visit(this);
63  }
64 
65 
66 
67 
73  private class TagResults extends Observable {
74  public void update() {
75  setChanged();
76  notifyObservers();
77  }
78  }
79 
86  public class RootNode extends DisplayableItemNode {
87 
88  public RootNode() {
89  super(Children.create(new TagNameNodeFactory(), true), Lookups.singleton(DISPLAY_NAME));
90  super.setName(DISPLAY_NAME);
91  super.setDisplayName(DISPLAY_NAME);
92  this.setIconBaseWithExtension(ICON_PATH);
93  }
94 
95  @Override
96  public boolean isLeafTypeNode() {
97  return false;
98  }
99 
100  @Override
101  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
102  return v.visit(this);
103  }
104 
105  @Override
106  protected Sheet createSheet() {
107  Sheet propertySheet = super.createSheet();
108  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
109  if (properties == null) {
110  properties = Sheet.createPropertiesSet();
111  propertySheet.put(properties);
112  }
113  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.name"), NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.displayName"), "", getName()));
114  return propertySheet;
115  }
116  }
117 
118  private class TagNameNodeFactory extends ChildFactory.Detachable<TagName> implements Observer {
119 
120  private final PropertyChangeListener pcl = new PropertyChangeListener() {
121  @Override
122  @SuppressWarnings("deprecation")
123  public void propertyChange(PropertyChangeEvent evt) {
124  String eventType = evt.getPropertyName();
125  if (eventType.equals(IngestManager.IngestModuleEvent.DATA_ADDED.toString())) {
126  /* Note: this is a hack. In an ideal world, TagsManager
127  * would fire events so that the directory tree would
128  * refresh. But, we haven't had a chance to add that so, we
129  * fire these events and the tree refreshes based on them. */
130  if ((((ModuleDataEvent) evt.getOldValue()).getArtifactType() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_ARTIFACT)
131  || ((ModuleDataEvent) evt.getOldValue()).getArtifactType() == BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE) {
132  refresh(true);
133  tagResults.update();
134  }
135  } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString()) || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
136  refresh(true);
137  tagResults.update();
138  }
139  else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
140  // case was closed. Remove listeners so that this can be garbage collected
141  if (evt.getNewValue() == null) {
142  removeNotify();
143  }
144  }
145  }
146  };
147 
148  @Override
149  protected void addNotify() {
153  tagResults.update();
154  tagResults.addObserver(this);
155  }
156 
157  @Override
158  protected void removeNotify() {
162  tagResults.deleteObserver(this);
163  }
164 
165  @Override
166  protected boolean createKeys(List<TagName> keys) {
167  try {
168  List<TagName> tagNamesInUse = Case.getCurrentCase().getServices().getTagsManager().getTagNamesInUse();
169  Collections.sort(tagNamesInUse);
170  keys.addAll(tagNamesInUse);
171  } catch (TskCoreException ex) {
172  Logger.getLogger(TagNameNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
173  }
174  return true;
175  }
176 
177  @Override
178  protected Node createNodeForKey(TagName key) {
179  return new TagNameNode(key);
180  }
181 
182  @Override
183  public void update(Observable o, Object arg) {
184  refresh(true);
185  }
186  }
187 
193  public class TagNameNode extends DisplayableItemNode implements Observer {
194 
195  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
196  private final String BOOKMARK_TAG_ICON_PATH = "org/sleuthkit/autopsy/images/star-bookmark-icon-16.png"; //NON-NLS
197  private final TagName tagName;
198 
199  public TagNameNode(TagName tagName) {
200  super(Children.create(new TagTypeNodeFactory(tagName), true), Lookups.singleton(NbBundle.getMessage(TagNameNode.class, "TagNameNode.namePlusTags.text", tagName.getDisplayName())));
201  this.tagName = tagName;
202  setName(tagName.getDisplayName());
204  if (tagName.getDisplayName().equals(NbBundle.getMessage(this.getClass(), "TagNameNode.bookmark.text"))) {
205  setIconBaseWithExtension(BOOKMARK_TAG_ICON_PATH);
206  } else {
207  setIconBaseWithExtension(ICON_PATH);
208  }
209  tagResults.addObserver(this);
210  }
211 
212  private void updateDisplayName() {
213  long tagsCount = 0;
214  try {
216  tagsCount = tm.getContentTagsCountByTagName(tagName);
217  tagsCount += tm.getBlackboardArtifactTagsCountByTagName(tagName);
218  } catch (TskCoreException ex) {
219  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "Failed to get tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
220  }
221  setDisplayName(tagName.getDisplayName() + " (" + tagsCount + ")");
222  }
223 
224  @Override
225  protected Sheet createSheet() {
226  Sheet propertySheet = super.createSheet();
227  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
228  if (properties == null) {
229  properties = Sheet.createPropertiesSet();
230  propertySheet.put(properties);
231  }
232  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.name"), NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.displayName"), tagName.getDescription(), getName()));
233  return propertySheet;
234  }
235 
236  @Override
237  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
238  // See classes derived from DisplayableItemNodeVisitor<AbstractNode>
239  // for behavior added using the Visitor pattern.
240  return v.visit(this);
241  }
242 
243  @Override
244  public boolean isLeafTypeNode() {
245  return false;
246  }
247 
248  @Override
249  public void update(Observable o, Object arg) {
251  }
252  }
253 
258  private class TagTypeNodeFactory extends ChildFactory<String> {
259  private final TagName tagName;
260  private final String CONTENT_TAG_TYPE_NODE_KEY = NbBundle.getMessage(TagNameNode.class, "TagNameNode.contentTagTypeNodeKey.text");
261  private final String BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY = NbBundle.getMessage(TagNameNode.class, "TagNameNode.bbArtTagTypeNodeKey.text");
262 
263  TagTypeNodeFactory(TagName tagName) {
264  super();
265  this.tagName = tagName;
266  }
267 
268  @Override
269  protected boolean createKeys(List<String> keys) {
270  keys.add(CONTENT_TAG_TYPE_NODE_KEY);
271  keys.add(BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY);
272  return true;
273  }
274 
275  @Override
276  protected Node createNodeForKey(String key) {
277  if (CONTENT_TAG_TYPE_NODE_KEY.equals(key)) {
278  return new ContentTagTypeNode(tagName);
279  } else if (BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY.equals(key)) {
280  return new BlackboardArtifactTagTypeNode(tagName);
281  } else {
282  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "{0} not a recognized key", key); //NON-NLS
283  return null;
284  }
285  }
286  }
287 
288  private final String CONTENT_DISPLAY_NAME = NbBundle.getMessage(ContentTagTypeNode.class, "ContentTagTypeNode.displayName.text");
289 
296  public class ContentTagTypeNode extends DisplayableItemNode implements Observer {
297 
298  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
299  private TagName tagName;
300  public ContentTagTypeNode(TagName tagName) {
301  super(Children.create(new ContentTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + CONTENT_DISPLAY_NAME));
302  this.tagName = tagName;
303  super.setName(CONTENT_DISPLAY_NAME);
305  this.setIconBaseWithExtension(ICON_PATH);
306  tagResults.addObserver(this);
307  }
308 
309  private void updateDisplayName() {
310  long tagsCount = 0;
311  try {
313  } catch (TskCoreException ex) {
314  Logger.getLogger(ContentTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get content tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
315  }
316  super.setDisplayName(CONTENT_DISPLAY_NAME + " (" + tagsCount + ")");
317  }
318 
319  @Override
320  protected Sheet createSheet() {
321  Sheet propertySheet = super.createSheet();
322  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
323  if (properties == null) {
324  properties = Sheet.createPropertiesSet();
325  propertySheet.put(properties);
326  }
327  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.name"), NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.displayName"), "", getName()));
328  return propertySheet;
329  }
330 
331  @Override
332  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
333  return v.visit(this);
334  }
335 
336  @Override
337  public boolean isLeafTypeNode() {
338  return true;
339  }
340 
341  @Override
342  public void update(Observable o, Object arg) {
344  }
345  }
346 
347  private class ContentTagNodeFactory extends ChildFactory<ContentTag> implements Observer {
348  private final TagName tagName;
349 
350  ContentTagNodeFactory(TagName tagName) {
351  super();
352  this.tagName = tagName;
353  tagResults.addObserver(this);
354  }
355 
356  @Override
357  protected boolean createKeys(List<ContentTag> keys) {
358  // Use the content tags bearing the specified tag name as the keys.
359  try {
361  } catch (TskCoreException ex) {
362  Logger.getLogger(ContentTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
363  }
364  return true;
365  }
366 
367  @Override
368  protected Node createNodeForKey(ContentTag key) {
369  // The content tags to be wrapped are used as the keys.
370  return new ContentTagNode(key);
371  }
372 
373  @Override
374  public void update(Observable o, Object arg) {
375  refresh(true);
376  }
377  }
378 
379  private final String ARTIFACT_DISPLAY_NAME = NbBundle.getMessage(BlackboardArtifactTagTypeNode.class, "BlackboardArtifactTagTypeNode.displayName.text");
380 
386  public class BlackboardArtifactTagTypeNode extends DisplayableItemNode implements Observer {
387  private TagName tagName;
388  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
389 
391  super(Children.create(new BlackboardArtifactTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + ARTIFACT_DISPLAY_NAME));
392  this.tagName = tagName;
393  super.setName(ARTIFACT_DISPLAY_NAME);
394  this.setIconBaseWithExtension(ICON_PATH);
396  tagResults.addObserver(this);
397  }
398 
399  private void updateDisplayName() {
400  long tagsCount = 0;
401  try {
403  } catch (TskCoreException ex) {
404  Logger.getLogger(BlackboardArtifactTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get blackboard artifact tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
405  }
406  super.setDisplayName(ARTIFACT_DISPLAY_NAME + " (" + tagsCount + ")");
407  }
408 
409  @Override
410  protected Sheet createSheet() {
411  Sheet propertySheet = super.createSheet();
412  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
413  if (properties == null) {
414  properties = Sheet.createPropertiesSet();
415  propertySheet.put(properties);
416  }
417  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.name"), NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.displayName"), "", getName()));
418  return propertySheet;
419  }
420 
421  @Override
422  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
423  return v.visit(this);
424  }
425 
426  @Override
427  public boolean isLeafTypeNode() {
428  return true;
429  }
430 
431  @Override
432  public void update(Observable o, Object arg) {
434  }
435  }
436 
437  private class BlackboardArtifactTagNodeFactory extends ChildFactory<BlackboardArtifactTag> {
438  private final TagName tagName;
439 
441  super();
442  this.tagName = tagName;
443  }
444 
445  @Override
446  protected boolean createKeys(List<BlackboardArtifactTag> keys) {
447  try {
448  // Use the blackboard artifact tags bearing the specified tag name as the keys.
450  } catch (TskCoreException ex) {
451  Logger.getLogger(BlackboardArtifactTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
452  }
453  return true;
454  }
455 
456  @Override
458  // The blackboard artifact tags to be wrapped are used as the keys.
459  return new BlackboardArtifactTagNode(key);
460  }
461  }
462 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
void update(Observable o, Object arg)
Definition: Tags.java:249
synchronized List< ContentTag > getContentTagsByTagName(TagName tagName)
synchronized List< BlackboardArtifactTag > getBlackboardArtifactTagsByTagName(TagName tagName)
void removeIngestJobEventListener(final PropertyChangeListener listener)
void addIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< BlackboardArtifactTag > keys)
Definition: Tags.java:446
synchronized long getBlackboardArtifactTagsCountByTagName(TagName tagName)
static synchronized void removePropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:837
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:833
synchronized long getContentTagsCountByTagName(TagName tagName)
static Logger getLogger(String name)
Definition: Logger.java:131

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.