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

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