Autopsy  4.7.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.addAll(ContextMenuExtensionPoint.getActions());
129  return actionsList;
130  }
131 
132  @Override
133  public List<? extends Action> visit(final LocalDirectory d) {
134  List<Action> actionsList = new ArrayList<>();
135  if (!d.isDataSource()) {
136  actionsList.add(AddContentTagAction.getInstance());
137 
138  final Collection<AbstractFile> selectedFilesList =
139  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
140  if(selectedFilesList.size() == 1) {
141  actionsList.add(DeleteFileContentTagAction.getInstance());
142  }
143  }
144  actionsList.add(ExtractAction.getInstance());
145  actionsList.addAll(ContextMenuExtensionPoint.getActions());
146  return actionsList;
147  }
148 
149  @Override
150  public List<? extends Action> visit(final DerivedFile d) {
151  List<Action> actionsList = new ArrayList<>();
152  actionsList.add(ExtractAction.getInstance());
153  actionsList.add(AddContentTagAction.getInstance());
154 
155  final Collection<AbstractFile> selectedFilesList =
156  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
157  if(selectedFilesList.size() == 1) {
158  actionsList.add(DeleteFileContentTagAction.getInstance());
159  }
160 
161  actionsList.addAll(ContextMenuExtensionPoint.getActions());
162  return actionsList;
163  }
164 
165  @Override
166  public List<? extends Action> visit(final LocalFile d) {
167  List<Action> actionsList = new ArrayList<>();
168  actionsList.add(ExtractAction.getInstance());
169  actionsList.add(AddContentTagAction.getInstance());
170 
171  final Collection<AbstractFile> selectedFilesList =
172  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
173  if(selectedFilesList.size() == 1) {
174  actionsList.add(DeleteFileContentTagAction.getInstance());
175  }
176 
177  actionsList.addAll(ContextMenuExtensionPoint.getActions());
178  return actionsList;
179  }
180 
181  @Override
182  public List<? extends Action> visit(final org.sleuthkit.datamodel.File d) {
183  List<Action> actionsList = new ArrayList<>();
184  actionsList.add(ExtractAction.getInstance());
185  actionsList.add(AddContentTagAction.getInstance());
186 
187  final Collection<AbstractFile> selectedFilesList =
188  new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
189  if(selectedFilesList.size() == 1) {
190  actionsList.add(DeleteFileContentTagAction.getInstance());
191  }
192 
193  actionsList.addAll(ContextMenuExtensionPoint.getActions());
194  return actionsList;
195  }
196 
197  @Override
198  protected List<? extends Action> defaultVisit(Content di) {
199  return Collections.<Action>emptyList();
200  }
201 
202 }
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-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.