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

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