Autopsy  4.8.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
LocalFileNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.logging.Level;
29 import javax.swing.Action;
30 import org.openide.nodes.Sheet;
31 import org.openide.util.NbBundle;
32 import org.openide.util.Utilities;
45 import org.sleuthkit.datamodel.AbstractFile;
46 import org.sleuthkit.datamodel.BlackboardArtifact;
47 import org.sleuthkit.datamodel.ContentTag;
48 import org.sleuthkit.datamodel.TskCoreException;
49 
53 public class LocalFileNode extends AbstractAbstractFileNode<AbstractFile> {
54 
55  private static final Logger logger = Logger.getLogger(LocalFileNode.class.getName());
56 
57  public LocalFileNode(AbstractFile af) {
58  super(af);
59 
60  this.setDisplayName(af.getName());
61 
62  // set name, display name, and icon
63  if (af.isDir()) {
64  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/Folder-icon.png"); //NON-NLS
65  } else {
66  this.setIconBaseWithExtension(FileNode.getIconForFileType(af));
67  }
68 
69  }
70 
71  @Override
72  protected Sheet createSheet() {
73  Sheet sheet = super.createSheet();
74  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
75  if (sheetSet == null) {
76  sheetSet = Sheet.createPropertiesSet();
77  sheet.put(sheetSet);
78  }
79  List<ContentTag> tags = getContentTagsFromDatabase();
80  Map<String, Object> map = new LinkedHashMap<>();
81  fillPropertyMap(map, getContent());
82 
83  sheetSet.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "LocalFileNode.createSheet.name.name"),
84  NbBundle.getMessage(this.getClass(), "LocalFileNode.createSheet.name.displayName"),
85  NbBundle.getMessage(this.getClass(), "LocalFileNode.createSheet.name.desc"),
86  getName()));
87 
88  addScoreProperty(sheetSet, tags);
89 
90  CorrelationAttributeInstance correlationAttribute = null;
92  correlationAttribute = getCorrelationAttributeInstance();
93  }
94  addCommentProperty(sheetSet, tags, correlationAttribute);
95 
97  addCountProperty(sheetSet, correlationAttribute);
98  }
99  final String NO_DESCR = NbBundle.getMessage(this.getClass(), "LocalFileNode.createSheet.noDescr.text");
100  for (Map.Entry<String, Object> entry : map.entrySet()) {
101  sheetSet.put(new NodeProperty<>(entry.getKey(), entry.getKey(), NO_DESCR, entry.getValue()));
102  }
103 
104  return sheet;
105  }
106 
107  @Override
108  public Action[] getActions(boolean context) {
109  List<Action> actionsList = new ArrayList<>();
110  actionsList.addAll(Arrays.asList(super.getActions(true)));
111 
112  actionsList.add(new ViewContextAction(NbBundle.getMessage(this.getClass(), "LocalFileNode.viewFileInDir.text"), this.content));
113  actionsList.add(null); // creates a menu separator
114  actionsList.add(new NewWindowViewAction(
115  NbBundle.getMessage(this.getClass(), "LocalFileNode.getActions.viewInNewWin.text"), this));
116  actionsList.add(new ExternalViewerAction(
117  NbBundle.getMessage(this.getClass(), "LocalFileNode.getActions.openInExtViewer.text"), this));
118  actionsList.add(null); // creates a menu separator
119 
120  actionsList.add(ExtractAction.getInstance());
121  actionsList.add(null); // creates a menu separator
122  actionsList.add(AddContentTagAction.getInstance());
123 
124  final Collection<AbstractFile> selectedFilesList
125  = new HashSet<>(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class));
126  if (selectedFilesList.size() == 1) {
127  actionsList.add(DeleteFileContentTagAction.getInstance());
128  }
129 
130  actionsList.addAll(ContextMenuExtensionPoint.getActions());
131  if (FileTypeExtensions.getArchiveExtensions().contains("." + this.content.getNameExtension().toLowerCase())) {
132  try {
133  if (this.content.getArtifacts(BlackboardArtifact.ARTIFACT_TYPE.TSK_ENCRYPTION_DETECTED).size() > 0) {
134  actionsList.add(new ExtractArchiveWithPasswordAction(this.getContent()));
135  }
136  } catch (TskCoreException ex) {
137  logger.log(Level.WARNING, "Unable to add unzip with password action to context menus", ex);
138  }
139  }
140  return actionsList.toArray(new Action[actionsList.size()]);
141  }
142 
143  @Override
144  public <T> T accept(ContentNodeVisitor<T> visitor) {
145  return visitor.visit(this);
146  }
147 
148  @Override
149  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
150  return visitor.visit(this);
151  }
152 
153  @Override
154  public boolean isLeafTypeNode() {
155  // This seems wrong, but it also seems that it is never called
156  // because the visitor to figure out if there are children or
157  // not will check if it has children using the Content API
158  return true;
159  }
160 
161  @Override
162  public String getItemType() {
163  return getClass().getName();
164  }
165 }
final void addScoreProperty(Sheet.Set sheetSet, List< ContentTag > tags)
static void fillPropertyMap(Map< String, Object > map, AbstractFile content)
static synchronized ExtractAction getInstance()
static synchronized DeleteFileContentTagAction getInstance()
final void addCountProperty(Sheet.Set sheetSet, CorrelationAttributeInstance attribute)
final void addCommentProperty(Sheet.Set sheetSet, List< ContentTag > tags, CorrelationAttributeInstance attribute)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static synchronized AddContentTagAction getInstance()

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