Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 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.datamodel;
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 java.util.logging.Level;
27 import javax.swing.Action;
28 import org.apache.commons.lang3.StringUtils;
29 import org.openide.util.NbBundle;
30 import org.openide.util.Utilities;
42 import org.sleuthkit.datamodel.AbstractFile;
43 import org.sleuthkit.datamodel.BlackboardArtifact;
44 import org.sleuthkit.datamodel.TskCoreException;
45 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
46 import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM;
47 
52 public class FileNode extends AbstractFsContentNode<AbstractFile> {
53 
54  private static final Logger logger = Logger.getLogger(FileNode.class.getName());
55 
64  static String getIconForFileType(AbstractFile file) {
65  String ext = file.getNameExtension();
66  if (StringUtils.isBlank(ext)) {
67  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
68  } else {
69  ext = "." + ext;
70  }
71  if (FileTypeExtensions.getImageExtensions().contains(ext)) {
72  return "org/sleuthkit/autopsy/images/image-file.png"; //NON-NLS
73  }
74  if (FileTypeExtensions.getVideoExtensions().contains(ext)) {
75  return "org/sleuthkit/autopsy/images/video-file.png"; //NON-NLS
76  }
77  if (FileTypeExtensions.getAudioExtensions().contains(ext)) {
78  return "org/sleuthkit/autopsy/images/audio-file.png"; //NON-NLS
79  }
80  if (FileTypeExtensions.getDocumentExtensions().contains(ext)) {
81  return "org/sleuthkit/autopsy/images/doc-file.png"; //NON-NLS
82  }
83  if (FileTypeExtensions.getExecutableExtensions().contains(ext)) {
84  return "org/sleuthkit/autopsy/images/exe-file.png"; //NON-NLS
85  }
86  if (FileTypeExtensions.getTextExtensions().contains(ext)) {
87  return "org/sleuthkit/autopsy/images/text-file.png"; //NON-NLS
88  }
89  if (FileTypeExtensions.getWebExtensions().contains(ext)) {
90  return "org/sleuthkit/autopsy/images/web-file.png"; //NON-NLS
91  }
92  if (FileTypeExtensions.getPDFExtensions().contains(ext)) {
93  return "org/sleuthkit/autopsy/images/pdf-file.png"; //NON-NLS
94  }
95  if (FileTypeExtensions.getArchiveExtensions().contains(ext)) {
96  return "org/sleuthkit/autopsy/images/archive-file.png"; //NON-NLS
97  }
98  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
99  }
100 
107  public FileNode(AbstractFile file) {
108  this(file, true);
109  setIcon(file);
110  }
111 
119  public FileNode(AbstractFile file, boolean directoryBrowseMode) {
120  super(file, directoryBrowseMode);
121  setIcon(file);
122  }
123 
124  /*
125  * Sets the icon for the node, based on properties of the AbstractFile.
126  */
127  private void setIcon(AbstractFile file) {
128  if (file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC)) {
129  if (file.getType().equals(TSK_DB_FILES_TYPE_ENUM.CARVED)) {
130  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/carved-file-icon-16.png"); //NON-NLS
131  } else {
132  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-icon-deleted.png"); //NON-NLS
133  }
134  } else {
135  this.setIconBaseWithExtension(getIconForFileType(file));
136  }
137  }
138 
148  @Override
149  @NbBundle.Messages({
150  "FileNode.getActions.viewFileInDir.text=View File in Directory",
151  "FileNode.getActions.viewInNewWin.text=View in New Window",
152  "FileNode.getActions.openInExtViewer.text=Open in External Viewer Ctrl+E",
153  "FileNode.getActions.searchFilesSameMD5.text=Search for files with the same MD5 hash"})
154  public Action[] getActions(boolean context) {
155  List<Action> actionsList = new ArrayList<>();
156  actionsList.addAll(Arrays.asList(super.getActions(true)));
157 
158  if (!this.getDirectoryBrowseMode()) {
159  actionsList.add(new ViewContextAction(Bundle.FileNode_getActions_viewFileInDir_text(), this));
160  actionsList.add(null); // Creates an item separator
161  }
162 
163  actionsList.add(new NewWindowViewAction(Bundle.FileNode_getActions_viewInNewWin_text(), this));
164  final Collection<AbstractFile> selectedFilesList
165  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
166  if (selectedFilesList.size() == 1) {
167  actionsList.add(new ExternalViewerAction(
168  Bundle.FileNode_getActions_openInExtViewer_text(), this));
169  } else {
170  actionsList.add(ExternalViewerShortcutAction.getInstance());
171  }
172  actionsList.add(ViewFileInTimelineAction.createViewFileAction(getContent()));
173  actionsList.add(null); // Creates an item separator
174 
175  actionsList.add(ExtractAction.getInstance());
176  actionsList.add(null); // Creates an item separator
177 
178  actionsList.add(AddContentTagAction.getInstance());
179  if (1 == selectedFilesList.size()) {
180  actionsList.add(DeleteFileContentTagAction.getInstance());
181  }
182  actionsList.addAll(ContextMenuExtensionPoint.getActions());
183  if (FileTypeExtensions.getArchiveExtensions().contains("." + this.content.getNameExtension().toLowerCase())) {
184  try {
185  if (this.content.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
186  actionsList.add(new ExtractArchiveWithPasswordAction(this.getContent()));
187  }
188  } catch (TskCoreException ex) {
189  logger.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);
190  }
191  }
192  return actionsList.toArray(new Action[actionsList.size()]);
193  }
194 
203  @Override
204  public <T> T accept(ContentNodeVisitor<T> visitor) {
205  return visitor.visit(this);
206  }
207 
216  @Override
217  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
218  return visitor.visit(this);
219  }
220 
227  @Override
228  public boolean isLeafTypeNode() {
229  /*
230  * A FileNode may have FileNodes for derived files as children.
231  */
232  return false;
233  }
234 
240  @Override
241  public String getItemType() {
242  return getClass().getName();
243  }
244 }
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
FileNode(AbstractFile file, boolean directoryBrowseMode)
Definition: FileNode.java:119
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
Action[] getActions(boolean context)
Definition: FileNode.java:154
static synchronized AddContentTagAction getInstance()

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