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

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