Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AdHocSearchFilterNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2018 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.keywordsearch;
20 
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.HashSet;
25 import java.util.List;
26 import javax.swing.Action;
27 import org.openide.nodes.FilterNode;
28 import org.openide.nodes.Node;
29 import org.openide.nodes.Node.Property;
30 import org.openide.nodes.Sheet;
31 import org.openide.util.NbBundle;
32 import org.openide.util.Utilities;
33 import org.openide.util.lookup.ProxyLookup;
41 import org.sleuthkit.datamodel.AbstractFile;
42 import org.sleuthkit.datamodel.Content;
43 import org.sleuthkit.datamodel.ContentVisitor;
44 import org.sleuthkit.datamodel.DerivedFile;
45 import org.sleuthkit.datamodel.Directory;
46 import org.sleuthkit.datamodel.File;
47 import org.sleuthkit.datamodel.LayoutFile;
48 import org.sleuthkit.datamodel.LocalFile;
49 import org.sleuthkit.datamodel.Report;
50 import org.sleuthkit.datamodel.SlackFile;
51 import org.sleuthkit.datamodel.TskData;
52 import org.sleuthkit.datamodel.VirtualDirectory;
53 
59 class AdHocSearchFilterNode extends FilterNode {
60 
66  AdHocSearchFilterNode(Node original) {
67  super(original, null, new ProxyLookup(original.getLookup()));
68  }
69 
70  @Override
71  public Node.PropertySet[] getPropertySets() {
72  Node.PropertySet[] propertySets = super.getPropertySets();
73 
74  for (int i = 0; i < propertySets.length; i++) {
75  Node.PropertySet ps = propertySets[i];
76 
77  if (ps.getName().equals(Sheet.PROPERTIES)) {
78  Sheet.Set newPs = new Sheet.Set();
79  newPs.setName(ps.getName());
80  newPs.setDisplayName(ps.getDisplayName());
81  newPs.setShortDescription(ps.getShortDescription());
82 
83  Property<?>[] oldProperties = ps.getProperties();
84 
85  int j = 0;
86  for (Property<?> p : oldProperties) {
87  newPs.put(p);
88  }
89 
90  propertySets[i] = newPs;
91  }
92  }
93 
94  return propertySets;
95  }
96 
105  @Override
106  public Action[] getActions(boolean popup) {
107 
108  List<Action> actions = new ArrayList<>();
109  actions.addAll(Arrays.asList(super.getActions(popup)));
110  Content content = this.getOriginal().getLookup().lookup(Content.class);
111  actions.addAll(content.accept(new GetPopupActionsContentVisitor()));
112 
113  return actions.toArray(new Action[actions.size()]);
114  }
115 
116  private class GetPopupActionsContentVisitor extends ContentVisitor.Default<List<Action>> {
117 
118  @Override
119  public List<Action> visit(Report r) {
120  List<Action> actionsList = new ArrayList<>();
121  actionsList.add(new NewWindowViewAction(NbBundle.getMessage(this.getClass(), "KeywordSearchFilterNode.getFileActions.viewInNewWinActionLbl"), AdHocSearchFilterNode.this));
122 
123  actionsList.addAll(ContextMenuExtensionPoint.getActions());
124  return actionsList;
125  }
126 
127  @Override
128  public List<Action> visit(File f) {
129  return getFileActions(true);
130  }
131 
132  @Override
133  public List<Action> visit(DerivedFile f) {
134  return getFileActions(true);
135  }
136 
137  @Override
138  public List<Action> visit(Directory d) {
139  return getFileActions(false);
140  }
141 
142  @Override
143  public List<Action> visit(LayoutFile lf) {
144  //we want hashsearch enabled on carved files but not unallocated blocks
145  boolean enableHashSearch = (lf.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.CARVED);
146  return getFileActions(enableHashSearch);
147  }
148 
149  @Override
150  public List<Action> visit(LocalFile lf) {
151  return getFileActions(true);
152  }
153 
154  @Override
155  public List<Action> visit(SlackFile f) {
156  return getFileActions(false);
157  }
158 
159  @Override
160  public List<Action> visit(VirtualDirectory dir) {
161  return getFileActions(false);
162  }
163 
164  private List<Action> getFileActions(boolean enableHashSearch) {
165  List<Action> actionsList = new ArrayList<>();
166  actionsList.add(new NewWindowViewAction(NbBundle.getMessage(this.getClass(), "KeywordSearchFilterNode.getFileActions.viewInNewWinActionLbl"), AdHocSearchFilterNode.this));
167  actionsList.add(new ExternalViewerAction(NbBundle.getMessage(this.getClass(), "KeywordSearchFilterNode.getFileActions.openExternViewActLbl"), getOriginal()));
168  actionsList.add(null);
169  actionsList.add(ExtractAction.getInstance());
170  Action hashSearchAction = new HashSearchAction(NbBundle.getMessage(this.getClass(), "KeywordSearchFilterNode.getFileActions.searchSameMd5"), getOriginal());
171  hashSearchAction.setEnabled(enableHashSearch);
172  actionsList.add(hashSearchAction);
173  actionsList.add(null); // creates a menu separator
174  actionsList.add(AddContentTagAction.getInstance());
175 
176  final Collection<AbstractFile> selectedFilesList
177  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
178  if (selectedFilesList.size() == 1) {
179  actionsList.add(DeleteFileContentTagAction.getInstance());
180  }
181 
182  actionsList.addAll(ContextMenuExtensionPoint.getActions());
183  return actionsList;
184  }
185 
186  @Override
187  protected List<Action> defaultVisit(Content c) {
188  return getFileActions(false);
189  }
190  }
191 }
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
static synchronized AddContentTagAction getInstance()

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