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

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