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-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.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;
36 
43 class ContentTagNode extends DisplayableItemNode {
44 
45  private static final Logger LOGGER = Logger.getLogger(ContentTagNode.class.getName());
46 
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  public ContentTagNode(ContentTag tag) {
51  super(Children.LEAF, Lookups.fixed(tag, 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  @Override
59  protected Sheet createSheet() {
60  Content content = tag.getContent();
61  String contentPath;
62  try {
63  contentPath = content.getUniquePath();
64  } catch (TskCoreException ex) {
65  LOGGER.log(Level.SEVERE, "Failed to get path for content (id = " + content.getId() + ")", ex); //NON-NLS
66  contentPath = NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.unavail.path");
67  }
68  AbstractFile file = content instanceof AbstractFile ? (AbstractFile) content : null;
69 
70  Sheet propertySheet = super.createSheet();
71  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
72  if (properties == null) {
73  properties = Sheet.createPropertiesSet();
74  propertySheet.put(properties);
75  }
76  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.file.name"),
77  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.file.displayName"),
78  "",
79  content.getName()));
80  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.filePath.name"),
81  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.filePath.displayName"),
82  "",
83  contentPath));
84  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.comment.name"),
85  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.comment.displayName"),
86  "",
87  tag.getComment()));
88  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileModifiedTime.name"),
89  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileModifiedTime.displayName"),
90  "",
91  file != null ? ContentUtils.getStringTime(file.getMtime(), file) : ""));
92  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileChangedTime.name"),
93  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileChangedTime.displayName"),
94  "",
95  file != null ? ContentUtils.getStringTime(file.getCtime(), file) : ""));
96  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileAccessedTime.name"),
97  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileAccessedTime.displayName"),
98  "",
99  file != null ? ContentUtils.getStringTime(file.getAtime(), file) : ""));
100  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileCreatedTime.name"),
101  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileCreatedTime.displayName"),
102  "",
103  file != null ? ContentUtils.getStringTime(file.getCrtime(), file) : ""));
104  properties.put(new NodeProperty<>(NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileSize.name"),
105  NbBundle.getMessage(this.getClass(), "ContentTagNode.createSheet.fileSize.displayName"),
106  "",
107  content.getSize()));
108 
109  return propertySheet;
110  }
111 
112  @Override
113  public Action[] getActions(boolean context) {
114  List<Action> actions = DataModelActionsFactory.getActions(tag.getContent(), false);
115  actions.addAll(Arrays.asList(super.getActions(context)));
116 
117  AbstractFile file = getLookup().lookup(AbstractFile.class);
118  if (file != null) {
119  actions.add(ViewFileInTimelineAction.createViewFileAction(file));
120  }
121  actions.add(null); // Adds a menu item separator.
122  actions.add(DeleteContentTagAction.getInstance());
123  return actions.toArray(new Action[actions.size()]);
124  }
125 
126  @Override
127  public <T> T accept(DisplayableItemNodeVisitor<T> v) {
128  return v.visit(this);
129  }
130 
131  @Override
132  public boolean isLeafTypeNode() {
133  return true;
134  }
135 
136  @Override
137  public String getItemType() {
138  return getClass().getName();
139  }
140 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.