Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MessageDataContent.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2017-18 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.communications.relationships;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.util.List;
23 import java.util.concurrent.ExecutionException;
24 import java.util.logging.Level;
25 import javax.swing.SwingWorker;
26 import org.openide.explorer.ExplorerManager;
27 import org.openide.nodes.Node;
28 import org.openide.util.Exceptions;
34 import org.sleuthkit.datamodel.AbstractFile;
35 import org.sleuthkit.datamodel.BlackboardArtifact;
36 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT;
37 import org.sleuthkit.datamodel.BlackboardAttribute;
38 import org.sleuthkit.datamodel.SleuthkitCase;
39 import org.sleuthkit.datamodel.TskCoreException;
40 
50 final class MessageDataContent extends MessageArtifactViewer implements DataContent, ExplorerManager.Provider {
51 
52  private static final Logger LOGGER = Logger.getLogger(MessageDataContent.class.getName());
53 
54  private static final long serialVersionUID = 1L;
55  final private ExplorerManager explorerManager = new ExplorerManager();
56 
57  private ArtifactFetcher worker;
58 
59  @Override
60  public void propertyChange(final PropertyChangeEvent evt) {
61  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
62  }
63 
64  @Override
65  public ExplorerManager getExplorerManager() {
66  return explorerManager;
67  }
68 
69  @Override
70  public void setNode(Node node) {
71  if(worker != null) {
72  worker.cancel(true);
73  worker = null;
74  }
75 
76  if(node == null) {
78  return;
79  }
80 
81  worker = new ArtifactFetcher(node);
82  worker.execute();
83  }
84 
97  private BlackboardArtifact getNodeArtifact(Node node) {
98  BlackboardArtifact nodeArtifact = node.getLookup().lookup(BlackboardArtifact.class);
99 
100  if (nodeArtifact == null) {
101  try {
102  SleuthkitCase tskCase = Case.getCurrentCaseThrows().getSleuthkitCase();
103  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
104  if (file != null) {
105  List<BlackboardArtifact> artifactsList = tskCase.getBlackboardArtifacts(TSK_ASSOCIATED_OBJECT, file.getId());
106 
107  for (BlackboardArtifact fileArtifact : artifactsList) {
108  BlackboardAttribute associatedArtifactAttribute = fileArtifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
109  if (associatedArtifactAttribute != null) {
110  BlackboardArtifact associatedArtifact = fileArtifact.getSleuthkitCase().getBlackboardArtifact(associatedArtifactAttribute.getValueLong());
111  if (isMessageArtifact(associatedArtifact)) {
112  nodeArtifact = associatedArtifact;
113  }
114  }
115  }
116  }
117  } catch (NoCurrentCaseException | TskCoreException ex) {
118  LOGGER.log(Level.SEVERE, "Failed to get file for selected node.", ex); //NON-NLS
119  }
120  }
121 
122  return nodeArtifact;
123  }
124 
125  private class ArtifactFetcher extends SwingWorker<BlackboardArtifact, Void> {
126  private final Node node;
127 
128  ArtifactFetcher(Node node) {
129  this.node = node;
130  }
131 
132  @Override
133  protected BlackboardArtifact doInBackground() throws Exception {
134  return getNodeArtifact(node);
135  }
136 
137  @Override
138  public void done() {
139  if(isCancelled()) {
140  return;
141  }
142 
143  try {
144  setArtifact(get());
145  } catch (InterruptedException | ExecutionException ex) {
146  LOGGER.log(Level.SEVERE, "Failed to get node for artifact.", ex); //NON-NLS
147  }
148  }
149  }
150 }

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.