19 package org.sleuthkit.autopsy.datamodel;
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;
46 class ContentTagNode
extends DisplayableItemNode {
48 private static final Logger LOGGER = Logger.getLogger(ContentTagNode.class.getName());
50 private static final String ICON_PATH =
"org/sleuthkit/autopsy/images/blue-tag-icon-16.png";
51 private final ContentTag tag;
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);
62 "ContentTagNode.createSheet.artifactMD5.displayName=MD5 Hash",
63 "ContentTagNode.createSheet.artifactMD5.name=MD5 Hash"
66 protected Sheet createSheet() {
67 Content content = tag.getContent();
70 contentPath = content.getUniquePath();
71 }
catch (TskCoreException ex) {
72 LOGGER.log(Level.SEVERE,
"Failed to get path for content (id = " + content.getId() +
")", ex);
73 contentPath = NbBundle.getMessage(this.getClass(),
"ContentTagNode.createSheet.unavail.path");
75 AbstractFile file = content instanceof AbstractFile ? (AbstractFile) content : null;
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);
83 properties.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"ContentTagNode.createSheet.file.name"),
84 NbBundle.getMessage(
this.getClass(),
"ContentTagNode.createSheet.file.displayName"),
87 properties.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"ContentTagNode.createSheet.filePath.name"),
88 NbBundle.getMessage(
this.getClass(),
"ContentTagNode.createSheet.filePath.displayName"),
91 properties.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"ContentTagNode.createSheet.comment.name"),
92 NbBundle.getMessage(
this.getClass(),
"ContentTagNode.createSheet.comment.displayName"),
95 properties.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"ContentTagNode.createSheet.fileModifiedTime.name"),
96 NbBundle.getMessage(
this.getClass(),
"ContentTagNode.createSheet.fileModifiedTime.displayName"),
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"),
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"),
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"),
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"),
115 properties.put(
new NodeProperty<>(Bundle.ContentTagNode_createSheet_artifactMD5_name(),
116 Bundle.ContentTagNode_createSheet_artifactMD5_displayName(),
118 file != null ? StringUtils.defaultString(file.getMd5Hash()) :
""));
119 return propertySheet;
123 public Action[] getActions(
boolean context) {
124 List<Action> actions =
new ArrayList<>();
125 actions.addAll(Arrays.asList(super.getActions(context)));
127 AbstractFile file = getLookup().lookup(AbstractFile.class);
129 actions.add(ViewFileInTimelineAction.createViewFileAction(file));
131 actions.addAll(DataModelActionsFactory.getActions(tag.getContent(),
false));
132 actions.add(DeleteContentTagAction.getInstance());
133 return actions.toArray(
new Action[actions.size()]);
137 public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
138 return visitor.visit(
this);
142 public boolean isLeafTypeNode() {
147 public String getItemType() {
148 return getClass().getName();