Autopsy  4.1
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 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.Arrays;
22 import java.util.List;
23 import java.util.logging.Level;
24 import javax.swing.Action;
25 import org.openide.nodes.Children;
26 import org.openide.nodes.Sheet;
27 import org.openide.util.NbBundle;
28 import org.openide.util.lookup.Lookups;
32 import org.sleuthkit.datamodel.AbstractFile;
33 import org.sleuthkit.datamodel.Content;
34 import org.sleuthkit.datamodel.ContentTag;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
43 class ContentTagNode extends DisplayableItemNode {
44 
45  private static final String ICON_PATH = "org/sleuthkit/autopsy/images/blue-tag-icon-16.png"; //NON-NLS
46  private final ContentTag tag;
47 
48  public ContentTagNode(ContentTag tag) {
49  super(Children.LEAF, Lookups.fixed(tag, tag.getContent()));
50  super.setName(tag.getContent().getName());
51  super.setDisplayName(tag.getContent().getName());
52  this.setIconBaseWithExtension(ICON_PATH);
53  this.tag = tag;
54  }
55 
56  @Override
57  protected Sheet createSheet() {
58  Content content = tag.getContent();
59  String contentPath;
60  try {
61  contentPath = content.getUniquePath();
62  } catch (TskCoreException ex) {
63  Logger.getLogger(ContentTagNode.class.getName()).log(Level.SEVERE, "Failed to get path for content (id = " + content.getId() + ")", ex); //NON-NLS
64  contentPath = NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.unavail.path");
65  }
66  AbstractFile file = content instanceof AbstractFile ? (AbstractFile) content : null;
67 
68  Sheet propertySheet = super.createSheet();
69  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
70  if (properties == null) {
71  properties = Sheet.createPropertiesSet();
72  propertySheet.put(properties);
73  }
74  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.file.name"),
75  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.file.displayName"),
76  "",
77  content.getName()));
78  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.filePath.name"),
79  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.filePath.displayName"),
80  "",
81  contentPath));
82  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.comment.name"),
83  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.comment.displayName"),
84  "",
85  tag.getComment()));
86  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileModifiedTime.name"),
87  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileModifiedTime.displayName"),
88  "",
89  file != null ? ContentUtils.getStringTime(file.getMtime(), file) : ""));
90  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileChangedTime.name"),
91  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileChangedTime.displayName"),
92  "",
93  file != null ? ContentUtils.getStringTime(file.getCtime(), file) : ""));
94  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileAccessedTime.name"),
95  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileAccessedTime.displayName"),
96  "",
97  file != null ? ContentUtils.getStringTime(file.getAtime(), file) : ""));
98  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileCreatedTime.name"),
99  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileCreatedTime.displayName"),
100  "",
101  file != null ? ContentUtils.getStringTime(file.getCrtime(), file) : ""));
102  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileSize.name"),
103  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileSize.displayName"),
104  "",
105  content.getSize()));
106  return propertySheet;
107  }
108 
109  @Override
110  public Action[] getActions(boolean context) {
111  List<Action> actions = DataModelActionsFactory.getActions(tag.getContent(), false);
112  actions.addAll(Arrays.asList(super.getActions(context)));
113 
114  AbstractFile file = getLookup().lookup(AbstractFile.class);
115  if (file != null) {
116  actions.add(ViewFileInTimelineAction.createViewFileAction(file));
117  }
118  actions.add(null); // Adds a menu item separator.
119  actions.add(DeleteContentTagAction.getInstance());
120  return actions.toArray(new Action[actions.size()]);
121  }
122 
123  @Override
124  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
125  return v.visit(this);
126  }
127 
128  @Override
129  public boolean isLeafTypeNode() {
130  return true;
131  }
132 
133  /*
134  * TODO (AUT-1849): Correct or remove peristent column reordering code
135  *
136  * Added to support this feature.
137  */
138 // @Override
139 // public String getItemType() {
140 // return "ContentTag"; //NON-NLS
141 // }
142 }

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