Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataResultFilterNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2013 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.beans.PropertyVetoException;
23 import java.util.ArrayList;
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.explorer.ExplorerManager;
29 import org.openide.nodes.AbstractNode;
30 import org.openide.nodes.FilterNode;
31 import org.openide.nodes.Node;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.NbBundle;
71 import org.sleuthkit.datamodel.AbstractFile;
72 import org.sleuthkit.datamodel.BlackboardArtifact;
73 import org.sleuthkit.datamodel.BlackboardAttribute;
74 import org.sleuthkit.datamodel.Content;
75 import org.sleuthkit.datamodel.DerivedFile;
76 import org.sleuthkit.datamodel.Directory;
77 import org.sleuthkit.datamodel.File;
78 import org.sleuthkit.datamodel.LayoutFile;
79 import org.sleuthkit.datamodel.LocalFile;
80 import org.sleuthkit.datamodel.TskException;
81 import org.sleuthkit.datamodel.VirtualDirectory;
82 
87 public class DataResultFilterNode extends FilterNode {
88 
89  private ExplorerManager sourceEm;
90 
92 
94 
100  public DataResultFilterNode(Node node, ExplorerManager em) {
101  super(node, new DataResultFilterChildren(node, em));
102  this.sourceEm = em;
103  getActionsDIV = new GetPopupActionsDisplayableItemNodeVisitor();
104  getPreferredActionsDIV = new GetPreferredActionsDisplayableItemNodeVisitor();
105  }
106 
115  @Override
116  public Action[] getActions(boolean popup) {
117 
118  List<Action> actions = new ArrayList<>();
119 
120  final DisplayableItemNode originalNode = (DisplayableItemNode) this.getOriginal();
121  List<Action> accept = originalNode.accept(getActionsDIV);
122  if (accept != null) {
123  actions.addAll(accept);
124  }
125 
126  //actions.add(new IndexContentFilesAction(nodeContent, "Index"));
127  return actions.toArray(new Action[actions.size()]);
128  }
129 
136  @Override
137  public Action getPreferredAction() {
138  final Node original = this.getOriginal();
139  // Once had a org.openide.nodes.ChildFactory$WaitFilterNode passed in
140  if ((original instanceof DisplayableItemNode) == false) {
141  return null;
142  }
143 
144  final DisplayableItemNode originalNode = (DisplayableItemNode) this.getOriginal();
145  return originalNode.accept(getPreferredActionsDIV);
146  }
147 
148  @Override
149  public Node.PropertySet[] getPropertySets() {
150  Node.PropertySet[] propertySets = super.getPropertySets();
151 
152  for (int i = 0; i < propertySets.length; i++) {
153  Node.PropertySet ps = propertySets[i];
154 
155  if (ps.getName().equals(Sheet.PROPERTIES)) {
156  Sheet.Set newPs = new Sheet.Set();
157  newPs.setName(ps.getName());
158  newPs.setDisplayName(ps.getDisplayName());
159  newPs.setShortDescription(ps.getShortDescription());
160 
161  newPs.put(ps.getProperties());
162  if (newPs.remove(AbstractFsContentNode.HIDE_PARENT) != null) {
163  newPs.remove(AbstractFilePropertyType.LOCATION.toString());
164  }
165  propertySets[i] = newPs;
166  }
167  }
168 
169  return propertySets;
170  }
171 
176  private static class GetPopupActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<List<Action>> {
177 
178  @Override
179  public List<Action> visit(BlackboardArtifactNode ban) {
180  //set up actions for artifact node based on its Content object
181  //TODO all actions need to be consolidated in single place!
182  //they should be set in individual Node subclass and using a utility to get Actions per Content sub-type
183  // TODO UPDATE: There is now a DataModelActionsFactory utility;
184 
185  List<Action> actions = new ArrayList<>();
186 
187  //merge predefined specific node actions if bban subclasses have their own
188  for (Action a : ban.getActions(true)) {
189  actions.add(a);
190  }
191  BlackboardArtifact ba = ban.getLookup().lookup(BlackboardArtifact.class);
192  final int artifactTypeID = ba.getArtifactTypeID();
193 
194  if (artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_HASHSET_HIT.getTypeID()
195  || artifactTypeID == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
196  actions.add(new ViewContextAction(
197  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), ban));
198  } else {
199  // if the artifact links to another file, add an action to go to
200  // that file
201  Content c = findLinked(ban);
202  if (c != null) {
203  actions.add(new ViewContextAction(
204  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewFileInDir.text"), c));
205  }
206  // action to go to the source file of the artifact
207  actions.add(new ViewContextAction(
208  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewSrcFileInDir.text"), ban));
209  }
210  Content c = ban.getLookup().lookup(File.class);
211  Node n = null;
212  boolean md5Action = false;
213  if (c != null) {
214  n = new FileNode((AbstractFile) c);
215  md5Action = true;
216  } else if ((c = ban.getLookup().lookup(Directory.class)) != null) {
217  n = new DirectoryNode((Directory) c);
218  } else if ((c = ban.getLookup().lookup(VirtualDirectory.class)) != null) {
219  n = new VirtualDirectoryNode((VirtualDirectory) c);
220  } else if ((c = ban.getLookup().lookup(LayoutFile.class)) != null) {
221  n = new LayoutFileNode((LayoutFile) c);
222  } else if ((c = ban.getLookup().lookup(LocalFile.class)) != null
223  || (c = ban.getLookup().lookup(DerivedFile.class)) != null) {
224  n = new LocalFileNode((AbstractFile) c);
225  }
226  if (n != null) {
227  actions.add(null); // creates a menu separator
228  actions.add(new NewWindowViewAction(
229  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInNewWin.text"), n));
230  actions.add(new ExternalViewerAction(
231  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.openInExtViewer.text"), n));
232  actions.add(null); // creates a menu separator
233  actions.add(ExtractAction.getInstance());
234  if (md5Action) {
235  actions.add(new HashSearchAction(
236  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.searchFilesSameMd5.text"), n));
237  }
238  actions.add(null); // creates a menu separator
239  actions.add(AddContentTagAction.getInstance());
241  actions.addAll(ContextMenuExtensionPoint.getActions());
242  } else {
243  // There's no specific file associated with the artifact, but
244  // we can still tag the artifact itself
245  actions.add(null);
247  }
248  return actions;
249  }
250 
251  @Override
252  public List<Action> visit(Reports.ReportsListNode ditem) {
253  // The base class Action is "Collapse All", inappropriate.
254  return null;
255  }
256 
257  @Override
258  protected List<Action> defaultVisit(DisplayableItemNode ditem) {
259  //preserve the default node's actions
260  List<Action> actions = new ArrayList<>();
261 
262  for (Action action : ditem.getActions(true)) {
263  actions.add(action);
264  }
265 
266  return actions;
267  }
268 
269  private Content findLinked(BlackboardArtifactNode ba) {
270  BlackboardArtifact art = ba.getLookup().lookup(BlackboardArtifact.class);
271  Content c = null;
272  try {
273  for (BlackboardAttribute attr : art.getAttributes()) {
274  if (attr.getAttributeType().getTypeID() == BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH_ID.getTypeID()) {
275  switch (attr.getAttributeType().getValueType()) {
276  case INTEGER:
277  int i = attr.getValueInt();
278  if (i != -1) {
279  c = art.getSleuthkitCase().getContentById(i);
280  }
281  break;
282  case LONG:
283  long l = attr.getValueLong();
284  if (l != -1) {
285  c = art.getSleuthkitCase().getContentById(l);
286  }
287  break;
288  }
289  }
290  }
291  } catch (TskException ex) {
292  Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error getting linked file", ex); //NON-NLS
293  }
294  return c;
295  }
296  }
297 
298  /*
299  * Action for double-click / preferred action on nodes.
300  */
301  private class GetPreferredActionsDisplayableItemNodeVisitor extends DisplayableItemNodeVisitor.Default<AbstractAction> {
302 
303  @Override
304  public AbstractAction visit(ImageNode in) {
305  return openChild(in);
306  }
307 
308  @Override
309  public AbstractAction visit(VolumeNode vn) {
310  return openChild(vn);
311  }
312 
313  @Override
314  public AbstractAction visit(ExtractedContent.RootNode ecn) {
315  return openChild(ecn);
316  }
317 
318  @Override
319  public AbstractAction visit(KeywordHits.RootNode khrn) {
320  return openChild(khrn);
321  }
322 
323  @Override
324  public AbstractAction visit(HashsetHits.RootNode hhrn) {
325  return openChild(hhrn);
326  }
327 
328  @Override
329  public AbstractAction visit(HashsetNameNode hhsn) {
330  return openChild(hhsn);
331  }
332 
333  @Override
334  public AbstractAction visit(InterestingHits.RootNode iarn) {
335  return openChild(iarn);
336  }
337 
338  @Override
339  public AbstractAction visit(InterestingHits.SetNameNode iasn) {
340  return openChild(iasn);
341  }
342 
343  @Override
344  public AbstractAction visit(EmailExtracted.RootNode eern) {
345  return openChild(eern);
346  }
347 
348  @Override
349  public AbstractAction visit(AccountNode eean) {
350  return openChild(eean);
351  }
352 
353  @Override
354  public AbstractAction visit(FolderNode eefn) {
355  return openChild(eefn);
356  }
357 
358  @Override
359  public AbstractAction visit(RecentFilesNode rfn) {
360  return openChild(rfn);
361  }
362 
363  @Override
364  public AbstractAction visit(DeletedContentsNode dcn) {
365  return openChild(dcn);
366  }
367 
368  @Override
369  public AbstractAction visit(DeletedContentNode dcn) {
370  return openChild(dcn);
371  }
372 
373  @Override
374  public AbstractAction visit(FileSizeRootNode fsrn) {
375  return openChild(fsrn);
376  }
377 
378  @Override
379  public AbstractAction visit(FileSizeNode fsn) {
380  return openChild(fsn);
381  }
382 
383  @Override
384  public AbstractAction visit(BlackboardArtifactNode ban) {
385  return new ViewContextAction(
386  NbBundle.getMessage(this.getClass(), "DataResultFilterNode.action.viewInDir.text"), ban);
387  }
388 
389  @Override
390  public AbstractAction visit(TypeNode atn) {
391  return openChild(atn);
392  }
393 
394  @Override
395  public AbstractAction visit(Tags.TagNameNode node) {
396  return openChild(node);
397  }
398 
399  @Override
400  public AbstractAction visit(Tags.ContentTagTypeNode node) {
401  return openChild(node);
402  }
403 
404  @Override
405  public AbstractAction visit(Tags.BlackboardArtifactTagTypeNode node) {
406  return openChild(node);
407  }
408 
409  @Override
410  public AbstractAction visit(DirectoryNode dn) {
411  if (dn.getDisplayName().equals(DirectoryNode.DOTDOTDIR)) {
412  return openParent(dn);
413  } else if (dn.getDisplayName().equals(DirectoryNode.DOTDIR) == false) {
414  return openChild(dn);
415  } else {
416  return null;
417  }
418  }
419 
420  @Override
421  public AbstractAction visit(VirtualDirectoryNode ldn) {
422  return openChild(ldn);
423  }
424 
425  @Override
426  public AbstractAction visit(FileNode fn) {
427  if (fn.hasContentChildren()) {
428  return openChild(fn);
429  } else {
430  return null;
431  }
432  }
433 
434  @Override
435  public AbstractAction visit(LocalFileNode dfn) {
436  if (dfn.hasContentChildren()) {
437  return openChild(dfn);
438  } else {
439  return null;
440  }
441  }
442 
443  @Override
444  public AbstractAction visit(FileTypeNode fsfn) {
445  return openChild(fsfn);
446  }
447 
448  @Override
449  public AbstractAction visit(FileTypesNode sfn) {
450  return openChild(sfn);
451  }
452 
453  @Override
454  public AbstractAction visit(RecentFilesFilterNode rffn) {
455  return openChild(rffn);
456  }
457 
458  @Override
459  public AbstractAction visit(ListNode khsn) {
460  return openChild(khsn);
461  }
462 
463  @Override
464  public AbstractAction visit(TermNode khmln) {
465  return openChild(khmln);
466  }
467 
468  @Override
469  public AbstractAction visit(Reports.ReportNode reportNode) {
470  return reportNode.getPreferredAction();
471  }
472 
473  @Override
474  protected AbstractAction defaultVisit(DisplayableItemNode c) {
475  return null;
476  }
477 
486  private AbstractAction openChild(final AbstractNode dataModelNode) {
487  // get the current selection from the directory tree explorer manager,
488  // which is a DirectoryTreeFilterNode. One of that node's children
489  // is a DirectoryTreeFilterNode that wraps the dataModelNode. We need
490  // to set that wrapped node as the selection and root context of the
491  // directory tree explorer manager (sourceEm)
492  final Node currentSelectionInDirectoryTree = sourceEm.getSelectedNodes()[0];
493 
494  return new AbstractAction() {
495  @Override
496  public void actionPerformed(ActionEvent e) {
497  if (currentSelectionInDirectoryTree != null) {
498  // Find the filter version of the passed in dataModelNode.
499  final org.openide.nodes.Children children = currentSelectionInDirectoryTree.getChildren();
500  // This call could break if the DirectoryTree is re-implemented with lazy ChildFactory objects.
501  Node newSelection = children.findChild(dataModelNode.getName());
502 
503  /*
504  * We got null here when we were viewing a ZIP file in
505  * the Views -> Archives area and double clicking on it
506  * got to this code. It tried to find the child in the
507  * tree and didn't find it. An exception was then thrown
508  * from setting the selected node to be null.
509  */
510  if (newSelection != null) {
511  try {
512  sourceEm.setExploredContextAndSelection(newSelection, new Node[]{newSelection});
513  } catch (PropertyVetoException ex) {
514  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
515  logger.log(Level.WARNING, "Error: can't open the selected directory.", ex); //NON-NLS
516  }
517  }
518  }
519  }
520  };
521  }
522 
531  private AbstractAction openParent(AbstractNode node) {
532  // @@@ Why do we ignore node?
533  Node[] selectedFilterNodes = sourceEm.getSelectedNodes();
534  Node selectedFilterNode = selectedFilterNodes[0];
535  final Node parentNode = selectedFilterNode.getParentNode();
536 
537  return new AbstractAction() {
538  @Override
539  public void actionPerformed(ActionEvent e) {
540  try {
541  sourceEm.setSelectedNodes(new Node[]{parentNode});
542  } catch (PropertyVetoException ex) {
543  Logger logger = Logger.getLogger(DataResultFilterNode.class.getName());
544  logger.log(Level.WARNING, "Error: can't open the parent directory.", ex); //NON-NLS
545  }
546  }
547  };
548  }
549  }
550 }
final DisplayableItemNodeVisitor< List< Action > > getActionsDIV
static synchronized AddBlackboardArtifactTagAction getInstance()
abstract< T > T accept(DisplayableItemNodeVisitor< T > v)
static synchronized ExtractAction getInstance()
final DisplayableItemNodeVisitor< AbstractAction > getPreferredActionsDIV
synchronized static Logger getLogger(String name)
Definition: Logger.java:166
static synchronized AddContentTagAction getInstance()

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