Autopsy  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;
42 
48 class DirectoryTreeFilterNode extends FilterNode {
49 
50  private static final Logger logger = Logger.getLogger(DirectoryTreeFilterNode.class.getName());
51  private static final Action collapseAllAction = new CollapseAction(NbBundle.getMessage(DirectoryTreeFilterNode.class, "DirectoryTreeFilterNode.action.collapseAll.text"));
52 
62  DirectoryTreeFilterNode(Node nodeToWrap, boolean createChildren) {
63  super(nodeToWrap,
64  DirectoryTreeFilterChildren.createInstance(nodeToWrap, createChildren),
65  new ProxyLookup(Lookups.singleton(new OriginalNode(nodeToWrap)), nodeToWrap.getLookup()));
66  }
67 
74  @Override
75  public String getDisplayName() {
76  final Node orig = getOriginal();
77  String name = orig.getDisplayName();
78  if (orig instanceof AbstractContentNode) {
79  AbstractFile file = getLookup().lookup(AbstractFile.class);
80  if (file != null) {
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  }
95  }
96  return name;
97  }
98 
108  private int getVisibleChildCount(AbstractFile file) throws TskCoreException {
109  List<Content> childList = file.getChildren();
110 
111  int numVisibleChildren = file.getChildrenCount();
112  boolean purgeKnownFiles = UserPreferences.hideKnownFilesInDataSourcesTree();
113  boolean purgeSlackFiles = UserPreferences.hideSlackFilesInDataSourcesTree();
114 
115  if(purgeKnownFiles || purgeSlackFiles) {
116  // Purge known and/or slack files from the file count
117  for(int i=0; i < childList.size(); i++) {
118  AbstractFile childFile = (AbstractFile)childList.get(i);
119  if((purgeKnownFiles && childFile.getKnown() == TskData.FileKnown.KNOWN)
120  || (purgeSlackFiles && childFile.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
121  numVisibleChildren--;
122  }
123  }
124  }
125 
126  return numVisibleChildren;
127  }
128 
137  @Override
138  public Action[] getActions(boolean context) {
139  List<Action> actions = new ArrayList<>();
140  final Content content = this.getLookup().lookup(Content.class);
141  if (content != null) {
142  actions.addAll(ExplorerNodeActionVisitor.getActions(content));
143 
144  Directory dir = this.getLookup().lookup(Directory.class);
145  if (dir != null) {
146  actions.add(ExtractAction.getInstance());
147  actions.add(new RunIngestModulesAction(dir));
148  }
149 
150  final Image img = this.getLookup().lookup(Image.class);
151  final VirtualDirectory virtualDirectory = this.getLookup().lookup(VirtualDirectory.class);
152  boolean isRootVD = false;
153  if (virtualDirectory != null) {
154  try {
155  if (virtualDirectory.getParent() == null) {
156  isRootVD = true;
157  }
158  } catch (TskCoreException ex) {
159  logger.log(Level.WARNING, "Error determining the parent of the virtual directory", ex); // NON-NLS
160  }
161  }
162  if (img != null || isRootVD) {
163  actions.add(new FileSearchAction(NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text")));
164  actions.add(new RunIngestModulesAction(Collections.<Content>singletonList(content)));
165  }
166  }
167  actions.add(collapseAllAction);
168  return actions.toArray(new Action[actions.size()]);
169  }
170 
171  //FIXME: this seems like a big hack -jm
172  public static class OriginalNode {
173 
174  private final Node original;
175 
176  OriginalNode(Node original) {
177  this.original = original;
178  }
179 
180  Node getNode() {
181  return original;
182  }
183  }
184 }

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