Autopsy  4.4.1
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-2017 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.Lookups;
34 import org.openide.util.lookup.ProxyLookup;
42 import org.sleuthkit.datamodel.AbstractFile;
43 import org.sleuthkit.datamodel.Content;
44 import org.sleuthkit.datamodel.ContentVisitor;
45 import org.sleuthkit.datamodel.DerivedFile;
46 import org.sleuthkit.datamodel.Directory;
47 import org.sleuthkit.datamodel.File;
48 import org.sleuthkit.datamodel.LayoutFile;
49 import org.sleuthkit.datamodel.LocalFile;
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 
59  KeywordSearchFilterNode(QueryResults highlights, Node original) {
60  super(original, null, new ProxyLookup(Lookups.singleton(highlights), original.getLookup()));
61  }
62 
63  @Override
64  public Node.PropertySet[] getPropertySets() {
65  Node.PropertySet[] propertySets = super.getPropertySets();
66 
67  for (int i = 0; i < propertySets.length; i++) {
68  Node.PropertySet ps = propertySets[i];
69 
70  if (ps.getName().equals(Sheet.PROPERTIES)) {
71  Sheet.Set newPs = new Sheet.Set();
72  newPs.setName(ps.getName());
73  newPs.setDisplayName(ps.getDisplayName());
74  newPs.setShortDescription(ps.getShortDescription());
75 
76  Property<?>[] oldProperties = ps.getProperties();
77 
78  int j = 0;
79  for (Property<?> p : oldProperties) {
80  newPs.put(p);
81  }
82 
83  propertySets[i] = newPs;
84  }
85  }
86 
87  return propertySets;
88  }
89 
98  @Override
99  public Action[] getActions(boolean popup) {
100 
101  List<Action> actions = new ArrayList<>();
102  actions.addAll(Arrays.asList(super.getActions(popup)));
103  Content content = this.getOriginal().getLookup().lookup(Content.class);
104  actions.addAll(content.accept(new GetPopupActionsContentVisitor()));
105 
106  return actions.toArray(new Action[actions.size()]);
107  }
108 
109  private class GetPopupActionsContentVisitor extends ContentVisitor.Default<List<Action>> {
110 
111  @Override
112  public List<Action> visit(File f) {
113  return getFileActions(true);
114  }
115 
116  @Override
117  public List<Action> visit(DerivedFile f) {
118  return getFileActions(true);
119  }
120 
121  @Override
122  public List<Action> visit(Directory d) {
123  return getFileActions(false);
124  }
125 
126  @Override
127  public List<Action> visit(LayoutFile lf) {
128  //we want hashsearch enabled on carved files but not unallocated blocks
129  boolean enableHashSearch = (lf.getType() == TskData.TSK_DB_FILES_TYPE_ENUM.CARVED);
130  return getFileActions(enableHashSearch);
131  }
132 
133  @Override
134  public List<Action> visit(LocalFile lf) {
135  return getFileActions(true);
136  }
137 
138  @Override
139  public List<Action> visit(SlackFile f) {
140  return getFileActions(false);
141  }
142 
143  @Override
144  public List<Action> visit(VirtualDirectory dir) {
145  return getFileActions(false);
146  }
147 
148  private List<Action> getFileActions(boolean enableHashSearch) {
149  List<Action> actionsList = new ArrayList<>();
150  actionsList.add(new NewWindowViewAction(NbBundle.getMessage(this.getClass(), "KeywordSearchFilterNode.getFileActions.viewInNewWinActionLbl"), KeywordSearchFilterNode.this));
151  actionsList.add(new ExternalViewerAction(NbBundle.getMessage(this.getClass(), "KeywordSearchFilterNode.getFileActions.openExternViewActLbl"), getOriginal()));
152  actionsList.add(null);
153  actionsList.add(ExtractAction.getInstance());
154  Action hashSearchAction = new HashSearchAction(NbBundle.getMessage(this.getClass(), "KeywordSearchFilterNode.getFileActions.searchSameMd5"), getOriginal());
155  hashSearchAction.setEnabled(enableHashSearch);
156  actionsList.add(hashSearchAction);
157  actionsList.add(null); // creates a menu separator
158  actionsList.add(AddContentTagAction.getInstance());
159 
160  final Collection<AbstractFile> selectedFilesList
161  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
162  if (selectedFilesList.size() == 1) {
163  actionsList.add(DeleteFileContentTagAction.getInstance());
164  }
165 
166  actionsList.addAll(ContextMenuExtensionPoint.getActions());
167  return actionsList;
168  }
169 
170  @Override
171  protected List<Action> defaultVisit(Content c) {
172  return getFileActions(false);
173  }
174  }
175 }
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
static synchronized AddContentTagAction getInstance()

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