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

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