Autopsy  3.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 - 2013 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 
25 import org.openide.util.NbBundle;
36 
41 public class FileNode extends AbstractFsContentNode<AbstractFile> {
42 
46  public FileNode(AbstractFile file) {
47  this(file, true);
48 
49  setIcon(file);
50  }
51 
52  public FileNode(AbstractFile file, boolean directoryBrowseMode) {
53  super(file, directoryBrowseMode);
54 
55  setIcon(file);
56  }
57 
58  private void setIcon(AbstractFile file) {
59  // set name, display name, and icon
61  if (file.getType().equals(TSK_DB_FILES_TYPE_ENUM.CARVED)) {
62  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/carved-file-icon-16.png"); //NON-NLS
63  } else {
64  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-icon-deleted.png"); //NON-NLS
65  }
66  } else {
67  this.setIconBaseWithExtension(getIconForFileType(file));
68  }
69  }
70 
77  @Override
78  public Action[] getActions(boolean popup) {
79  List<Action> actionsList = new ArrayList<>();
80  if (!this.getDirectoryBrowseMode()) {
81  actionsList.add(new ViewContextAction(NbBundle.getMessage(this.getClass(), "FileNode.viewFileInDir.text"), this));
82  actionsList.add(null); // creates a menu separator
83  }
84  actionsList.add(new NewWindowViewAction(
85  NbBundle.getMessage(this.getClass(), "FileNode.getActions.viewInNewWin.text"), this));
86  actionsList.add(new ExternalViewerAction(
87  NbBundle.getMessage(this.getClass(), "FileNode.getActions.openInExtViewer.text"), this));
88  actionsList.add(null); // creates a menu separator
89  actionsList.add(ExtractAction.getInstance());
90  actionsList.add(new HashSearchAction(
91  NbBundle.getMessage(this.getClass(), "FileNode.getActions.searchFilesSameMD5.text"), this));
92  actionsList.add(null); // creates a menu separator
93  actionsList.add(AddContentTagAction.getInstance());
94  actionsList.addAll(ContextMenuExtensionPoint.getActions());
95  return actionsList.toArray(new Action[0]);
96  }
97 
98  @Override
99  public <T> T accept(ContentNodeVisitor< T> v) {
100  return v.visit(this);
101  }
102 
103  @Override
104  public <T> T accept(DisplayableItemNodeVisitor< T> v) {
105  return v.visit(this);
106  }
107 
108  // Given a file, returns the correct icon for said
109  // file based off it's extension
110  static String getIconForFileType(AbstractFile file) {
111  // Get the name, extension
112  String name = file.getName();
113  int dotIndex = name.lastIndexOf(".");
114  if (dotIndex == -1) {
115  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
116  }
117  String ext = name.substring(dotIndex).toLowerCase();
118 
119  // Images
120  for (String s : FileTypeExtensions.getImageExtensions()) {
121  if (ext.equals(s)) {
122  return "org/sleuthkit/autopsy/images/image-file.png"; //NON-NLS
123  }
124  }
125  // Videos
126  for (String s : FileTypeExtensions.getVideoExtensions()) {
127  if (ext.equals(s)) {
128  return "org/sleuthkit/autopsy/images/video-file.png"; //NON-NLS
129  }
130  }
131  // Audio Files
132  for (String s : FileTypeExtensions.getAudioExtensions()) {
133  if (ext.equals(s)) {
134  return "org/sleuthkit/autopsy/images/audio-file.png"; //NON-NLS
135  }
136  }
137  // Documents
138  for (String s : FileTypeExtensions.getDocumentExtensions()) {
139  if (ext.equals(s)) {
140  return "org/sleuthkit/autopsy/images/doc-file.png"; //NON-NLS
141  }
142  }
143  // Executables / System Files
144  for (String s : FileTypeExtensions.getExecutableExtensions()) {
145  if (ext.equals(s)) {
146  return "org/sleuthkit/autopsy/images/exe-file.png"; //NON-NLS
147  }
148  }
149  // Text Files
150  for (String s : FileTypeExtensions.getTextExtensions()) {
151  if (ext.equals(s)) {
152  return "org/sleuthkit/autopsy/images/text-file.png"; //NON-NLS
153  }
154  }
155  // Web Files
156  for (String s : FileTypeExtensions.getWebExtensions()) {
157  if (ext.equals(s)) {
158  return "org/sleuthkit/autopsy/images/web-file.png"; //NON-NLS
159  }
160  }
161  // PDFs
162  for (String s : FileTypeExtensions.getPDFExtensions()) {
163  if (ext.equals(s)) {
164  return "org/sleuthkit/autopsy/images/pdf-file.png"; //NON-NLS
165  }
166  }
167  // Archives
168  for (String s : FileTypeExtensions.getArchiveExtensions()) {
169  if (ext.equals(s)) {
170  return "org/sleuthkit/autopsy/images/archive-file.png"; //NON-NLS
171  }
172  }
173  // Else return the default
174  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
175 
176  }
177 
178  @Override
179  public boolean isLeafTypeNode() {
180  // This seems wrong, but it also seems that it is never called
181  // because the visitor to figure out if there are children or
182  // not will check if it has children using the Content API
183  return true;
184  }
185 }
boolean isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM flag)
Action[] getActions(boolean popup)
Definition: FileNode.java:78
TskData.TSK_DB_FILES_TYPE_ENUM getType()
static synchronized ExtractAction getInstance()
FileNode(AbstractFile file, boolean directoryBrowseMode)
Definition: FileNode.java:52
static synchronized AddContentTagAction getInstance()

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