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-2014 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.awt.event.ActionEvent;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.AbstractAction;
27 import javax.swing.Action;
28 import org.openide.nodes.FilterNode;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.Lookups;
32 import org.openide.util.lookup.ProxyLookup;
37 import org.sleuthkit.datamodel.AbstractFile;
38 import org.sleuthkit.datamodel.Content;
39 import org.sleuthkit.datamodel.Directory;
40 import org.sleuthkit.datamodel.Image;
41 import org.sleuthkit.datamodel.TskCoreException;
42 import org.sleuthkit.datamodel.VirtualDirectory;
43 
49 class DirectoryTreeFilterNode extends FilterNode {
50 
51  private static final Action collapseAll = new CollapseAction(
52  NbBundle.getMessage(DirectoryTreeFilterNode.class, "DirectoryTreeFilterNode.action.collapseAll.text"));
53 
54  private static final Logger logger = Logger.getLogger(DirectoryTreeFilterNode.class.getName());
55 
59  DirectoryTreeFilterNode(Node arg, boolean createChildren) {
60  super(arg, DirectoryTreeFilterChildren.createInstance(arg, createChildren),
61  new ProxyLookup(Lookups.singleton(new OriginalNode(arg)),
62  arg.getLookup()));
63  }
64 
65  @Override
66  public String getDisplayName() {
67  final Node orig = getOriginal();
68 
69  String name = orig.getDisplayName();
70 
71  //do not show children counts for non content nodes
72  if (orig instanceof AbstractContentNode) {
73  //show only for file content nodes
74  AbstractFile file = getLookup().lookup(AbstractFile.class);
75  if (file != null) {
76  try {
77  final int numChildren = file.getChildrenCount();
78 
79  // left-to-right marks here are necessary to keep the count and parens together
80  // for mixed right-to-left and left-to-right names
81  name = name + " \u200E(\u200E" + numChildren + ")\u200E";
82  } catch (TskCoreException ex) {
83  logger.log(Level.SEVERE, "Error getting children count to display for file: " + file, ex); //NON-NLS
84  }
85 
86  }
87  }
88 
89  return name;
90  }
91 
99  @Override
100  public Action[] getActions(boolean popup) {
101  List<Action> actions = new ArrayList<>();
102 
103  final Content content = this.getLookup().lookup(Content.class);
104  if (content != null) {
105  actions.addAll(DirectoryTreeFilterNode.getDetailActions(content));
106 
107  //extract dir action
108  Directory dir = this.getLookup().lookup(Directory.class);
109  if (dir != null) {
110  actions.add(ExtractAction.getInstance());
111  actions.add(new AbstractAction(
112  NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.runIngestMods.text")) {
113  @Override
114  public void actionPerformed(ActionEvent e) {
115  final RunIngestModulesDialog ingestDialog = new RunIngestModulesDialog(dir);
116  ingestDialog.display();
117  }
118  });
119  }
120 
121  final Image img = this.getLookup().lookup(Image.class);
122 
123  VirtualDirectory virtualDirectory = this.getLookup().lookup(VirtualDirectory.class);
124  // determine if the virtualDireory is at root-level (Logical File Set).
125  boolean isRootVD = false;
126  if (virtualDirectory != null) {
127  try {
128  if (virtualDirectory.getParent() == null) {
129  isRootVD = true;
130  }
131  } catch (TskCoreException ex) {
132  logger.log(Level.WARNING, "Error determining the parent of the virtual directory", ex); // NON-NLS
133  }
134  }
135 
136  // 'run ingest' action and 'file search' action are added only if the
137  // selected node is img node or a root level virtual directory.
138  if (img != null || isRootVD) {
139  actions.add(new FileSearchAction(
140  NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.openFileSrcByAttr.text")));
141  actions.add(new AbstractAction(
142  NbBundle.getMessage(this.getClass(), "DirectoryTreeFilterNode.action.runIngestMods.text")) {
143  @Override
144  public void actionPerformed(ActionEvent e) {
145  final RunIngestModulesDialog ingestDialog = new RunIngestModulesDialog(Collections.<Content>singletonList(content));
146  ingestDialog.display();
147  }
148  });
149  }
150  }
151 
152  //check if delete actions should be added
153  final Node orig = getOriginal();
154  //TODO add a mechanism to determine if DisplayableItemNode
155  if (orig instanceof DisplayableItemNode) {
156  actions.addAll(getDeleteActions((DisplayableItemNode) orig));
157  }
158 
159  actions.add(collapseAll);
160  return actions.toArray(new Action[actions.size()]);
161  }
162 
163  private static List<Action> getDeleteActions(DisplayableItemNode original) {
164  List<Action> actions = new ArrayList<>();
165  //actions.addAll(original.accept(getDeleteActionVisitor));
166  return actions;
167  }
168 
169  private static List<Action> getDetailActions(Content c) {
170  List<Action> actions = new ArrayList<>();
171 
172  actions.addAll(ExplorerNodeActionVisitor.getActions(c));
173 
174  return actions;
175  }
176 
177  //FIXME: this seems like a big hack -jm
178  public static class OriginalNode {
179 
180  private final Node original;
181 
182  OriginalNode(Node original) {
183  this.original = original;
184  }
185 
186  Node getNode() {
187  return original;
188  }
189  }
190 }

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