Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
DirectoryTreeFilterNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.directorytree;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.Action;
26 import org.openide.nodes.FilterNode;
27 import org.openide.nodes.Node;
28 import org.openide.util.Lookup;
29 import org.openide.util.NbBundle;
30 import org.openide.util.lookup.Lookups;
31 import org.openide.util.lookup.ProxyLookup;
36 import org.sleuthkit.datamodel.AbstractFile;
37 import org.sleuthkit.datamodel.BlackboardArtifact;
38 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
39 import org.sleuthkit.datamodel.Content;
40 import org.sleuthkit.datamodel.Host;
41 import org.sleuthkit.datamodel.Person;
42 import org.sleuthkit.datamodel.TskCoreException;
43 import org.sleuthkit.datamodel.TskData;
44 
50 class DirectoryTreeFilterNode extends FilterNode {
51 
52  private static final Logger logger = Logger.getLogger(DirectoryTreeFilterNode.class.getName());
53  private static final Action collapseAllAction = new CollapseAction(NbBundle.getMessage(DirectoryTreeFilterNode.class, "DirectoryTreeFilterNode.action.collapseAll.text"));
54 
64  DirectoryTreeFilterNode(Node nodeToWrap, boolean createChildren) {
65  super(nodeToWrap,
66  DirectoryTreeFilterChildren.createInstance(nodeToWrap, createChildren),
67  new ProxyLookup(Lookups.singleton(nodeToWrap), nodeToWrap.getLookup()));
68  }
69 
76  @Override
77  public String getDisplayName() {
78  final Node orig = getOriginal();
79  String name = orig.getDisplayName();
80 
81  if (orig instanceof AbstractContentNode) {
82  AbstractFile file = getLookup().lookup(AbstractFile.class);
83  if ((file != null) && (false == (orig instanceof BlackboardArtifactNode))) {
84  try {
85  int numVisibleChildren = getVisibleChildCount(file);
86 
87  /*
88  * Left-to-right marks here are necessary to keep the count
89  * and parens together for mixed right-to-left and
90  * left-to-right names.
91  */
92  name = name + " \u200E(\u200E" + numVisibleChildren + ")\u200E"; //NON-NLS
93 
94  } catch (TskCoreException ex) {
95  logger.log(Level.SEVERE, "Error getting children count to display for file: " + file, ex); //NON-NLS
96  }
97  } else if (orig instanceof BlackboardArtifactNode) {
98  BlackboardArtifact artifact = ((BlackboardArtifactNode) orig).getArtifact();
99  try {
100  int numAttachments = artifact.getChildrenCount();
101  name = name + " \u200E(\u200E" + numAttachments + ")\u200E"; //NON-NLS
102  } catch (TskCoreException ex) {
103  logger.log(Level.SEVERE, "Error getting chidlren count for atifact: " + artifact, ex); //NON-NLS
104  }
105  }
106  }
107  return name;
108  }
109 
119  private int getVisibleChildCount(AbstractFile file) throws TskCoreException {
120  List<Content> childList = file.getChildren();
121 
122  int numVisibleChildren = childList.size();
123  boolean purgeKnownFiles = UserPreferences.hideKnownFilesInDataSourcesTree();
124  boolean purgeSlackFiles = UserPreferences.hideSlackFilesInDataSourcesTree();
125 
126  if (purgeKnownFiles || purgeSlackFiles) {
127  // Purge known and/or slack files from the file count
128  for (int i = 0; i < childList.size(); i++) {
129  Content child = childList.get(i);
130  if (child instanceof AbstractFile) {
131  AbstractFile childFile = (AbstractFile) child;
132  if ((purgeKnownFiles && childFile.getKnown() == TskData.FileKnown.KNOWN)
133  || (purgeSlackFiles && childFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
134  numVisibleChildren--;
135  }
136  } else if (child instanceof BlackboardArtifact) {
137 
138  if (FilterNodeUtils.showMessagesInDatasourceTree()) {
139  // In older versions of Autopsy, attachments were children of email/message artifacts
140  // and hence email/messages with attachments are shown in the directory tree.
141  BlackboardArtifact bba = (BlackboardArtifact) child;
142  // Only message type artifacts are displayed in the tree
143  if ((bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
144  && (bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
145  numVisibleChildren--;
146  }
147  } else {
148  numVisibleChildren--;
149  }
150  }
151  }
152  }
153 
154  return numVisibleChildren;
155  }
156 
165  @Override
166  public Action[] getActions(boolean context) {
167  List<Action> actions = new ArrayList<>();
168  actions.addAll(Arrays.asList(getNodeActions()));
169  actions.add(collapseAllAction);
170  return actions.toArray(new Action[actions.size()]);
171  }
172 
177  private Action[] getNodeActions() {
178  Lookup lookup = this.getLookup();
179  if (lookup.lookup(Content.class) != null
180  || lookup.lookup(Host.class) != null
181  || lookup.lookup(Person.class) != null) {
182  return super.getActions(true);
183  } else {
184  return new Action[0];
185  }
186  }
187 
193  @Override
194  public Node getOriginal() {
195  return super.getOriginal();
196  }
197 
198 }

Copyright © 2012-2022 Basis Technology. Generated on: Thu Oct 6 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.