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

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.