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

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.