Autopsy  4.4.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 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.datamodel;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.Collections;
24 import java.util.EnumSet;
25 import java.util.List;
26 import java.util.Observable;
27 import java.util.Observer;
28 import java.util.Set;
29 import java.util.logging.Level;
30 import org.openide.nodes.ChildFactory;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Node;
33 import org.openide.nodes.Sheet;
34 import org.openide.util.NbBundle;
35 import org.openide.util.lookup.Lookups;
40 import org.sleuthkit.datamodel.BlackboardArtifactTag;
41 import org.sleuthkit.datamodel.ContentTag;
42 import org.sleuthkit.datamodel.TagName;
43 import org.sleuthkit.datamodel.TskCoreException;
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  @Override
60  public <T> T accept(AutopsyItemVisitor<T> v) {
61  return v.visit(this);
62  }
63 
69  private class TagResults extends Observable {
70 
71  public void update() {
72  setChanged();
73  notifyObservers();
74  }
75  }
76 
83  public class RootNode extends DisplayableItemNode {
84 
85  public RootNode() {
86  super(Children.create(new TagNameNodeFactory(), true), Lookups.singleton(DISPLAY_NAME));
87  super.setName(DISPLAY_NAME);
88  super.setDisplayName(DISPLAY_NAME);
89  this.setIconBaseWithExtension(ICON_PATH);
90  }
91 
92  @Override
93  public boolean isLeafTypeNode() {
94  return false;
95  }
96 
97  @Override
98  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
99  return v.visit(this);
100  }
101 
102  @Override
103  protected Sheet createSheet() {
104  Sheet propertySheet = super.createSheet();
105  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
106  if (properties == null) {
107  properties = Sheet.createPropertiesSet();
108  propertySheet.put(properties);
109  }
110  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.name"),
111  NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.displayName"), "", getName()));
112  return propertySheet;
113  }
114 
115  @Override
116  public String getItemType() {
117  return getClass().getName();
118  }
119  }
120 
121  private class TagNameNodeFactory extends ChildFactory.Detachable<TagName> implements Observer {
122 
128 
129  private final PropertyChangeListener pcl = new PropertyChangeListener() {
130  @Override
131  public void propertyChange(PropertyChangeEvent evt) {
132  String eventType = evt.getPropertyName();
133  if (eventType.equals(Case.Events.BLACKBOARD_ARTIFACT_TAG_ADDED.toString())
134  || eventType.equals(Case.Events.BLACKBOARD_ARTIFACT_TAG_DELETED.toString())
135  || eventType.equals(Case.Events.CONTENT_TAG_ADDED.toString())
136  || eventType.equals(Case.Events.CONTENT_TAG_DELETED.toString())) {
143  try {
145  refresh(true);
146  tagResults.update();
147  } catch (IllegalStateException notUsed) {
151  }
152  } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
153  || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
160  try {
162  refresh(true);
163  tagResults.update();
164  } catch (IllegalStateException notUsed) {
168  }
169  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
170  // case was closed. Remove listeners so that this can be garbage collected
171  if (evt.getNewValue() == null) {
172  removeNotify();
173  }
174  }
175  }
176  };
177 
178  @Override
179  protected void addNotify() {
183  tagResults.update();
184  tagResults.addObserver(this);
185  }
186 
187  @Override
188  protected void removeNotify() {
192  tagResults.deleteObserver(this);
193  }
194 
195  @Override
196  protected boolean createKeys(List<TagName> keys) {
197  try {
198  List<TagName> tagNamesInUse = Case.getCurrentCase().getServices().getTagsManager().getTagNamesInUse();
199  Collections.sort(tagNamesInUse);
200  keys.addAll(tagNamesInUse);
201  } catch (TskCoreException ex) {
202  Logger.getLogger(TagNameNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
203  }
204  return true;
205  }
206 
207  @Override
208  protected Node createNodeForKey(TagName key) {
209  return new TagNameNode(key);
210  }
211 
212  @Override
213  public void update(Observable o, Object arg) {
214  refresh(true);
215  }
216  }
217 
223  public class TagNameNode extends DisplayableItemNode implements Observer {
224 
225  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
226  private final String BOOKMARK_TAG_ICON_PATH = "org/sleuthkit/autopsy/images/star-bookmark-icon-16.png"; //NON-NLS
227  private final TagName tagName;
228 
229  public TagNameNode(TagName tagName) {
230  super(Children.create(new TagTypeNodeFactory(tagName), true), Lookups.singleton(NbBundle.getMessage(TagNameNode.class, "TagNameNode.namePlusTags.text", tagName.getDisplayName())));
231  this.tagName = tagName;
232  setName(tagName.getDisplayName());
234  if (tagName.getDisplayName().equals(NbBundle.getMessage(this.getClass(), "TagNameNode.bookmark.text"))) {
235  setIconBaseWithExtension(BOOKMARK_TAG_ICON_PATH);
236  } else {
237  setIconBaseWithExtension(ICON_PATH);
238  }
239  tagResults.addObserver(this);
240  }
241 
242  private void updateDisplayName() {
243  long tagsCount = 0;
244  try {
246  tagsCount = tm.getContentTagsCountByTagName(tagName);
247  tagsCount += tm.getBlackboardArtifactTagsCountByTagName(tagName);
248  } catch (TskCoreException ex) {
249  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "Failed to get tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
250  }
251  setDisplayName(tagName.getDisplayName() + " \u200E(\u200E" + tagsCount + ")\u200E");
252  }
253 
254  @Override
255  protected Sheet createSheet() {
256  Sheet propertySheet = super.createSheet();
257  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
258  if (properties == null) {
259  properties = Sheet.createPropertiesSet();
260  propertySheet.put(properties);
261  }
262  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.name"),
263  NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.displayName"), tagName.getDescription(), getName()));
264  return propertySheet;
265  }
266 
267  @Override
268  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
269  // See classes derived from DisplayableItemNodeVisitor<AbstractNode>
270  // for behavior added using the Visitor pattern.
271  return v.visit(this);
272  }
273 
274  @Override
275  public boolean isLeafTypeNode() {
276  return false;
277  }
278 
279  @Override
280  public void update(Observable o, Object arg) {
282  }
283 
284  @Override
285  public String getItemType() {
286  return getClass().getName();
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 final 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"),
366  NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.displayName"), "", getName()));
367  return propertySheet;
368  }
369 
370  @Override
371  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
372  return v.visit(this);
373  }
374 
375  @Override
376  public boolean isLeafTypeNode() {
377  return true;
378  }
379 
380  @Override
381  public void update(Observable o, Object arg) {
383  }
384 
385  @Override
386  public String getItemType() {
387  return getClass().getName();
388  }
389  }
390 
391  private class ContentTagNodeFactory extends ChildFactory<ContentTag> implements Observer {
392 
393  private final TagName tagName;
394 
395  ContentTagNodeFactory(TagName tagName) {
396  super();
397  this.tagName = tagName;
398  tagResults.addObserver(this);
399  }
400 
401  @Override
402  protected boolean createKeys(List<ContentTag> keys) {
403  // Use the content tags bearing the specified tag name as the keys.
404  try {
406  } catch (TskCoreException ex) {
407  Logger.getLogger(ContentTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
408  }
409  return true;
410  }
411 
412  @Override
413  protected Node createNodeForKey(ContentTag key) {
414  // The content tags to be wrapped are used as the keys.
415  return new ContentTagNode(key);
416  }
417 
418  @Override
419  public void update(Observable o, Object arg) {
420  refresh(true);
421  }
422  }
423 
424  private final String ARTIFACT_DISPLAY_NAME = NbBundle.getMessage(BlackboardArtifactTagTypeNode.class, "BlackboardArtifactTagTypeNode.displayName.text");
425 
432  public class BlackboardArtifactTagTypeNode extends DisplayableItemNode implements Observer {
433 
434  private final TagName tagName;
435  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
436 
437  public BlackboardArtifactTagTypeNode(TagName tagName) {
438  super(Children.create(new BlackboardArtifactTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + ARTIFACT_DISPLAY_NAME));
439  this.tagName = tagName;
440  super.setName(ARTIFACT_DISPLAY_NAME);
441  this.setIconBaseWithExtension(ICON_PATH);
443  tagResults.addObserver(this);
444  }
445 
446  private void updateDisplayName() {
447  long tagsCount = 0;
448  try {
450  } catch (TskCoreException ex) {
451  Logger.getLogger(BlackboardArtifactTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get blackboard artifact tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
452  }
453  super.setDisplayName(ARTIFACT_DISPLAY_NAME + " (" + tagsCount + ")");
454  }
455 
456  @Override
457  protected Sheet createSheet() {
458  Sheet propertySheet = super.createSheet();
459  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
460  if (properties == null) {
461  properties = Sheet.createPropertiesSet();
462  propertySheet.put(properties);
463  }
464  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.name"),
465  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.displayName"), "", getName()));
466  return propertySheet;
467  }
468 
469  @Override
470  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
471  return v.visit(this);
472  }
473 
474  @Override
475  public boolean isLeafTypeNode() {
476  return true;
477  }
478 
479  @Override
480  public void update(Observable o, Object arg) {
482  }
483 
484  @Override
485  public String getItemType() {
486  return getClass().getName();
487  }
488  }
489 
490  private class BlackboardArtifactTagNodeFactory extends ChildFactory<BlackboardArtifactTag> implements Observer {
491 
492  private final TagName tagName;
493 
494  BlackboardArtifactTagNodeFactory(TagName tagName) {
495  super();
496  this.tagName = tagName;
497  tagResults.addObserver(this);
498  }
499 
500  @Override
501  protected boolean createKeys(List<BlackboardArtifactTag> keys) {
502  try {
503  // Use the blackboard artifact tags bearing the specified tag name as the keys.
505  } catch (TskCoreException ex) {
506  Logger.getLogger(BlackboardArtifactTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
507  }
508  return true;
509  }
510 
511  @Override
512  protected Node createNodeForKey(BlackboardArtifactTag key) {
513  // The blackboard artifact tags to be wrapped are used as the keys.
514  return new BlackboardArtifactTagNode(key);
515  }
516 
517  @Override
518  public void update(Observable o, Object arg) {
519  refresh(true);
520  }
521  }
522 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
void update(Observable o, Object arg)
Definition: Tags.java:280
void removeIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< ContentTag > keys)
Definition: Tags.java:402
void addIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< BlackboardArtifactTag > keys)
Definition: Tags.java:501
List< BlackboardArtifactTag > getBlackboardArtifactTagsByTagName(TagName tagName)
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:395
List< ContentTag > getContentTagsByTagName(TagName tagName)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:440

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