Autopsy  4.4
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-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.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 javax.swing.Action;
27 import org.apache.commons.lang3.StringUtils;
28 import org.openide.util.NbBundle;
29 import org.openide.util.Utilities;
40 import org.sleuthkit.datamodel.AbstractFile;
41 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
42 import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM;
43 
48 public class FileNode extends AbstractFsContentNode<AbstractFile> {
49 
58  static String getIconForFileType(AbstractFile file) {
59  String ext = file.getNameExtension();
60  if (StringUtils.isBlank(ext)) {
61  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
62  } else {
63  ext = "." + ext;
64  }
66  || FileTypeExtensions.getImageExtensions().contains(ext)) {
67  return "org/sleuthkit/autopsy/images/image-file.png"; //NON-NLS
68  }
69  if (FileTypeExtensions.getVideoExtensions().contains(ext)) {
70  return "org/sleuthkit/autopsy/images/video-file.png"; //NON-NLS
71  }
72  if (FileTypeExtensions.getAudioExtensions().contains(ext)) {
73  return "org/sleuthkit/autopsy/images/audio-file.png"; //NON-NLS
74  }
75  if (FileTypeExtensions.getDocumentExtensions().contains(ext)) {
76  return "org/sleuthkit/autopsy/images/doc-file.png"; //NON-NLS
77  }
78  if (FileTypeExtensions.getExecutableExtensions().contains(ext)) {
79  return "org/sleuthkit/autopsy/images/exe-file.png"; //NON-NLS
80  }
81  if (FileTypeExtensions.getTextExtensions().contains(ext)) {
82  return "org/sleuthkit/autopsy/images/text-file.png"; //NON-NLS
83  }
84  if (FileTypeExtensions.getWebExtensions().contains(ext)) {
85  return "org/sleuthkit/autopsy/images/web-file.png"; //NON-NLS
86  }
87  if (FileTypeExtensions.getPDFExtensions().contains(ext)) {
88  return "org/sleuthkit/autopsy/images/pdf-file.png"; //NON-NLS
89  }
90  if (FileTypeExtensions.getArchiveExtensions().contains(ext)) {
91  return "org/sleuthkit/autopsy/images/archive-file.png"; //NON-NLS
92  }
93  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
94  }
95 
102  public FileNode(AbstractFile file) {
103  this(file, true);
104  setIcon(file);
105  }
106 
114  public FileNode(AbstractFile file, boolean directoryBrowseMode) {
115  super(file, directoryBrowseMode);
116  setIcon(file);
117  }
118 
119  /*
120  * Sets the icon for the node, based on properties of the AbstractFile.
121  */
122  private void setIcon(AbstractFile file) {
123  if (file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC)) {
124  if (file.getType().equals(TSK_DB_FILES_TYPE_ENUM.CARVED)) {
125  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/carved-file-icon-16.png"); //NON-NLS
126  } else {
127  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-icon-deleted.png"); //NON-NLS
128  }
129  } else {
130  this.setIconBaseWithExtension(getIconForFileType(file));
131  }
132  }
133 
143  @Override
144  @NbBundle.Messages({
145  "FileNode.getActions.viewFileInDir.text=View File in Directory",
146  "FileNode.getActions.viewInNewWin.text=View in New Window",
147  "FileNode.getActions.openInExtViewer.text=Open in External Viewer",
148  "FileNode.getActions.searchFilesSameMD5.text=Search for files with the same MD5 hash"})
149  public Action[] getActions(boolean context) {
150  List<Action> actionsList = new ArrayList<>();
151  actionsList.addAll(Arrays.asList(super.getActions(true)));
152  if (!this.getDirectoryBrowseMode()) {
153  actionsList.add(new ViewContextAction(Bundle.FileNode_getActions_viewFileInDir_text(), this));
154  actionsList.add(null); // Creates an item separator
155  }
156 
157  actionsList.add(new NewWindowViewAction(Bundle.FileNode_getActions_viewInNewWin_text(), this));
158  actionsList.add(new ExternalViewerAction(Bundle.FileNode_getActions_openInExtViewer_text(), this));
159  actionsList.add(ViewFileInTimelineAction.createViewFileAction(getContent()));
160  actionsList.add(null); // Creates an item separator
161 
162  actionsList.add(ExtractAction.getInstance());
163  actionsList.add(new HashSearchAction(Bundle.FileNode_getActions_searchFilesSameMD5_text(), this));
164  actionsList.add(null); // Creates an item separator
165 
166  actionsList.add(AddContentTagAction.getInstance());
167  final Collection<AbstractFile> selectedFilesList = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
168  if (1 == selectedFilesList.size()) {
169  actionsList.add(DeleteFileContentTagAction.getInstance());
170  }
171  actionsList.addAll(ContextMenuExtensionPoint.getActions());
172  return actionsList.toArray(new Action[actionsList.size()]);
173  }
174 
183  @Override
184  public <T> T accept(ContentNodeVisitor<T> visitor) {
185  return visitor.visit(this);
186  }
187 
196  @Override
197  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
198  return visitor.visit(this);
199  }
200 
207  @Override
208  public boolean isLeafTypeNode() {
209  /*
210  * A FileNode may have FileNodes for derived files as children.
211  */
212  return false;
213  }
214 
220  @Override
221  public String getItemType() {
222  return getClass().getName();
223  }
224 }
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
FileNode(AbstractFile file, boolean directoryBrowseMode)
Definition: FileNode.java:114
static boolean isImageThumbnailSupported(AbstractFile file)
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
Action[] getActions(boolean context)
Definition: FileNode.java:149
static synchronized AddContentTagAction getInstance()

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