Autopsy  4.10.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ContentTagNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.Arrays;
23 import java.util.List;
24 import java.util.logging.Level;
25 import javax.swing.Action;
26 import org.apache.commons.lang3.StringUtils;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Sheet;
29 import org.openide.util.NbBundle;
30 import org.openide.util.NbBundle.Messages;
31 import org.openide.util.lookup.Lookups;
34 import org.sleuthkit.datamodel.AbstractFile;
35 import org.sleuthkit.datamodel.Content;
36 import org.sleuthkit.datamodel.ContentTag;
37 import org.sleuthkit.datamodel.TskCoreException;
38 
45 class ContentTagNode extends DisplayableItemNode {
46 
47  private static final Logger LOGGER = Logger.getLogger(ContentTagNode.class.getName());
48 
49  private static final String ICON_PATH = "org/sleuthkit/autopsy/images/blue-tag-icon-16.png"; //NON-NLS
50  private final ContentTag tag;
51 
52  public ContentTagNode(ContentTag tag) {
53  super(Children.LEAF, Lookups.fixed(tag, tag.getContent()));
54  super.setName(tag.getContent().getName());
55  super.setDisplayName(tag.getContent().getName());
56  this.setIconBaseWithExtension(ICON_PATH);
57  this.tag = tag;
58  }
59 
60  @Messages({
61  "ContentTagNode.createSheet.artifactMD5.displayName=MD5 Hash",
62  "ContentTagNode.createSheet.artifactMD5.name=MD5 Hash",
63  "ContentTagNode.createSheet.userName.text=User Name"})
64  @Override
65  protected Sheet createSheet() {
66  Content content = tag.getContent();
67  String contentPath;
68  try {
69  contentPath = content.getUniquePath();
70  } catch (TskCoreException ex) {
71  LOGGER.log(Level.SEVERE, "Failed to get path for content (id = " + content.getId() + ")", ex); //NON-NLS
72  contentPath = NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.unavail.path");
73  }
74  AbstractFile file = content instanceof AbstractFile ? (AbstractFile) content : null;
75 
76  Sheet propertySheet = super.createSheet();
77  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
78  if (properties == null) {
79  properties = Sheet.createPropertiesSet();
80  propertySheet.put(properties);
81  }
82  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.file.name"),
83  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.file.displayName"),
84  "",
85  content.getName()));
86  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.filePath.name"),
87  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.filePath.displayName"),
88  "",
89  contentPath));
90  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.comment.name"),
91  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.comment.displayName"),
92  "",
93  tag.getComment()));
94  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileModifiedTime.name"),
95  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileModifiedTime.displayName"),
96  "",
97  file != null ? ContentUtils.getStringTime(file.getMtime(), file) : ""));
98  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileChangedTime.name"),
99  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileChangedTime.displayName"),
100  "",
101  file != null ? ContentUtils.getStringTime(file.getCtime(), file) : ""));
102  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileAccessedTime.name"),
103  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileAccessedTime.displayName"),
104  "",
105  file != null ? ContentUtils.getStringTime(file.getAtime(), file) : ""));
106  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileCreatedTime.name"),
107  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileCreatedTime.displayName"),
108  "",
109  file != null ? ContentUtils.getStringTime(file.getCrtime(), file) : ""));
110  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileSize.name"),
111  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileSize.displayName"),
112  "",
113  content.getSize()));
114  properties.put(new NodeProperty<>(Bundle.ContentTagNode_createSheet_artifactMD5_name(),
115  Bundle.ContentTagNode_createSheet_artifactMD5_displayName(),
116  "",
117  file != null ? StringUtils.defaultString(file.getMd5Hash()) : ""));
118  properties.put(new NodeProperty<>(
119  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.userName.text"),
120  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.userName.text"),
121  "",
122  tag.getUserName()));
123  return propertySheet;
124  }
125 
126  @Override
127  public Action[] getActions(boolean context) {
128  List<Action> actions = new ArrayList<>();
129  actions.addAll(Arrays.asList(super.getActions(context)));
130 
131  AbstractFile file = getLookup().lookup(AbstractFile.class
132  );
133  if (file != null) {
134  actions.add(ViewFileInTimelineAction.createViewFileAction(file));
135  }
136 
137  actions.addAll(DataModelActionsFactory.getActions(tag, false));
138 
139  return actions.toArray(new Action[actions.size()]);
140  }
141 
142  @Override
143  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
144  return visitor.visit(this);
145  }
146 
147  @Override
148  public boolean isLeafTypeNode() {
149  return true;
150  }
151 
152  @Override
153  public String getItemType() {
154  return getClass().getName();
155  }
156 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.