Autopsy  4.4
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.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"),
109  NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.displayName"), "", getName()));
110  return propertySheet;
111  }
112 
113  @Override
114  public String getItemType() {
115  return getClass().getName();
116  }
117  }
118 
119  private class TagNameNodeFactory extends ChildFactory.Detachable<TagName> implements Observer {
120 
121  private final PropertyChangeListener pcl = new PropertyChangeListener() {
122  @Override
123  public void propertyChange(PropertyChangeEvent evt) {
124  String eventType = evt.getPropertyName();
125  if (eventType.equals(Case.Events.BLACKBOARD_ARTIFACT_TAG_ADDED.toString())
126  || eventType.equals(Case.Events.BLACKBOARD_ARTIFACT_TAG_DELETED.toString())
127  || eventType.equals(Case.Events.CONTENT_TAG_ADDED.toString())
128  || eventType.equals(Case.Events.CONTENT_TAG_DELETED.toString())) {
135  try {
137  refresh(true);
138  tagResults.update();
139  } catch (IllegalStateException notUsed) {
143  }
144  } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
145  || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
152  try {
154  refresh(true);
155  tagResults.update();
156  } catch (IllegalStateException notUsed) {
160  }
161  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
162  // case was closed. Remove listeners so that this can be garbage collected
163  if (evt.getNewValue() == null) {
164  removeNotify();
165  }
166  }
167  }
168  };
169 
170  @Override
171  protected void addNotify() {
175  tagResults.update();
176  tagResults.addObserver(this);
177  }
178 
179  @Override
180  protected void removeNotify() {
184  tagResults.deleteObserver(this);
185  }
186 
187  @Override
188  protected boolean createKeys(List<TagName> keys) {
189  try {
190  List<TagName> tagNamesInUse = Case.getCurrentCase().getServices().getTagsManager().getTagNamesInUse();
191  Collections.sort(tagNamesInUse);
192  keys.addAll(tagNamesInUse);
193  } catch (TskCoreException ex) {
194  Logger.getLogger(TagNameNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
195  }
196  return true;
197  }
198 
199  @Override
200  protected Node createNodeForKey(TagName key) {
201  return new TagNameNode(key);
202  }
203 
204  @Override
205  public void update(Observable o, Object arg) {
206  refresh(true);
207  }
208  }
209 
215  public class TagNameNode extends DisplayableItemNode implements Observer {
216 
217  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
218  private final String BOOKMARK_TAG_ICON_PATH = "org/sleuthkit/autopsy/images/star-bookmark-icon-16.png"; //NON-NLS
219  private final TagName tagName;
220 
221  public TagNameNode(TagName tagName) {
222  super(Children.create(new TagTypeNodeFactory(tagName), true), Lookups.singleton(NbBundle.getMessage(TagNameNode.class, "TagNameNode.namePlusTags.text", tagName.getDisplayName())));
223  this.tagName = tagName;
224  setName(tagName.getDisplayName());
226  if (tagName.getDisplayName().equals(NbBundle.getMessage(this.getClass(), "TagNameNode.bookmark.text"))) {
227  setIconBaseWithExtension(BOOKMARK_TAG_ICON_PATH);
228  } else {
229  setIconBaseWithExtension(ICON_PATH);
230  }
231  tagResults.addObserver(this);
232  }
233 
234  private void updateDisplayName() {
235  long tagsCount = 0;
236  try {
238  tagsCount = tm.getContentTagsCountByTagName(tagName);
239  tagsCount += tm.getBlackboardArtifactTagsCountByTagName(tagName);
240  } catch (TskCoreException ex) {
241  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "Failed to get tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
242  }
243  setDisplayName(tagName.getDisplayName() + " \u200E(\u200E" + tagsCount + ")\u200E");
244  }
245 
246  @Override
247  protected Sheet createSheet() {
248  Sheet propertySheet = super.createSheet();
249  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
250  if (properties == null) {
251  properties = Sheet.createPropertiesSet();
252  propertySheet.put(properties);
253  }
254  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.name"),
255  NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.displayName"), tagName.getDescription(), getName()));
256  return propertySheet;
257  }
258 
259  @Override
260  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
261  // See classes derived from DisplayableItemNodeVisitor<AbstractNode>
262  // for behavior added using the Visitor pattern.
263  return v.visit(this);
264  }
265 
266  @Override
267  public boolean isLeafTypeNode() {
268  return false;
269  }
270 
271  @Override
272  public void update(Observable o, Object arg) {
274  }
275 
276  @Override
277  public String getItemType() {
278  return getClass().getName();
279  }
280  }
281 
286  private class TagTypeNodeFactory extends ChildFactory<String> {
287 
288  private final TagName tagName;
289  private final String CONTENT_TAG_TYPE_NODE_KEY = NbBundle.getMessage(TagNameNode.class, "TagNameNode.contentTagTypeNodeKey.text");
290  private final String BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY = NbBundle.getMessage(TagNameNode.class, "TagNameNode.bbArtTagTypeNodeKey.text");
291 
292  TagTypeNodeFactory(TagName tagName) {
293  super();
294  this.tagName = tagName;
295  }
296 
297  @Override
298  protected boolean createKeys(List<String> keys) {
299  keys.add(CONTENT_TAG_TYPE_NODE_KEY);
300  keys.add(BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY);
301  return true;
302  }
303 
304  @Override
305  protected Node createNodeForKey(String key) {
306  if (CONTENT_TAG_TYPE_NODE_KEY.equals(key)) {
307  return new ContentTagTypeNode(tagName);
308  } else if (BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY.equals(key)) {
309  return new BlackboardArtifactTagTypeNode(tagName);
310  } else {
311  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "{0} not a recognized key", key); //NON-NLS
312  return null;
313  }
314  }
315  }
316 
317  private final String CONTENT_DISPLAY_NAME = NbBundle.getMessage(ContentTagTypeNode.class, "ContentTagTypeNode.displayName.text");
318 
325  public class ContentTagTypeNode extends DisplayableItemNode implements Observer {
326 
327  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
328  private final TagName tagName;
329 
330  public ContentTagTypeNode(TagName tagName) {
331  super(Children.create(new ContentTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + CONTENT_DISPLAY_NAME));
332  this.tagName = tagName;
333  super.setName(CONTENT_DISPLAY_NAME);
335  this.setIconBaseWithExtension(ICON_PATH);
336  tagResults.addObserver(this);
337  }
338 
339  private void updateDisplayName() {
340  long tagsCount = 0;
341  try {
343  } catch (TskCoreException ex) {
344  Logger.getLogger(ContentTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get content tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
345  }
346  super.setDisplayName(CONTENT_DISPLAY_NAME + " (" + tagsCount + ")");
347  }
348 
349  @Override
350  protected Sheet createSheet() {
351  Sheet propertySheet = super.createSheet();
352  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
353  if (properties == null) {
354  properties = Sheet.createPropertiesSet();
355  propertySheet.put(properties);
356  }
357  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.name"),
358  NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.displayName"), "", getName()));
359  return propertySheet;
360  }
361 
362  @Override
363  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
364  return v.visit(this);
365  }
366 
367  @Override
368  public boolean isLeafTypeNode() {
369  return true;
370  }
371 
372  @Override
373  public void update(Observable o, Object arg) {
375  }
376 
377  @Override
378  public String getItemType() {
379  return getClass().getName();
380  }
381  }
382 
383  private class ContentTagNodeFactory extends ChildFactory<ContentTag> implements Observer {
384 
385  private final TagName tagName;
386 
387  ContentTagNodeFactory(TagName tagName) {
388  super();
389  this.tagName = tagName;
390  tagResults.addObserver(this);
391  }
392 
393  @Override
394  protected boolean createKeys(List<ContentTag> keys) {
395  // Use the content tags bearing the specified tag name as the keys.
396  try {
398  } catch (TskCoreException ex) {
399  Logger.getLogger(ContentTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
400  }
401  return true;
402  }
403 
404  @Override
405  protected Node createNodeForKey(ContentTag key) {
406  // The content tags to be wrapped are used as the keys.
407  return new ContentTagNode(key);
408  }
409 
410  @Override
411  public void update(Observable o, Object arg) {
412  refresh(true);
413  }
414  }
415 
416  private final String ARTIFACT_DISPLAY_NAME = NbBundle.getMessage(BlackboardArtifactTagTypeNode.class, "BlackboardArtifactTagTypeNode.displayName.text");
417 
424  public class BlackboardArtifactTagTypeNode extends DisplayableItemNode implements Observer {
425 
426  private final TagName tagName;
427  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
428 
429  public BlackboardArtifactTagTypeNode(TagName tagName) {
430  super(Children.create(new BlackboardArtifactTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + ARTIFACT_DISPLAY_NAME));
431  this.tagName = tagName;
432  super.setName(ARTIFACT_DISPLAY_NAME);
433  this.setIconBaseWithExtension(ICON_PATH);
435  tagResults.addObserver(this);
436  }
437 
438  private void updateDisplayName() {
439  long tagsCount = 0;
440  try {
442  } catch (TskCoreException ex) {
443  Logger.getLogger(BlackboardArtifactTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get blackboard artifact tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
444  }
445  super.setDisplayName(ARTIFACT_DISPLAY_NAME + " (" + tagsCount + ")");
446  }
447 
448  @Override
449  protected Sheet createSheet() {
450  Sheet propertySheet = super.createSheet();
451  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
452  if (properties == null) {
453  properties = Sheet.createPropertiesSet();
454  propertySheet.put(properties);
455  }
456  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.name"),
457  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.displayName"), "", getName()));
458  return propertySheet;
459  }
460 
461  @Override
462  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
463  return v.visit(this);
464  }
465 
466  @Override
467  public boolean isLeafTypeNode() {
468  return true;
469  }
470 
471  @Override
472  public void update(Observable o, Object arg) {
474  }
475 
476  @Override
477  public String getItemType() {
478  return getClass().getName();
479  }
480  }
481 
482  private class BlackboardArtifactTagNodeFactory extends ChildFactory<BlackboardArtifactTag> implements Observer {
483 
484  private final TagName tagName;
485 
486  BlackboardArtifactTagNodeFactory(TagName tagName) {
487  super();
488  this.tagName = tagName;
489  tagResults.addObserver(this);
490  }
491 
492  @Override
493  protected boolean createKeys(List<BlackboardArtifactTag> keys) {
494  try {
495  // Use the blackboard artifact tags bearing the specified tag name as the keys.
497  } catch (TskCoreException ex) {
498  Logger.getLogger(BlackboardArtifactTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
499  }
500  return true;
501  }
502 
503  @Override
504  protected Node createNodeForKey(BlackboardArtifactTag key) {
505  // The blackboard artifact tags to be wrapped are used as the keys.
506  return new BlackboardArtifactTagNode(key);
507  }
508 
509  @Override
510  public void update(Observable o, Object arg) {
511  refresh(true);
512  }
513  }
514 }
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
static void removePropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:369
void update(Observable o, Object arg)
Definition: Tags.java:272
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:394
void addIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< BlackboardArtifactTag > keys)
Definition: Tags.java:493
synchronized long getBlackboardArtifactTagsCountByTagName(TagName tagName)
static void addPropertyChangeListener(PropertyChangeListener listener)
Definition: Case.java:357
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
synchronized long getContentTagsCountByTagName(TagName tagName)

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