Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
BlackboardArtifactTagNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2021 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.text.MessageFormat;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.Action;
27 import org.openide.nodes.Sheet;
28 import org.openide.util.Lookup;
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.AnalysisResult;
37 import org.sleuthkit.datamodel.BlackboardArtifact;
38 import org.sleuthkit.datamodel.BlackboardArtifactTag;
39 import org.sleuthkit.datamodel.TskCoreException;
40 import static org.sleuthkit.autopsy.datamodel.Bundle.*;
41 import org.sleuthkit.datamodel.Content;
42 import org.sleuthkit.datamodel.DataArtifact;
43 
51 public class BlackboardArtifactTagNode extends TagNode {
52 
53  private static final Logger LOGGER = Logger.getLogger(BlackboardArtifactTagNode.class.getName());
54  private static final String ICON_PATH = "org/sleuthkit/autopsy/images/green-tag-icon-16.png"; //NON-NLS
55  private final BlackboardArtifactTag tag;
56 
57  public BlackboardArtifactTagNode(BlackboardArtifactTag tag) {
58  super(createLookup(tag), tag.getContent());
59  String name = tag.getContent().getName(); // As a backup.
60  try {
61  name = tag.getArtifact().getShortDescription();
62  } catch (TskCoreException ex) {
63  LOGGER.log(Level.WARNING, "Failed to get short description for artifact id=" + tag.getArtifact().getId(), ex);
64  }
65  setName(name);
66  setDisplayName(name);
67  this.setIconBaseWithExtension(ICON_PATH);
68  this.tag = tag;
69  }
70 
78  private static Lookup createLookup(BlackboardArtifactTag tag) {
79  /*
80  * Make an Autopsy Data Model wrapper for the artifact.
81  *
82  * NOTE: The creation of an Autopsy Data Model independent of the
83  * NetBeans nodes is a work in progress. At the time this comment is
84  * being written, this object is only being used to indicate the item
85  * represented by this BlackboardArtifactTagNode.
86  */
87  Content sourceContent = tag.getContent();
88  BlackboardArtifact artifact = tag.getArtifact();
89  BlackboardArtifactItem<?> artifactItem;
90  if (artifact instanceof AnalysisResult) {
91  artifactItem = new AnalysisResultItem((AnalysisResult) artifact, sourceContent);
92  } else {
93  artifactItem = new DataArtifactItem((DataArtifact) artifact, sourceContent);
94  }
95  return Lookups.fixed(tag, artifactItem, artifact, sourceContent);
96  }
97 
98  @Messages({"BlackboardArtifactTagNode.createSheet.userName.text=User Name"})
99  @Override
100  protected Sheet createSheet() {
101  Sheet propertySheet = super.createSheet();
102  Sheet.Set properties = propertySheet.get(Sheet.PROPERTIES);
103  if (properties == null) {
104  properties = Sheet.createPropertiesSet();
105  propertySheet.put(properties);
106  }
107 
108  properties.put(new NodeProperty<>(
109  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.srcFile.text"),
110  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.srcFile.text"),
111  "",
112  getDisplayName()));
113  addOriginalNameProp(properties);
114  String contentPath;
115  try {
116  contentPath = tag.getContent().getUniquePath();
117  } catch (TskCoreException ex) {
118  Logger.getLogger(ContentTagNode.class.getName()).log(Level.SEVERE, "Failed to get path for content (id = " + tag.getContent().getId() + ")", ex); //NON-NLS
119  contentPath = NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.unavail.text");
120  }
121  properties.put(new NodeProperty<>(
122  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.srcFilePath.text"),
123  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.srcFilePath.text"),
124  "",
125  contentPath));
126  properties.put(new NodeProperty<>(
127  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.resultType.text"),
128  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.resultType.text"),
129  "",
130  tag.getArtifact().getDisplayName()));
131  properties.put(new NodeProperty<>(
132  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.comment.text"),
133  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.comment.text"),
134  "",
135  tag.getComment()));
136  properties.put(new NodeProperty<>(
137  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.userName.text"),
138  NbBundle.getMessage(this.getClass(), "BlackboardArtifactTagNode.createSheet.userName.text"),
139  "",
140  tag.getUserName()));
141  return propertySheet;
142  }
143 
144  @NbBundle.Messages("BlackboardArtifactTagNode.viewSourceArtifact.text=View Source Result")
145  @Override
146  public Action[] getActions(boolean context) {
147  List<Action> actions = new ArrayList<>();
148  BlackboardArtifact artifact = getLookup().lookup(BlackboardArtifact.class);
149  //if this artifact has a time stamp add the action to view it in the timeline
150  try {
152  actions.add(new ViewArtifactInTimelineAction(artifact));
153  }
154  } catch (TskCoreException ex) {
155  LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting arttribute(s) from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
156  }
157 
158  actions.add(new ViewTaggedArtifactAction(Bundle.BlackboardArtifactTagNode_viewSourceArtifact_text(), artifact));
159  actions.add(null);
160  // if the artifact links to another file, add an action to go to that file
161  try {
162  AbstractFile c = findLinked(artifact);
163  if (c != null) {
165  }
166  } catch (TskCoreException ex) {
167  LOGGER.log(Level.SEVERE, MessageFormat.format("Error getting linked file from blackboard artifact{0}.", artifact.getArtifactID()), ex); //NON-NLS
168  }
169  //if this artifact has associated content, add the action to view the content in the timeline
170  AbstractFile file = getLookup().lookup(AbstractFile.class);
171  if (null != file) {
173  }
174  actions.addAll(DataModelActionsFactory.getActions(tag, true));
175  actions.add(null);
176  actions.addAll(Arrays.asList(super.getActions(context)));
177  return actions.toArray(new Action[0]);
178  }
179 
180  @Override
181  public <T> T accept(DisplayableItemNodeVisitor<T> visitor) {
182  return visitor.visit(this);
183  }
184 
185  @Override
186  public String getItemType() {
187  return getClass().getName();
188  }
189 }
static List< Action > getActions(File file, boolean isArtifactSource)
static ViewFileInTimelineAction createViewSourceFileAction(AbstractFile file)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static ViewFileInTimelineAction createViewFileAction(AbstractFile file)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.