Autopsy  4.0
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 2011-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.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;
38 import org.sleuthkit.datamodel.BlackboardArtifactTag;
39 import org.sleuthkit.datamodel.ContentTag;
40 import org.sleuthkit.datamodel.TagName;
41 import org.sleuthkit.datamodel.TskCoreException;
42 
48 public class Tags implements AutopsyVisitableItem {
49  // Creation of a RootNode object corresponding to a Tags object is done
50  // by a CreateAutopsyNodeVisitor dispatched from the AbstractContentChildren
51  // override of Children.Keys<T>.createNodes().
52 
53  private final TagResults tagResults = new TagResults();
54  private final String DISPLAY_NAME = NbBundle.getMessage(RootNode.class, "TagsNode.displayName.text");
55  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
56 
57  @Override
58  public <T> T accept(AutopsyItemVisitor<T> v) {
59  return v.visit(this);
60  }
61 
67  private class TagResults extends Observable {
68 
69  public void update() {
70  setChanged();
71  notifyObservers();
72  }
73  }
74 
81  public class RootNode extends DisplayableItemNode {
82 
83  public RootNode() {
84  super(Children.create(new TagNameNodeFactory(), true), Lookups.singleton(DISPLAY_NAME));
85  super.setName(DISPLAY_NAME);
86  super.setDisplayName(DISPLAY_NAME);
87  this.setIconBaseWithExtension(ICON_PATH);
88  }
89 
90  @Override
91  public boolean isLeafTypeNode() {
92  return false;
93  }
94 
95  @Override
96  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
97  return v.visit(this);
98  }
99 
100  @Override
101  protected Sheet createSheet() {
102  Sheet propertySheet = super.createSheet();
103  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
104  if (properties == null) {
105  properties = Sheet.createPropertiesSet();
106  propertySheet.put(properties);
107  }
108  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.name"), NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.displayName"), "", getName()));
109  return propertySheet;
110  }
111 
112  /*
113  * TODO (AUT-1849): Correct or remove peristent column reordering code
114  *
115  * Added to support this feature.
116  */
117 // @Override
118 // public String getItemType() {
119 // return "TagsRoots"; //NON-NLS
120 // }
121  }
122 
123  private class TagNameNodeFactory extends ChildFactory.Detachable<TagName> implements Observer {
124 
125  private final PropertyChangeListener pcl = new PropertyChangeListener() {
126  @Override
127  public void propertyChange(PropertyChangeEvent evt) {
128  String eventType = evt.getPropertyName();
129  if (eventType.equals(Case.Events.BLACKBOARD_ARTIFACT_TAG_ADDED.toString())
130  || eventType.equals(Case.Events.BLACKBOARD_ARTIFACT_TAG_DELETED.toString())
131  || eventType.equals(Case.Events.CONTENT_TAG_ADDED.toString())
132  || eventType.equals(Case.Events.CONTENT_TAG_DELETED.toString())) {
139  try {
141  refresh(true);
142  tagResults.update();
143  } catch (IllegalStateException notUsed) {
147  }
148  } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
149  || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
156  try {
158  refresh(true);
159  tagResults.update();
160  } catch (IllegalStateException notUsed) {
164  }
165  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
166  // case was closed. Remove listeners so that this can be garbage collected
167  if (evt.getNewValue() == null) {
168  removeNotify();
169  }
170  }
171  }
172  };
173 
174  @Override
175  protected void addNotify() {
179  tagResults.update();
180  tagResults.addObserver(this);
181  }
182 
183  @Override
184  protected void removeNotify() {
188  tagResults.deleteObserver(this);
189  }
190 
191  @Override
192  protected boolean createKeys(List<TagName> keys) {
193  try {
194  List<TagName> tagNamesInUse = Case.getCurrentCase().getServices().getTagsManager().getTagNamesInUse();
195  Collections.sort(tagNamesInUse);
196  keys.addAll(tagNamesInUse);
197  } catch (TskCoreException ex) {
198  Logger.getLogger(TagNameNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
199  }
200  return true;
201  }
202 
203  @Override
204  protected Node createNodeForKey(TagName key) {
205  return new TagNameNode(key);
206  }
207 
208  @Override
209  public void update(Observable o, Object arg) {
210  refresh(true);
211  }
212  }
213 
219  public class TagNameNode extends DisplayableItemNode implements Observer {
220 
221  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
222  private final String BOOKMARK_TAG_ICON_PATH = "org/sleuthkit/autopsy/images/star-bookmark-icon-16.png"; //NON-NLS
223  private final TagName tagName;
224 
225  public TagNameNode(TagName tagName) {
226  super(Children.create(new TagTypeNodeFactory(tagName), true), Lookups.singleton(NbBundle.getMessage(TagNameNode.class, "TagNameNode.namePlusTags.text", tagName.getDisplayName())));
227  this.tagName = tagName;
228  setName(tagName.getDisplayName());
230  if (tagName.getDisplayName().equals(NbBundle.getMessage(this.getClass(), "TagNameNode.bookmark.text"))) {
231  setIconBaseWithExtension(BOOKMARK_TAG_ICON_PATH);
232  } else {
233  setIconBaseWithExtension(ICON_PATH);
234  }
235  tagResults.addObserver(this);
236  }
237 
238  private void updateDisplayName() {
239  long tagsCount = 0;
240  try {
242  tagsCount = tm.getContentTagsCountByTagName(tagName);
243  tagsCount += tm.getBlackboardArtifactTagsCountByTagName(tagName);
244  } catch (TskCoreException ex) {
245  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "Failed to get tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
246  }
247  setDisplayName(tagName.getDisplayName() + " (" + tagsCount + ")");
248  }
249 
250  @Override
251  protected Sheet createSheet() {
252  Sheet propertySheet = super.createSheet();
253  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
254  if (properties == null) {
255  properties = Sheet.createPropertiesSet();
256  propertySheet.put(properties);
257  }
258  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.name"), NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.displayName"), tagName.getDescription(), getName()));
259  return propertySheet;
260  }
261 
262  @Override
263  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
264  // See classes derived from DisplayableItemNodeVisitor<AbstractNode>
265  // for behavior added using the Visitor pattern.
266  return v.visit(this);
267  }
268 
269  @Override
270  public boolean isLeafTypeNode() {
271  return false;
272  }
273 
274  @Override
275  public void update(Observable o, Object arg) {
277  }
278 
279  /*
280  * TODO (AUT-1849): Correct or remove peristent column reordering code
281  *
282  * Added to support this feature.
283  */
284 // @Override
285 // public String getItemType() {
286 // return "TagsName"; //NON-NLS
287 // }
288  }
289 
294  private class TagTypeNodeFactory extends ChildFactory<String> {
295 
296  private final TagName tagName;
297  private final String CONTENT_TAG_TYPE_NODE_KEY = NbBundle.getMessage(TagNameNode.class, "TagNameNode.contentTagTypeNodeKey.text");
298  private final String BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY = NbBundle.getMessage(TagNameNode.class, "TagNameNode.bbArtTagTypeNodeKey.text");
299 
300  TagTypeNodeFactory(TagName tagName) {
301  super();
302  this.tagName = tagName;
303  }
304 
305  @Override
306  protected boolean createKeys(List<String> keys) {
307  keys.add(CONTENT_TAG_TYPE_NODE_KEY);
308  keys.add(BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY);
309  return true;
310  }
311 
312  @Override
313  protected Node createNodeForKey(String key) {
314  if (CONTENT_TAG_TYPE_NODE_KEY.equals(key)) {
315  return new ContentTagTypeNode(tagName);
316  } else if (BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY.equals(key)) {
317  return new BlackboardArtifactTagTypeNode(tagName);
318  } else {
319  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "{0} not a recognized key", key); //NON-NLS
320  return null;
321  }
322  }
323  }
324 
325  private final String CONTENT_DISPLAY_NAME = NbBundle.getMessage(ContentTagTypeNode.class, "ContentTagTypeNode.displayName.text");
326 
333  public class ContentTagTypeNode extends DisplayableItemNode implements Observer {
334 
335  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
336  private TagName tagName;
337 
338  public ContentTagTypeNode(TagName tagName) {
339  super(Children.create(new ContentTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + CONTENT_DISPLAY_NAME));
340  this.tagName = tagName;
341  super.setName(CONTENT_DISPLAY_NAME);
343  this.setIconBaseWithExtension(ICON_PATH);
344  tagResults.addObserver(this);
345  }
346 
347  private void updateDisplayName() {
348  long tagsCount = 0;
349  try {
351  } catch (TskCoreException ex) {
352  Logger.getLogger(ContentTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get content tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
353  }
354  super.setDisplayName(CONTENT_DISPLAY_NAME + " (" + tagsCount + ")");
355  }
356 
357  @Override
358  protected Sheet createSheet() {
359  Sheet propertySheet = super.createSheet();
360  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
361  if (properties == null) {
362  properties = Sheet.createPropertiesSet();
363  propertySheet.put(properties);
364  }
365  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.name"), NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.displayName"), "", getName()));
366  return propertySheet;
367  }
368 
369  @Override
370  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
371  return v.visit(this);
372  }
373 
374  @Override
375  public boolean isLeafTypeNode() {
376  return true;
377  }
378 
379  @Override
380  public void update(Observable o, Object arg) {
382  }
383 
384  /*
385  * TODO (AUT-1849): Correct or remove peristent column reordering code
386  *
387  * Added to support this feature.
388  */
389 // @Override
390 // public String getItemType() {
391 // return "TagsContentType"; //NON-NLS
392 // }
393  }
394 
395  private class ContentTagNodeFactory extends ChildFactory<ContentTag> implements Observer {
396 
397  private final TagName tagName;
398 
399  ContentTagNodeFactory(TagName tagName) {
400  super();
401  this.tagName = tagName;
402  tagResults.addObserver(this);
403  }
404 
405  @Override
406  protected boolean createKeys(List<ContentTag> keys) {
407  // Use the content tags bearing the specified tag name as the keys.
408  try {
410  } catch (TskCoreException ex) {
411  Logger.getLogger(ContentTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
412  }
413  return true;
414  }
415 
416  @Override
417  protected Node createNodeForKey(ContentTag key) {
418  // The content tags to be wrapped are used as the keys.
419  return new ContentTagNode(key);
420  }
421 
422  @Override
423  public void update(Observable o, Object arg) {
424  refresh(true);
425  }
426  }
427 
428  private final String ARTIFACT_DISPLAY_NAME = NbBundle.getMessage(BlackboardArtifactTagTypeNode.class, "BlackboardArtifactTagTypeNode.displayName.text");
429 
436  public class BlackboardArtifactTagTypeNode extends DisplayableItemNode implements Observer {
437 
438  private TagName tagName;
439  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
440 
441  public BlackboardArtifactTagTypeNode(TagName tagName) {
442  super(Children.create(new BlackboardArtifactTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + ARTIFACT_DISPLAY_NAME));
443  this.tagName = tagName;
444  super.setName(ARTIFACT_DISPLAY_NAME);
445  this.setIconBaseWithExtension(ICON_PATH);
447  tagResults.addObserver(this);
448  }
449 
450  private void updateDisplayName() {
451  long tagsCount = 0;
452  try {
454  } catch (TskCoreException ex) {
455  Logger.getLogger(BlackboardArtifactTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get blackboard artifact tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
456  }
457  super.setDisplayName(ARTIFACT_DISPLAY_NAME + " (" + tagsCount + ")");
458  }
459 
460  @Override
461  protected Sheet createSheet() {
462  Sheet propertySheet = super.createSheet();
463  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
464  if (properties == null) {
465  properties = Sheet.createPropertiesSet();
466  propertySheet.put(properties);
467  }
468  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.name"), NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.displayName"), "", getName()));
469  return propertySheet;
470  }
471 
472  @Override
473  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
474  return v.visit(this);
475  }
476 
477  @Override
478  public boolean isLeafTypeNode() {
479  return true;
480  }
481 
482  @Override
483  public void update(Observable o, Object arg) {
485  }
486 
487  /*
488  * TODO (AUT-1849): Correct or remove peristent column reordering code
489  *
490  * Added to support this feature.
491  */
492 // @Override
493 // public String getItemType() {
494 // return "TagsBlackboardArtifact"; //NON-NLS
495 // }
496  }
497 
498  private class BlackboardArtifactTagNodeFactory extends ChildFactory<BlackboardArtifactTag> implements Observer {
499 
500  private final TagName tagName;
501 
502  BlackboardArtifactTagNodeFactory(TagName tagName) {
503  super();
504  this.tagName = tagName;
505  tagResults.addObserver(this);
506  }
507 
508  @Override
509  protected boolean createKeys(List<BlackboardArtifactTag> keys) {
510  try {
511  // Use the blackboard artifact tags bearing the specified tag name as the keys.
513  } catch (TskCoreException ex) {
514  Logger.getLogger(BlackboardArtifactTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
515  }
516  return true;
517  }
518 
519  @Override
520  protected Node createNodeForKey(BlackboardArtifactTag key) {
521  // The blackboard artifact tags to be wrapped are used as the keys.
522  return new BlackboardArtifactTagNode(key);
523  }
524 
525  @Override
526  public void update(Observable o, Object arg) {
527  refresh(true);
528  }
529  }
530 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
void update(Observable o, Object arg)
Definition: Tags.java:275
synchronized List< ContentTag > getContentTagsByTagName(TagName tagName)
synchronized List< BlackboardArtifactTag > getBlackboardArtifactTagsByTagName(TagName tagName)
void removeIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< ContentTag > keys)
Definition: Tags.java:406
void addIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< BlackboardArtifactTag > keys)
Definition: Tags.java:509
synchronized long getBlackboardArtifactTagsCountByTagName(TagName tagName)
static synchronized void removePropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:1305
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:1292
synchronized static Logger getLogger(String name)
Definition: Logger.java:166
synchronized long getContentTagsCountByTagName(TagName tagName)

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.