Autopsy  4.15.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.NbBundle;
29 import org.openide.util.lookup.Lookups;
30 import org.openide.util.lookup.ProxyLookup;
35 import org.sleuthkit.datamodel.AbstractFile;
36 import org.sleuthkit.datamodel.BlackboardArtifact;
37 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
38 import org.sleuthkit.datamodel.Content;
39 import org.sleuthkit.datamodel.TskCoreException;
40 import org.sleuthkit.datamodel.TskData;
41 
47 class DirectoryTreeFilterNode extends FilterNode {
48 
49  private static final Logger logger = Logger.getLogger(DirectoryTreeFilterNode.class.getName());
50  private static final Action collapseAllAction = new CollapseAction(NbBundle.getMessage(DirectoryTreeFilterNode.class, "DirectoryTreeFilterNode.action.collapseAll.text"));
51 
61  DirectoryTreeFilterNode(Node nodeToWrap, boolean createChildren) {
62  super(nodeToWrap,
63  DirectoryTreeFilterChildren.createInstance(nodeToWrap, createChildren),
64  new ProxyLookup(Lookups.singleton(nodeToWrap), nodeToWrap.getLookup()));
65  }
66 
73  @Override
74  public String getDisplayName() {
75  final Node orig = getOriginal();
76  String name = orig.getDisplayName();
77 
78  if (orig instanceof AbstractContentNode) {
79  AbstractFile file = getLookup().lookup(AbstractFile.class);
80  if ((file != null) && (false == (orig instanceof BlackboardArtifactNode))) {
81  try {
82  int numVisibleChildren = getVisibleChildCount(file);
83 
84  /*
85  * Left-to-right marks here are necessary to keep the count
86  * and parens together for mixed right-to-left and
87  * left-to-right names.
88  */
89  name = name + " \u200E(\u200E" + numVisibleChildren + ")\u200E"; //NON-NLS
90 
91  } catch (TskCoreException ex) {
92  logger.log(Level.SEVERE, "Error getting children count to display for file: " + file, ex); //NON-NLS
93  }
94  } else if (orig instanceof BlackboardArtifactNode) {
95  BlackboardArtifact artifact = ((BlackboardArtifactNode) orig).getArtifact();
96  try {
97  int numAttachments = artifact.getChildrenCount();
98  name = name + " \u200E(\u200E" + numAttachments + ")\u200E"; //NON-NLS
99  } catch (TskCoreException ex) {
100  logger.log(Level.SEVERE, "Error getting chidlren count for atifact: " + artifact, ex); //NON-NLS
101  }
102  }
103  }
104  return name;
105  }
106 
116  private int getVisibleChildCount(AbstractFile file) throws TskCoreException {
117  List<Content> childList = file.getChildren();
118 
119  int numVisibleChildren = childList.size();
120  boolean purgeKnownFiles = UserPreferences.hideKnownFilesInDataSourcesTree();
121  boolean purgeSlackFiles = UserPreferences.hideSlackFilesInDataSourcesTree();
122 
123  if (purgeKnownFiles || purgeSlackFiles) {
124  // Purge known and/or slack files from the file count
125  for (int i = 0; i < childList.size(); i++) {
126  Content child = childList.get(i);
127  if (child instanceof AbstractFile) {
128  AbstractFile childFile = (AbstractFile) child;
129  if ((purgeKnownFiles && childFile.getKnown() == TskData.FileKnown.KNOWN)
130  || (purgeSlackFiles && childFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
131  numVisibleChildren--;
132  }
133  } else if (child instanceof BlackboardArtifact) {
134 
135  if (FilterNodeUtils.showMessagesInDatasourceTree()) {
136  // In older versions of Autopsy, attachments were children of email/message artifacts
137  // and hence email/messages with attachments are shown in the directory tree.
138  BlackboardArtifact bba = (BlackboardArtifact) child;
139  // Only message type artifacts are displayed in the tree
140  if ((bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
141  && (bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())) {
142  numVisibleChildren--;
143  }
144  }
145  else {
146  numVisibleChildren--;
147  }
148  }
149  }
150  }
151 
152  return numVisibleChildren;
153  }
154 
163  @Override
164  public Action[] getActions(boolean context) {
165  List<Action> actions = new ArrayList<>();
166 
167  final Content content = this.getLookup().lookup(Content.class);
168  if (content != null) {
169  actions.addAll(Arrays.asList(super.getActions(true)));
170  }
171  actions.add(collapseAllAction);
172  return actions.toArray(new Action[actions.size()]);
173  }
174 
180  @Override
181  public Node getOriginal() {
182  return super.getOriginal();
183  }
184 
185 }

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