Autopsy  4.6.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-2018 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 java.util.logging.Level;
27 import javax.swing.Action;
28 import org.apache.commons.lang3.StringUtils;
29 import org.openide.util.NbBundle;
30 import org.openide.util.Utilities;
42 import org.sleuthkit.datamodel.AbstractFile;
43 import org.sleuthkit.datamodel.BlackboardArtifact;
44 import org.sleuthkit.datamodel.TskCoreException;
45 import org.sleuthkit.datamodel.TskData.TSK_DB_FILES_TYPE_ENUM;
46 import org.sleuthkit.datamodel.TskData.TSK_FS_NAME_FLAG_ENUM;
47 
52 public class FileNode extends AbstractFsContentNode<AbstractFile> {
53 
54  private static final Logger logger = Logger.getLogger(FileNode.class.getName());
55 
64  static String getIconForFileType(AbstractFile file) {
65  String ext = file.getNameExtension();
66  if (StringUtils.isBlank(ext)) {
67  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
68  } else {
69  ext = "." + ext;
70  }
71  if (FileTypeExtensions.getImageExtensions().contains(ext)) {
72  return "org/sleuthkit/autopsy/images/image-file.png"; //NON-NLS
73  }
74  if (FileTypeExtensions.getVideoExtensions().contains(ext)) {
75  return "org/sleuthkit/autopsy/images/video-file.png"; //NON-NLS
76  }
77  if (FileTypeExtensions.getAudioExtensions().contains(ext)) {
78  return "org/sleuthkit/autopsy/images/audio-file.png"; //NON-NLS
79  }
80  if (FileTypeExtensions.getDocumentExtensions().contains(ext)) {
81  return "org/sleuthkit/autopsy/images/doc-file.png"; //NON-NLS
82  }
83  if (FileTypeExtensions.getExecutableExtensions().contains(ext)) {
84  return "org/sleuthkit/autopsy/images/exe-file.png"; //NON-NLS
85  }
86  if (FileTypeExtensions.getTextExtensions().contains(ext)) {
87  return "org/sleuthkit/autopsy/images/text-file.png"; //NON-NLS
88  }
89  if (FileTypeExtensions.getWebExtensions().contains(ext)) {
90  return "org/sleuthkit/autopsy/images/web-file.png"; //NON-NLS
91  }
92  if (FileTypeExtensions.getPDFExtensions().contains(ext)) {
93  return "org/sleuthkit/autopsy/images/pdf-file.png"; //NON-NLS
94  }
95  if (FileTypeExtensions.getArchiveExtensions().contains(ext)) {
96  return "org/sleuthkit/autopsy/images/archive-file.png"; //NON-NLS
97  }
98  return "org/sleuthkit/autopsy/images/file-icon.png"; //NON-NLS
99  }
100 
107  public FileNode(AbstractFile file) {
108  this(file, true);
109  setIcon(file);
110  }
111 
119  public FileNode(AbstractFile file, boolean directoryBrowseMode) {
120  super(file, directoryBrowseMode);
121  setIcon(file);
122  }
123 
124  /*
125  * Sets the icon for the node, based on properties of the AbstractFile.
126  */
127  private void setIcon(AbstractFile file) {
128  if (file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC)) {
129  if (file.getType().equals(TSK_DB_FILES_TYPE_ENUM.CARVED)) {
130  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/carved-file-icon-16.png"); //NON-NLS
131  } else {
132  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/file-icon-deleted.png"); //NON-NLS
133  }
134  } else {
135  this.setIconBaseWithExtension(getIconForFileType(file));
136  }
137  }
138 
148  @Override
149  @NbBundle.Messages({
150  "FileNode.getActions.viewFileInDir.text=View File in Directory",
151  "FileNode.getActions.viewInNewWin.text=View in New Window",
152  "FileNode.getActions.openInExtViewer.text=Open in External Viewer",
153  "FileNode.getActions.searchFilesSameMD5.text=Search for files with the same MD5 hash"})
154  public Action[] getActions(boolean context) {
155  List<Action> actionsList = new ArrayList<>();
156  actionsList.addAll(Arrays.asList(super.getActions(true)));
157 
158  if (!this.getDirectoryBrowseMode()) {
159  actionsList.add(new ViewContextAction(Bundle.FileNode_getActions_viewFileInDir_text(), this));
160  actionsList.add(null); // Creates an item separator
161  }
162 
163  actionsList.add(new NewWindowViewAction(Bundle.FileNode_getActions_viewInNewWin_text(), this));
164  actionsList.add(new ExternalViewerAction(Bundle.FileNode_getActions_openInExtViewer_text(), this));
165  actionsList.add(ViewFileInTimelineAction.createViewFileAction(getContent()));
166  actionsList.add(null); // Creates an item separator
167 
168  actionsList.add(ExtractAction.getInstance());
169  actionsList.add(new HashSearchAction(Bundle.FileNode_getActions_searchFilesSameMD5_text(), this));
170  actionsList.add(null); // Creates an item separator
171 
172  actionsList.add(AddContentTagAction.getInstance());
173  final Collection<AbstractFile> selectedFilesList = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
174  if (1 == selectedFilesList.size()) {
175  actionsList.add(DeleteFileContentTagAction.getInstance());
176  }
177  actionsList.addAll(ContextMenuExtensionPoint.getActions());
178  if (FileTypeExtensions.getArchiveExtensions().contains("." + this.content.getNameExtension().toLowerCase())) {
179  try {
180  if (this.content.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
181  actionsList.add(new ExtractArchiveWithPasswordAction(this.getContent()));
182  }
183  } catch (TskCoreException ex) {
184  logger.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);
185  }
186  }
187  return actionsList.toArray(new Action[actionsList.size()]);
188  }
189 
198  @Override
199  public <T> T accept(ContentNodeVisitor<T> visitor) {
200  return visitor.visit(this);
201  }
202 
211  @Override
212  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
213  return visitor.visit(this);
214  }
215 
222  @Override
223  public boolean isLeafTypeNode() {
224  /*
225  * A FileNode may have FileNodes for derived files as children.
226  */
227  return false;
228  }
229 
235  @Override
236  public String getItemType() {
237  return getClass().getName();
238  }
239 }
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
FileNode(AbstractFile file, boolean directoryBrowseMode)
Definition: FileNode.java:119
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)
Action[] getActions(boolean context)
Definition: FileNode.java:154
static synchronized AddContentTagAction getInstance()

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.