Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExplorerNodeActionVisitor.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-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.directorytree;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.AbstractAction;
28 import javax.swing.Action;
29 import org.openide.util.NbBundle;
30 import org.openide.util.Utilities;
35 import org.sleuthkit.datamodel.AbstractFile;
36 import org.sleuthkit.datamodel.Content;
37 import org.sleuthkit.datamodel.ContentVisitor;
38 import org.sleuthkit.datamodel.DerivedFile;
39 import org.sleuthkit.datamodel.Directory;
40 import org.sleuthkit.datamodel.FileSystem;
41 import org.sleuthkit.datamodel.Image;
42 import org.sleuthkit.datamodel.LocalFile;
43 import org.sleuthkit.datamodel.LocalDirectory;
44 import org.sleuthkit.datamodel.VirtualDirectory;
45 import org.sleuthkit.datamodel.Volume;
47 
48 public class ExplorerNodeActionVisitor extends ContentVisitor.Default<List<? extends Action>> {
49 
51 
52  public static List<Action> getActions(Content c) {
53  List<Action> actions = new ArrayList<>();
54 
55  actions.addAll(c.accept(instance));
56  //TODO: fix this
57  /*
58  * while (c.isOnto()) { try { List<? extends Content> children =
59  * c.getChildren(); if (!children.isEmpty()) { c =
60  * c.getChildren().get(0); } else { return actions; } } catch
61  * (TskException ex) {
62  * Log.get(ExplorerNodeActionVisitor.class).log(Level.WARNING, "Error
63  * getting show detail actions.", ex); return actions; }
64  * actions.addAll(c.accept(instance));
65  }
66  */
67  return actions;
68  }
69 
71  }
72 
73  @Override
74  public List<? extends Action> visit(final Image img) {
75  List<Action> lst = new ArrayList<>();
76  //TODO lst.add(new ExtractAction("Extract Image", img));
77  try {
78  lst.add(new ExtractUnallocAction(
79  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.extUnallocToSingleFiles"), img));
80  } catch (NoCurrentCaseException ex) {
81  Logger.getLogger(ExplorerNodeActionVisitor.class.getName()).log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
82  }
83  return lst;
84  }
85 
86  @Override
87  public List<? extends Action> visit(final FileSystem fs) {
88  return new ArrayList<>();
89  }
90 
91  @Override
92  public List<? extends Action> visit(final Volume vol) {
93  List<AbstractAction> lst = new ArrayList<>();
94  lst.add(new ExtractUnallocAction(
95  NbBundle.getMessage(this.getClass(), "ExplorerNodeActionVisitor.action.extUnallocToSingleFile"), vol));
96 
97  return lst;
98  }
99 
100  @Override
101  public List<? extends Action> visit(final Directory d) {
102  List<Action> actionsList = new ArrayList<>();
103  actionsList.add(AddContentTagAction.getInstance());
104 
105  final Collection<AbstractFile> selectedFilesList =
106  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
107  if(selectedFilesList.size() == 1) {
108  actionsList.add(DeleteFileContentTagAction.getInstance());
109  }
110 
111  actionsList.addAll(ContextMenuExtensionPoint.getActions());
112  return actionsList;
113  }
114 
115  @Override
116  public List<? extends Action> visit(final VirtualDirectory d) {
117  List<Action> actionsList = new ArrayList<>();
118  if (!d.isDataSource()) {
119  actionsList.add(AddContentTagAction.getInstance());
120 
121  final Collection<AbstractFile> selectedFilesList =
122  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
123  if(selectedFilesList.size() == 1) {
124  actionsList.add(DeleteFileContentTagAction.getInstance());
125  }
126  }
127  actionsList.add(ExtractAction.getInstance());
128  actionsList.add(ExportCSVAction.getInstance());
129  actionsList.addAll(ContextMenuExtensionPoint.getActions());
130  return actionsList;
131  }
132 
133  @Override
134  public List<? extends Action> visit(final LocalDirectory d) {
135  List<Action> actionsList = new ArrayList<>();
136  if (!d.isDataSource()) {
137  actionsList.add(AddContentTagAction.getInstance());
138 
139  final Collection<AbstractFile> selectedFilesList =
140  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
141  if(selectedFilesList.size() == 1) {
142  actionsList.add(DeleteFileContentTagAction.getInstance());
143  }
144  }
145  actionsList.add(ExtractAction.getInstance());
146  actionsList.add(ExportCSVAction.getInstance());
147  actionsList.addAll(ContextMenuExtensionPoint.getActions());
148  return actionsList;
149  }
150 
151  @Override
152  public List<? extends Action> visit(final DerivedFile d) {
153  List<Action> actionsList = new ArrayList<>();
154  actionsList.add(ExtractAction.getInstance());
155  actionsList.add(ExportCSVAction.getInstance());
156  actionsList.add(AddContentTagAction.getInstance());
157 
158  final Collection<AbstractFile> selectedFilesList =
159  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
160  if(selectedFilesList.size() == 1) {
161  actionsList.add(DeleteFileContentTagAction.getInstance());
162  }
163 
164  actionsList.addAll(ContextMenuExtensionPoint.getActions());
165  return actionsList;
166  }
167 
168  @Override
169  public List<? extends Action> visit(final LocalFile d) {
170  List<Action> actionsList = new ArrayList<>();
171  actionsList.add(ExtractAction.getInstance());
172  actionsList.add(ExportCSVAction.getInstance());
173  actionsList.add(AddContentTagAction.getInstance());
174 
175  final Collection<AbstractFile> selectedFilesList =
176  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
177  if(selectedFilesList.size() == 1) {
178  actionsList.add(DeleteFileContentTagAction.getInstance());
179  }
180 
181  actionsList.addAll(ContextMenuExtensionPoint.getActions());
182  return actionsList;
183  }
184 
185  @Override
186  public List<? extends Action> visit(final org.sleuthkit.datamodel.File d) {
187  List<Action> actionsList = new ArrayList<>();
188  actionsList.add(ExtractAction.getInstance());
189  actionsList.add(ExportCSVAction.getInstance());
190  actionsList.add(AddContentTagAction.getInstance());
191 
192  final Collection<AbstractFile> selectedFilesList =
193  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
194  if(selectedFilesList.size() == 1) {
195  actionsList.add(DeleteFileContentTagAction.getInstance());
196  }
197 
198  actionsList.addAll(ContextMenuExtensionPoint.getActions());
199  return actionsList;
200  }
201 
202  @Override
203  protected List<? extends Action> defaultVisit(Content di) {
204  return Collections.<Action>emptyList();
205  }
206 
207 }
static synchronized ExportCSVAction getInstance()
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
List<?extends Action > visit(final org.sleuthkit.datamodel.File d)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static synchronized AddContentTagAction getInstance()

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