Autopsy  4.4.1
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.Collections;
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;
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.Directory;
41 import org.sleuthkit.datamodel.Image;
42 import org.sleuthkit.datamodel.TskCoreException;
43 import org.sleuthkit.datamodel.TskData;
44 import org.sleuthkit.datamodel.VirtualDirectory;
45 
51 class DirectoryTreeFilterNode extends FilterNode {
52 
53  private static final Logger logger = Logger.getLogger(DirectoryTreeFilterNode.class.getName());
54  private static final Action collapseAllAction = new CollapseAction(NbBundle.getMessage(DirectoryTreeFilterNode.class, "DirectoryTreeFilterNode.action.collapseAll.text"));
55 
65  DirectoryTreeFilterNode(Node nodeToWrap, boolean createChildren) {
66  super(nodeToWrap,
67  DirectoryTreeFilterChildren.createInstance(nodeToWrap, createChildren),
68  new ProxyLookup(Lookups.singleton(nodeToWrap), nodeToWrap.getLookup()));
69  }
70 
77  @Override
78  public String getDisplayName() {
79  final Node orig = getOriginal();
80  String name = orig.getDisplayName();
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  }
98  else if (orig instanceof BlackboardArtifactNode) {
99  BlackboardArtifact artifact = ((BlackboardArtifactNode) orig).getArtifact();
100  try {
101  int numAttachments = artifact.getChildrenCount();
102  name = name + " \u200E(\u200E" + numAttachments + ")\u200E"; //NON-NLS
103  } catch (TskCoreException ex) {
104  logger.log(Level.SEVERE, "Error getting chidlren count for atifact: " + artifact, ex); //NON-NLS
105  }
106  }
107  }
108  return name;
109  }
110 
120  private int getVisibleChildCount(AbstractFile file) throws TskCoreException {
121  List<Content> childList = file.getChildren();
122 
123  int numVisibleChildren = childList.size();
124  boolean purgeKnownFiles = UserPreferences.hideKnownFilesInDataSourcesTree();
125  boolean purgeSlackFiles = UserPreferences.hideSlackFilesInDataSourcesTree();
126 
127  if (purgeKnownFiles || purgeSlackFiles) {
128  // Purge known and/or slack files from the file count
129  for (int i = 0; i < childList.size(); i++) {
130  Content child = childList.get(i);
131  if (child instanceof AbstractFile) {
132  AbstractFile childFile = (AbstractFile) child;
133  if ((purgeKnownFiles && childFile.getKnown() == TskData.FileKnown.KNOWN)
134  || (purgeSlackFiles && childFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
135  numVisibleChildren--;
136  }
137  } else if(child instanceof BlackboardArtifact){
138  BlackboardArtifact bba = (BlackboardArtifact) child;
139 
140  // Only message type artifacts are displayed in the tree
141  if((bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID())
142  && (bba.getArtifactTypeID() != ARTIFACT_TYPE.TSK_MESSAGE.getTypeID())){
143  numVisibleChildren--;
144  }
145  }
146  }
147  }
148 
149 
150  return numVisibleChildren;
151  }
152 
161  @Override
162  public Action[] getActions(boolean context) {
163  List<Action> actions = new ArrayList<>();
164  final Content content = this.getLookup().lookup(Content.class);
165  if (content != null) {
166  actions.addAll(ExplorerNodeActionVisitor.getActions(content));
167 
168  Directory dir = this.getLookup().lookup(Directory.class);
169  if (dir != null) {
170  actions.add(ExtractAction.getInstance());
171  actions.add(new RunIngestModulesAction(dir));
172  }
173 
174  final Image img = this.getLookup().lookup(Image.class);
175  final VirtualDirectory virtualDirectory = this.getLookup().lookup(VirtualDirectory.class);
176  boolean isRootVD = false;
177  if (virtualDirectory != null) {
178  try {
179  if (virtualDirectory.getParent() == null) {
180  isRootVD = true;
181  }
182  } catch (TskCoreException ex) {
183  logger.log(Level.WARNING, "Error determining the parent of the virtual directory", ex); // NON-NLS
184  }
185  }
186  if (img != null || isRootVD) {
187  actions.add(new FileSearchAction(NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text")));
188  actions.add(new RunIngestModulesAction(Collections.<Content>singletonList(content)));
189  }
190  }
191  actions.add(collapseAllAction);
192  return actions.toArray(new Action[actions.size()]);
193  }
194 
200  @Override
201  public Node getOriginal() {
202  return super.getOriginal();
203  }
204 
205 }

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.