Autopsy  4.5.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.Collections;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.Action;
27 import org.openide.nodes.FilterNode;
28 import org.openide.nodes.Node;
29 import org.openide.util.NbBundle;
30 import org.openide.util.lookup.Lookups;
31 import org.openide.util.lookup.ProxyLookup;
37 import org.sleuthkit.datamodel.AbstractFile;
38 import org.sleuthkit.datamodel.BlackboardArtifact;
39 import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
40 import org.sleuthkit.datamodel.Content;
41 import org.sleuthkit.datamodel.Directory;
42 import org.sleuthkit.datamodel.Image;
43 import org.sleuthkit.datamodel.TskCoreException;
44 import org.sleuthkit.datamodel.TskData;
45 import org.sleuthkit.datamodel.VirtualDirectory;
46 import org.sleuthkit.datamodel.Volume;
47 
53 class DirectoryTreeFilterNode extends FilterNode {
54 
55  private static final Logger logger = Logger.getLogger(DirectoryTreeFilterNode.class.getName());
56  private static final Action collapseAllAction = new CollapseAction(NbBundle.getMessage(DirectoryTreeFilterNode.class, "DirectoryTreeFilterNode.action.collapseAll.text"));
57 
67  DirectoryTreeFilterNode(Node nodeToWrap, boolean createChildren) {
68  super(nodeToWrap,
69  DirectoryTreeFilterChildren.createInstance(nodeToWrap, createChildren),
70  new ProxyLookup(Lookups.singleton(nodeToWrap), nodeToWrap.getLookup()));
71  }
72 
79  @Override
80  public String getDisplayName() {
81  final Node orig = getOriginal();
82  String name = orig.getDisplayName();
83 
84  if (orig instanceof AbstractContentNode) {
85  AbstractFile file = getLookup().lookup(AbstractFile.class);
86  if ((file != null) && (false == (orig instanceof BlackboardArtifactNode))) {
87  try {
88  int numVisibleChildren = getVisibleChildCount(file);
89 
90  /*
91  * Left-to-right marks here are necessary to keep the count
92  * and parens together for mixed right-to-left and
93  * left-to-right names.
94  */
95  name = name + " \u200E(\u200E" + numVisibleChildren + ")\u200E"; //NON-NLS
96 
97  } catch (TskCoreException ex) {
98  logger.log(Level.SEVERE, "Error getting children count to display for file: " + file, ex); //NON-NLS
99  }
100  } else if (orig instanceof BlackboardArtifactNode) {
101  BlackboardArtifact artifact = ((BlackboardArtifactNode) orig).getArtifact();
102  try {
103  int numAttachments = artifact.getChildrenCount();
104  name = name + " \u200E(\u200E" + numAttachments + ")\u200E"; //NON-NLS
105  } catch (TskCoreException ex) {
106  logger.log(Level.SEVERE, "Error getting chidlren count for atifact: " + artifact, ex); //NON-NLS
107  }
108  }
109  }
110  return name;
111  }
112 
122  private int getVisibleChildCount(AbstractFile file) throws TskCoreException {
123  List<Content> childList = file.getChildren();
124 
125  int numVisibleChildren = childList.size();
126  boolean purgeKnownFiles = UserPreferences.hideKnownFilesInDataSourcesTree();
127  boolean purgeSlackFiles = UserPreferences.hideSlackFilesInDataSourcesTree();
128 
129  if (purgeKnownFiles || purgeSlackFiles) {
130  // Purge known and/or slack files from the file count
131  for (int i = 0; i < childList.size(); i++) {
132  Content child = childList.get(i);
133  if (child instanceof AbstractFile) {
134  AbstractFile childFile = (AbstractFile) child;
135  if ((purgeKnownFiles && childFile.getKnown() == TskData.FileKnown.KNOWN)
136  || (purgeSlackFiles && childFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
137  numVisibleChildren--;
138  }
139  } else if (child instanceof BlackboardArtifact) {
140  BlackboardArtifact bba = (BlackboardArtifact) child;
141 
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  }
148  }
149  }
150 
151  return numVisibleChildren;
152  }
153 
162  @Override
163  public Action[] getActions(boolean context) {
164  List<Action> actions = new ArrayList<>();
165 
166  final Content content = this.getLookup().lookup(Content.class);
167  if (content != null) {
168  actions.addAll(Arrays.asList(super.getActions(true)));
169  }
170  actions.add(collapseAllAction);
171  return actions.toArray(new Action[actions.size()]);
172  }
173 
179  @Override
180  public Node getOriginal() {
181  return super.getOriginal();
182  }
183 
184 }

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