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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.