Autopsy  4.21.0
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  name = name + " (" + numVisibleChildren + ")"; //NON-NLS
88 
89  } catch (TskCoreException ex) {
90  logger.log(Level.SEVERE, "Error getting children count to display for file: " + file, ex); //NON-NLS
91  }
92  } else if (orig instanceof BlackboardArtifactNode) {
93  BlackboardArtifact artifact = ((BlackboardArtifactNode) orig).getArtifact();
94  try {
95  int numAttachments = artifact.getChildrenCount();
96  name = name + " (" + numAttachments + ")"; //NON-NLS
97  } catch (TskCoreException ex) {
98  logger.log(Level.SEVERE, "Error getting chidlren count for atifact: " + artifact, ex); //NON-NLS
99  }
100  }
101  }
102  return name;
103  }
104 
114  private int getVisibleChildCount(AbstractFile file) throws TskCoreException {
115  List<Content> childList = file.getChildren();
116 
117  int numVisibleChildren = childList.size();
118  boolean purgeKnownFiles = UserPreferences.hideKnownFilesInDataSourcesTree();
119  boolean purgeSlackFiles = UserPreferences.hideSlackFilesInDataSourcesTree();
120 
121  if (purgeKnownFiles || purgeSlackFiles) {
122  // Purge known and/or slack files from the file count
123  for (int i = 0; i < childList.size(); i++) {
124  Content child = childList.get(i);
125  if (child instanceof AbstractFile) {
126  AbstractFile childFile = (AbstractFile) child;
127  if ((purgeKnownFiles && childFile.getKnown() == TskData.FileKnown.KNOWN)
128  || (purgeSlackFiles && childFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
129  numVisibleChildren--;
130  }
131  } else if (child instanceof BlackboardArtifact) {
132 
133  if (FilterNodeUtils.showMessagesInDatasourceTree()) {
134  // In older versions of Autopsy, attachments were children of email/message artifacts
135  // and hence email/messages with attachments are shown in the directory tree.
136  BlackboardArtifact bba = (BlackboardArtifact) child;
137  // Only message type artifacts are displayed in the tree
138  if ((bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
139  && (bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
140  numVisibleChildren--;
141  }
142  } else {
143  numVisibleChildren--;
144  }
145  }
146  }
147  }
148 
149  return numVisibleChildren;
150  }
151 
160  @Override
161  public Action[] getActions(boolean context) {
162  List<Action> actions = new ArrayList<>();
163  actions.addAll(Arrays.asList(getNodeActions()));
164  actions.add(collapseAllAction);
165  return actions.toArray(new Action[actions.size()]);
166  }
167 
172  private Action[] getNodeActions() {
173  Lookup lookup = this.getLookup();
174  if (lookup.lookup(Content.class) != null
175  || lookup.lookup(Host.class) != null
176  || lookup.lookup(Person.class) != null) {
177  return super.getActions(true);
178  } else {
179  return new Action[0];
180  }
181  }
182 
188  @Override
189  public Node getOriginal() {
190  return super.getOriginal();
191  }
192 
193 }

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