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

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