Autopsy  4.13.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-2019 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;
42 import org.sleuthkit.datamodel.BlackboardArtifactTag;
43 import org.sleuthkit.datamodel.ContentTag;
44 import org.sleuthkit.datamodel.TagName;
45 import org.sleuthkit.datamodel.TskCoreException;
46 
52 public class Tags implements AutopsyVisitableItem {
53  // Creation of a RootNode object corresponding to a Tags object is done
54  // by a CreateAutopsyNodeVisitor dispatched from the AbstractContentChildren
55  // override of Children.Keys<T>.createNodes().
56 
57  private final static String DISPLAY_NAME = NbBundle.getMessage(RootNode.class, "TagsNode.displayName.text");
59  private static final String USER_NAME_PROPERTY = "user.name"; //NON-NLS
60  private final TagResults tagResults = new TagResults();
61  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
62 
63  private final long filteringDSObjId; // 0 if not filtering/grouping by data source
64 
65  Tags() {
66  this(0);
67  }
68 
69  Tags(long dsObjId) {
70  this.filteringDSObjId = dsObjId;
71  }
72 
78  public static String getTagsDisplayName() {
79  return DISPLAY_NAME;
80  }
81 
82  long filteringDataSourceObjId() {
83  return this.filteringDSObjId;
84  }
85 
86  @Override
87  public <T> T accept(AutopsyItemVisitor<T> visitor) {
88  return visitor.visit(this);
89  }
90 
96  private class TagResults extends Observable {
97 
98  public void update() {
99  setChanged();
100  notifyObservers();
101  }
102  }
103 
110  public class RootNode extends DisplayableItemNode {
111 
112  public RootNode(long objId) {
113  super(Children.create(new TagNameNodeFactory(objId), true), Lookups.singleton(DISPLAY_NAME));
114  super.setName(DISPLAY_NAME);
115  super.setDisplayName(DISPLAY_NAME);
116  this.setIconBaseWithExtension(ICON_PATH);
117  }
118 
119  @Override
120  public boolean isLeafTypeNode() {
121  return false;
122  }
123 
124  @Override
125  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
126  return visitor.visit(this);
127  }
128 
129  @Override
130  protected Sheet createSheet() {
131  Sheet propertySheet = super.createSheet();
132  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
133  if (properties == null) {
134  properties = Sheet.createPropertiesSet();
135  propertySheet.put(properties);
136  }
137  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.name"),
138  NbBundle.getMessage(this.getClass(), "TagsNode.createSheet.name.displayName"), "", getName()));
139  return propertySheet;
140  }
141 
142  @Override
143  public String getItemType() {
144  return getClass().getName();
145  }
146 
150  public void refresh() {
151  tagResults.update();
152  }
153 
154  }
155 
156  private class TagNameNodeFactory extends ChildFactory.Detachable<TagName> implements Observer {
157 
158  private final long filteringDSObjId; // 0 if not filtering/grouping by data source
159 
165 
166  private final PropertyChangeListener pcl = new PropertyChangeListener() {
167  @Override
168  public void propertyChange(PropertyChangeEvent evt) {
169  String eventType = evt.getPropertyName();
170  if (eventType.equals(Case.Events.BLACKBOARD_ARTIFACT_TAG_ADDED.toString())
171  || eventType.equals(Case.Events.BLACKBOARD_ARTIFACT_TAG_DELETED.toString())
172  || eventType.equals(Case.Events.CONTENT_TAG_ADDED.toString())
173  || eventType.equals(Case.Events.CONTENT_TAG_DELETED.toString())) {
180  try {
182  refresh(true);
183  tagResults.update();
184  } catch (NoCurrentCaseException notUsed) {
188  }
189  } else if (eventType.equals(IngestManager.IngestJobEvent.COMPLETED.toString())
190  || eventType.equals(IngestManager.IngestJobEvent.CANCELLED.toString())) {
197  try {
199  refresh(true);
200  tagResults.update();
201  } catch (NoCurrentCaseException notUsed) {
205  }
206  } else if (eventType.equals(Case.Events.CURRENT_CASE.toString())) {
207  // case was closed. Remove listeners so that this can be garbage collected
208  if (evt.getNewValue() == null) {
209  removeNotify();
210  }
211  }
212  }
213  };
214 
220  TagNameNodeFactory(long objId) {
221  this.filteringDSObjId = objId;
222 
223  }
224 
225  @Override
226  protected void addNotify() {
229  tagResults.update();
230  tagResults.addObserver(this);
231  }
232 
233  @Override
234  protected void removeNotify() {
237  tagResults.deleteObserver(this);
238  }
239 
240  @Override
241  protected boolean createKeys(List<TagName> keys) {
242  try {
243  List<TagName> tagNamesInUse;
245  String userName = System.getProperty(USER_NAME_PROPERTY);
246  tagNamesInUse = (filteringDSObjId > 0)
249  } else {
250  tagNamesInUse = (filteringDSObjId > 0)
253  }
254  Collections.sort(tagNamesInUse);
255  keys.addAll(tagNamesInUse);
256  } catch (TskCoreException | NoCurrentCaseException ex) {
257  Logger.getLogger(TagNameNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
258  }
259  return true;
260  }
261 
262  @Override
263  protected Node createNodeForKey(TagName key) {
264  return new TagNameNode(key);
265  }
266 
267  @Override
268  public void update(Observable o, Object arg) {
269  refresh(true);
270  }
271  }
272 
278  public class TagNameNode extends DisplayableItemNode implements Observer {
279 
280  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
281  private final String BOOKMARK_TAG_ICON_PATH = "org/sleuthkit/autopsy/images/star-bookmark-icon-16.png"; //NON-NLS
282  private final TagName tagName;
283 
284  public TagNameNode(TagName tagName) {
285  super(Children.create(new TagTypeNodeFactory(tagName), true), Lookups.singleton(NbBundle.getMessage(TagNameNode.class, "TagNameNode.namePlusTags.text", tagName.getDisplayName())));
286  this.tagName = tagName;
287  setName(tagName.getDisplayName());
289  if (tagName.getDisplayName().equals(NbBundle.getMessage(this.getClass(), "TagNameNode.bookmark.text"))) {
290  setIconBaseWithExtension(BOOKMARK_TAG_ICON_PATH);
291  } else {
292  setIconBaseWithExtension(ICON_PATH);
293  }
294  tagResults.addObserver(this);
295  }
296 
297  private void updateDisplayName() {
298  long tagsCount = 0;
299  try {
302  String userName = System.getProperty(USER_NAME_PROPERTY);
303  if (filteringDSObjId > 0) {
304  tagsCount = tm.getContentTagsCountByTagNameForUser(tagName, filteringDSObjId, userName);
305  tagsCount += tm.getBlackboardArtifactTagsCountByTagNameForUser(tagName, filteringDSObjId, userName);
306  } else {
307  tagsCount = tm.getContentTagsCountByTagNameForUser(tagName, userName);
308  tagsCount += tm.getBlackboardArtifactTagsCountByTagNameForUser(tagName, userName);
309  }
310  } else {
311  if (filteringDSObjId > 0) {
312  tagsCount = tm.getContentTagsCountByTagName(tagName, filteringDSObjId);
313  tagsCount += tm.getBlackboardArtifactTagsCountByTagName(tagName, filteringDSObjId);
314  } else {
315  tagsCount = tm.getContentTagsCountByTagName(tagName);
316  tagsCount += tm.getBlackboardArtifactTagsCountByTagName(tagName);
317  }
318  }
319  } catch (TskCoreException | NoCurrentCaseException ex) {
320  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "Failed to get tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
321  }
322  setDisplayName(tagName.getDisplayName() + " \u200E(\u200E" + tagsCount + ")\u200E");
323  }
324 
325  @Override
326  protected Sheet createSheet() {
327  Sheet propertySheet = super.createSheet();
328  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
329  if (properties == null) {
330  properties = Sheet.createPropertiesSet();
331  propertySheet.put(properties);
332  }
333  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.name"),
334  NbBundle.getMessage(this.getClass(), "TagNameNode.createSheet.name.displayName"), tagName.getDescription(), getName()));
335  return propertySheet;
336  }
337 
338  @Override
339  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
340  // See classes derived from DisplayableItemNodeVisitor<AbstractNode>
341  // for behavior added using the Visitor pattern.
342  return visitor.visit(this);
343  }
344 
345  @Override
346  public boolean isLeafTypeNode() {
347  return false;
348  }
349 
350  @Override
351  public void update(Observable o, Object arg) {
353  }
354 
355  @Override
356  public String getItemType() {
357  return getClass().getName();
358  }
359  }
360 
365  private class TagTypeNodeFactory extends ChildFactory<String> {
366 
367  private final TagName tagName;
368  private final String CONTENT_TAG_TYPE_NODE_KEY = NbBundle.getMessage(TagNameNode.class, "TagNameNode.contentTagTypeNodeKey.text");
369  private final String BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY = NbBundle.getMessage(TagNameNode.class, "TagNameNode.bbArtTagTypeNodeKey.text");
370 
371  TagTypeNodeFactory(TagName tagName) {
372  super();
373  this.tagName = tagName;
374  }
375 
376  @Override
377  protected boolean createKeys(List<String> keys) {
378  keys.add(CONTENT_TAG_TYPE_NODE_KEY);
379  keys.add(BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY);
380  return true;
381  }
382 
383  @Override
384  protected Node createNodeForKey(String key) {
385  if (CONTENT_TAG_TYPE_NODE_KEY.equals(key)) {
386  return new ContentTagTypeNode(tagName);
387  } else if (BLACKBOARD_ARTIFACT_TAG_TYPE_NODE_KEY.equals(key)) {
388  return new BlackboardArtifactTagTypeNode(tagName);
389  } else {
390  Logger.getLogger(TagNameNode.class.getName()).log(Level.SEVERE, "{0} not a recognized key", key); //NON-NLS
391  return null;
392  }
393  }
394  }
395 
396  private final String CONTENT_DISPLAY_NAME = NbBundle.getMessage(ContentTagTypeNode.class, "ContentTagTypeNode.displayName.text");
397 
404  public class ContentTagTypeNode extends DisplayableItemNode implements Observer {
405 
406  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
407  private final TagName tagName;
408 
409  public ContentTagTypeNode(TagName tagName) {
410  super(Children.create(new ContentTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + CONTENT_DISPLAY_NAME));
411  this.tagName = tagName;
412  super.setName(CONTENT_DISPLAY_NAME);
414  this.setIconBaseWithExtension(ICON_PATH);
415  tagResults.addObserver(this);
416  }
417 
418  private void updateDisplayName() {
419  long tagsCount = 0;
420  try {
421 
423  String userName = System.getProperty(USER_NAME_PROPERTY);
424  tagsCount = (filteringDSObjId > 0)
425  ? Case.getCurrentCaseThrows().getServices().getTagsManager().getContentTagsCountByTagNameForUser(tagName, filteringDSObjId, userName)
427  } else {
428  tagsCount = (filteringDSObjId > 0)
431  }
432  } catch (TskCoreException | NoCurrentCaseException ex) {
433  Logger.getLogger(ContentTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get content tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
434  }
435  super.setDisplayName(CONTENT_DISPLAY_NAME + " (" + tagsCount + ")");
436  }
437 
438  @Override
439  protected Sheet createSheet() {
440  Sheet propertySheet = super.createSheet();
441  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
442  if (properties == null) {
443  properties = Sheet.createPropertiesSet();
444  propertySheet.put(properties);
445  }
446  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.name"),
447  NbBundle.getMessage(this.getClass(), "ContentTagTypeNode.createSheet.name.displayName"), "", getName()));
448  return propertySheet;
449  }
450 
451  @Override
452  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
453  return visitor.visit(this);
454  }
455 
456  @Override
457  public boolean isLeafTypeNode() {
458  return true;
459  }
460 
461  @Override
462  public void update(Observable o, Object arg) {
464  }
465 
466  @Override
467  public String getItemType() {
468  return getClass().getName();
469  }
470  }
471 
472  private class ContentTagNodeFactory extends ChildFactory<ContentTag> implements Observer {
473 
474  private final TagName tagName;
475 
476  ContentTagNodeFactory(TagName tagName) {
477  super();
478  this.tagName = tagName;
479  tagResults.addObserver(this);
480  }
481 
482  @Override
483  protected boolean createKeys(List<ContentTag> keys) {
484  // Use the content tags bearing the specified tag name as the keys.
485  try {
486  List<ContentTag> contentTags = (filteringDSObjId > 0)
490  String userName = System.getProperty(USER_NAME_PROPERTY);
491  for (ContentTag tag : contentTags) {
492  if (userName.equals(tag.getUserName())) {
493  keys.add(tag);
494  }
495  }
496  } else {
497  keys.addAll(contentTags);
498  }
499  } catch (TskCoreException | NoCurrentCaseException ex) {
500  Logger.getLogger(ContentTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
501  }
502  return true;
503  }
504 
505  @Override
506  protected Node createNodeForKey(ContentTag key) {
507  // The content tags to be wrapped are used as the keys.
508  return new ContentTagNode(key);
509  }
510 
511  @Override
512  public void update(Observable o, Object arg) {
513  refresh(true);
514  }
515  }
516 
517  private final String ARTIFACT_DISPLAY_NAME = NbBundle.getMessage(BlackboardArtifactTagTypeNode.class, "BlackboardArtifactTagTypeNode.displayName.text");
518 
525  public class BlackboardArtifactTagTypeNode extends DisplayableItemNode implements Observer {
526 
527  private final TagName tagName;
528  private final String ICON_PATH = "org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png"; //NON-NLS
529 
530  public BlackboardArtifactTagTypeNode(TagName tagName) {
531  super(Children.create(new BlackboardArtifactTagNodeFactory(tagName), true), Lookups.singleton(tagName.getDisplayName() + " " + ARTIFACT_DISPLAY_NAME));
532  this.tagName = tagName;
533  super.setName(ARTIFACT_DISPLAY_NAME);
534  this.setIconBaseWithExtension(ICON_PATH);
536  tagResults.addObserver(this);
537  }
538 
539  private void updateDisplayName() {
540  long tagsCount = 0;
541  try {
543  String userName = System.getProperty(USER_NAME_PROPERTY);
544  tagsCount = (filteringDSObjId > 0)
547  } else {
548  tagsCount = (filteringDSObjId > 0)
551  }
552  } catch (TskCoreException | NoCurrentCaseException ex) {
553  Logger.getLogger(BlackboardArtifactTagTypeNode.class.getName()).log(Level.SEVERE, "Failed to get blackboard artifact tags count for " + tagName.getDisplayName() + " tag name", ex); //NON-NLS
554  }
555  super.setDisplayName(ARTIFACT_DISPLAY_NAME + " (" + tagsCount + ")");
556  }
557 
558  @Override
559  protected Sheet createSheet() {
560  Sheet propertySheet = super.createSheet();
561  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
562  if (properties == null) {
563  properties = Sheet.createPropertiesSet();
564  propertySheet.put(properties);
565  }
566  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.name"),
567  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagTypeNode.createSheet.name.displayName"), "", getName()));
568  return propertySheet;
569  }
570 
571  @Override
572  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
573  return visitor.visit(this);
574  }
575 
576  @Override
577  public boolean isLeafTypeNode() {
578  return true;
579  }
580 
581  @Override
582  public void update(Observable o, Object arg) {
584  }
585 
586  @Override
587  public String getItemType() {
588  return getClass().getName();
589  }
590  }
591 
592  private class BlackboardArtifactTagNodeFactory extends ChildFactory<BlackboardArtifactTag> implements Observer {
593 
594  private final TagName tagName;
595 
596  BlackboardArtifactTagNodeFactory(TagName tagName) {
597  super();
598  this.tagName = tagName;
599  tagResults.addObserver(this);
600  }
601 
602  @Override
603  protected boolean createKeys(List<BlackboardArtifactTag> keys) {
604  try {
605  // Use the blackboard artifact tags bearing the specified tag name as the keys.
606  List<BlackboardArtifactTag> artifactTags = (filteringDSObjId > 0)
610  String userName = System.getProperty(USER_NAME_PROPERTY);
611  for (BlackboardArtifactTag tag : artifactTags) {
612  if (userName.equals(tag.getUserName())) {
613  keys.add(tag);
614  }
615  }
616  } else {
617  keys.addAll(artifactTags);
618  }
619  } catch (TskCoreException | NoCurrentCaseException ex) {
620  Logger.getLogger(BlackboardArtifactTagNodeFactory.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
621  }
622  return true;
623  }
624 
625  @Override
626  protected Node createNodeForKey(BlackboardArtifactTag key) {
627  // The blackboard artifact tags to be wrapped are used as the keys.
628  return new BlackboardArtifactTagNode(key);
629  }
630 
631  @Override
632  public void update(Observable o, Object arg) {
633  refresh(true);
634  }
635  }
636 }
static synchronized IngestManager getInstance()
void update(Observable o, Object arg)
Definition: Tags.java:351
List< TagName > getTagNamesInUseForUser(String userName)
static String getTagsDisplayName()
Definition: Tags.java:78
void removeIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< ContentTag > keys)
Definition: Tags.java:483
void addIngestJobEventListener(final PropertyChangeListener listener)
static final String DISPLAY_NAME
Definition: Tags.java:57
boolean createKeys(List< BlackboardArtifactTag > keys)
Definition: Tags.java:603
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
Definition: Tags.java:58
List< BlackboardArtifactTag > getBlackboardArtifactTagsByTagName(TagName tagName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:486
List< ContentTag > getContentTagsByTagName(TagName tagName)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
Definition: Case.java:531
long getContentTagsCountByTagNameForUser(TagName tagName, String userName)
long getBlackboardArtifactTagsCountByTagNameForUser(TagName tagName, String userName)
static final String USER_NAME_PROPERTY
Definition: Tags.java:59

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.