Autopsy  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-2016 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.List;
23 import javax.swing.Action;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openide.util.NbBundle;
35 import org.sleuthkit.datamodel.AbstractFile;
36 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
37 import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM;
38 
43 public class FileNode extends AbstractFsContentNode<AbstractFile> {
44 
50  public FileNode(AbstractFile file) {
51  this(file, true);
52 
53  setIcon(file);
54  }
55 
56  public FileNode(AbstractFile file, boolean directoryBrowseMode) {
57  super(file, directoryBrowseMode);
58 
59  setIcon(file);
60  }
61 
62  private void setIcon(AbstractFile file) {
63  // set name, display name, and icon
64  if (file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC)) {
65  if (file.getType().equals(TSK_DB_FILES_TYPE_ENUM.CARVED)) {
66  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/carved-file-icon-16.png"); //NON-NLS
67  } else {
68  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-icon-deleted.png"); //NON-NLS
69  }
70  } else {
71  this.setIconBaseWithExtension(getIconForFileType(file));
72  }
73  }
74 
75  @Override
76  @NbBundle.Messages({
77  "FileNode.getActions.viewFileInDir.text=View File in Directory",
78  "FileNode.getActions.viewInNewWin.text=View in New Window",
79  "FileNode.getActions.openInExtViewer.text=Open in External Viewer",
80  "FileNode.getActions.searchFilesSameMD5.text=Search for files with the same MD5 hash"})
81  public Action[] getActions(boolean popup) {
82  List<Action> actionsList = new ArrayList<>();
83  for (Action a : super.getActions(true)) {
84  actionsList.add(a);
85  }
86  if (!this.getDirectoryBrowseMode()) {
87  actionsList.add(new ViewContextAction(Bundle.FileNode_getActions_viewFileInDir_text(), this));
88  actionsList.add(null); // creates a menu separator
89  }
90  actionsList.add(new NewWindowViewAction(Bundle.FileNode_getActions_viewInNewWin_text(), this));
91  actionsList.add(new ExternalViewerAction(Bundle.FileNode_getActions_openInExtViewer_text(), this));
92  actionsList.add(ViewFileInTimelineAction.createViewFileAction(getContent()));
93 
94  actionsList.add(null); // creates a menu separator
95  actionsList.add(ExtractAction.getInstance());
96  actionsList.add(new HashSearchAction(Bundle.FileNode_getActions_searchFilesSameMD5_text(), this));
97  actionsList.add(null); // creates a menu separator
98  actionsList.add(AddContentTagAction.getInstance());
99  actionsList.addAll(ContextMenuExtensionPoint.getActions());
100  return actionsList.toArray(new Action[actionsList.size()]);
101  }
102 
103  @Override
104  public <T> T accept(ContentNodeVisitor<T> v) {
105  return v.visit(this);
106  }
107 
108  @Override
109  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
110  return v.visit(this);
111  }
112 
113  // Given a file, returns the correct icon for said
114  // file based off it's extension
115  static String getIconForFileType(AbstractFile file) {
116  // Get the name, extension
117  String ext = file.getNameExtension();
118 
119  if (StringUtils.isBlank(ext)) {
120  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
121  } else {
122  ext = "." + ext;
123  }
124 
125  if (ImageUtils.isImageThumbnailSupported(file)
126  || FileTypeExtensions.getImageExtensions().contains(ext)) {
127  return "org/sleuthkit/autopsy/images/image-file.png"; //NON-NLS
128  }
129  // Videos
130  if (FileTypeExtensions.getVideoExtensions().contains(ext)) {
131  return "org/sleuthkit/autopsy/images/video-file.png"; //NON-NLS
132  }
133  // Audio Files
134  if (FileTypeExtensions.getAudioExtensions().contains(ext)) {
135  return "org/sleuthkit/autopsy/images/audio-file.png"; //NON-NLS
136  }
137  // Documents
138  if (FileTypeExtensions.getDocumentExtensions().contains(ext)) {
139  return "org/sleuthkit/autopsy/images/doc-file.png"; //NON-NLS
140  }
141  // Executables / System Files
142  if (FileTypeExtensions.getExecutableExtensions().contains(ext)) {
143  return "org/sleuthkit/autopsy/images/exe-file.png"; //NON-NLS
144  }
145  // Text Files
146  if (FileTypeExtensions.getTextExtensions().contains(ext)) {
147  return "org/sleuthkit/autopsy/images/text-file.png"; //NON-NLS
148  }
149  // Web Files
150  if (FileTypeExtensions.getWebExtensions().contains(ext)) {
151  return "org/sleuthkit/autopsy/images/web-file.png"; //NON-NLS
152  }
153  // PDFs
154  if (FileTypeExtensions.getPDFExtensions().contains(ext)) {
155  return "org/sleuthkit/autopsy/images/pdf-file.png"; //NON-NLS
156  }
157  // Archives
158  if (FileTypeExtensions.getArchiveExtensions().contains(ext)) {
159  return "org/sleuthkit/autopsy/images/archive-file.png"; //NON-NLS
160  }
161  // Else return the default
162  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
163  }
164 
165  @Override
166  public boolean isLeafTypeNode() {
167  // This seems wrong, but it also seems that it is never called
168  // because the visitor to figure out if there are children or
169  // not will check if it has children using the Content API
170  return true;
171  }
172 
173  /*
174  * TODO (AUT-1849): Correct or remove peristent column reordering code
175  *
176  * Added to support this feature.
177  */
178 // @Override
179 // public String getItemType() {
180 // return "File"; //NON-NLS
181 // }
182 }
Action[] getActions(boolean popup)
Definition: FileNode.java:81
static synchronized ExtractAction getInstance()
void setIcon(AbstractFile file)
Definition: FileNode.java:62
FileNode(AbstractFile file, boolean directoryBrowseMode)
Definition: FileNode.java:56
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
static synchronized AddContentTagAction getInstance()

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