19 package org.sleuthkit.autopsy.contentviewers;
21 import java.awt.Component;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.logging.Level;
25 import org.apache.commons.lang3.StringEscapeUtils;
27 import org.openide.util.NbBundle;
29 import org.openide.nodes.Node;
30 import org.openide.util.lookup.ServiceProvider;
53 @SuppressWarnings(
"PMD.SingularField")
56 "AnnotationsContentViewer.title=Annotations",
57 "AnnotationsContentViewer.toolTip=Displays tags and comments associated with the selected content."
73 if ((node == null) || (!isSupported(node))) {
78 StringBuilder html =
new StringBuilder();
80 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
81 Content sourceFile = null;
84 if (artifact != null) {
89 sourceFile = artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID());
96 sourceFile = node.getLookup().lookup(AbstractFile.class);
98 }
catch (TskCoreException ex) {
99 logger.log(Level.SEVERE, String.format(
100 "Exception while trying to retrieve a Content instance from the BlackboardArtifact '%s' (id=%d).",
101 artifact.getDisplayName(), artifact.getArtifactID()), ex);
104 if (artifact != null) {
105 populateTagData(html, artifact, sourceFile);
107 populateTagData(html, sourceFile);
110 if (sourceFile instanceof AbstractFile) {
111 populateCentralRepositoryData(html, artifact, (AbstractFile) sourceFile);
114 setText(html.toString());
115 jTextPane1.setCaretPosition(0);
129 startSection(html,
"Selected Item");
130 List<ContentTag> fileTagsList = tskCase.getContentTagsByContent(content);
131 if (fileTagsList.isEmpty()) {
132 addMessage(html,
"There are no tags for the selected content.");
134 for (ContentTag tag : fileTagsList) {
135 addTagEntry(html, tag);
140 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
141 }
catch (TskCoreException ex) {
142 logger.log(Level.SEVERE,
"Exception while getting tags from the case database.", ex);
154 private void populateTagData(StringBuilder html, BlackboardArtifact artifact, Content sourceFile) {
158 startSection(html,
"Selected Item");
159 List<BlackboardArtifactTag> artifactTagsList = tskCase.getBlackboardArtifactTagsByArtifact(artifact);
160 if (artifactTagsList.isEmpty()) {
161 addMessage(html,
"There are no tags for the selected artifact.");
163 for (BlackboardArtifactTag tag : artifactTagsList) {
164 addTagEntry(html, tag);
169 if (sourceFile != null) {
170 startSection(html,
"Source File");
171 List<ContentTag> fileTagsList = tskCase.getContentTagsByContent(sourceFile);
172 if (fileTagsList.isEmpty()) {
173 addMessage(html,
"There are no tags for the source content.");
175 for (ContentTag tag : fileTagsList) {
176 addTagEntry(html, tag);
182 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
183 }
catch (TskCoreException ex) {
184 logger.log(Level.SEVERE,
"Exception while getting tags from the case database.", ex);
198 startSection(html,
"Central Repository Comments");
199 List<CorrelationAttributeInstance> instancesList =
new ArrayList<>();
200 if (artifact != null) {
205 String md5 = sourceFile.getMd5Hash();
206 if (md5 != null && !md5.isEmpty() && null != artifactTypes && !artifactTypes.isEmpty()) {
215 sourceFile.getParentPath() + sourceFile.
getName(),
217 sourceFile.getKnown(),
218 sourceFile.getId()));
224 boolean commentDataFound =
false;
227 List<CorrelationAttributeInstance> correlatedInstancesList
230 if (correlatedInstance.getComment() != null && correlatedInstance.getComment().isEmpty() ==
false) {
231 commentDataFound =
true;
232 addCentralRepositoryEntry(html, correlatedInstance);
237 if (commentDataFound ==
false) {
238 addMessage(html,
"There is no comment data for the selected content in the Central Repository.");
241 logger.log(Level.SEVERE,
"Error connecting to the Central Repository database.", ex);
243 logger.log(Level.SEVERE,
"Error normalizing instance from Central Repository database.", ex);
255 jTextPane1.setText(
"<html><body>" + text +
"</body></html>");
265 html.append(
"<p style=\"font-size:14px;font-weight:bold;\">")
276 private void addMessage(StringBuilder html, String message) {
277 html.append(
"<p style=\"font-size:11px;font-style:italic;\">")
289 "AnnotationsContentViewer.tagEntryDataLabel.tag=Tag:",
290 "AnnotationsContentViewer.tagEntryDataLabel.tagUser=Tag User:",
291 "AnnotationsContentViewer.tagEntryDataLabel.comment=Comment:"
295 addRow(html, Bundle.AnnotationsContentViewer_tagEntryDataLabel_tag(), tag.getName().getDisplayName());
296 addRow(html, Bundle.AnnotationsContentViewer_tagEntryDataLabel_tagUser(), tag.getUserName());
297 addRow(html, Bundle.AnnotationsContentViewer_tagEntryDataLabel_comment(), formatHtmlString(tag.getComment()));
310 "AnnotationsContentViewer.centralRepositoryEntryDataLabel.case=Case:",
311 "AnnotationsContentViewer.centralRepositoryEntryDataLabel.type=Type:",
312 "AnnotationsContentViewer.centralRepositoryEntryDataLabel.comment=Comment:",
313 "AnnotationsContentViewer.centralRepositoryEntryDataLabel.path=Path:"
319 addRow(html, Bundle.AnnotationsContentViewer_centralRepositoryEntryDataLabel_comment(), formatHtmlString(attributeInstance.
getComment()));
320 addRow(html, Bundle.AnnotationsContentViewer_centralRepositoryEntryDataLabel_path(), attributeInstance.
getFilePath());
330 html.append(
"<table>");
340 private void addRow(StringBuilder html, String key, String value) {
341 html.append(
"<tr><td valign=\"top\">");
343 html.append(
"</td><td>");
345 html.append(
"</td></tr>");
354 html.append(
"</table><br><br>");
375 String formattedString = StringEscapeUtils.escapeHtml4(text);
376 return formattedString.replaceAll(
"(\r\n|\r|\n|\n\r)",
"<br>");
384 @SuppressWarnings(
"unchecked")
386 private
void initComponents() {
388 jScrollPane5 =
new javax.swing.JScrollPane();
389 jTextPane1 =
new javax.swing.JTextPane();
391 setPreferredSize(
new java.awt.Dimension(100, 58));
393 jTextPane1.setEditable(
false);
394 jTextPane1.setName(
"");
395 jTextPane1.setPreferredSize(
new java.awt.Dimension(600, 52));
396 jScrollPane5.setViewportView(jTextPane1);
398 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
399 this.setLayout(layout);
400 layout.setHorizontalGroup(
401 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
402 .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 907, Short.MAX_VALUE)
404 layout.setVerticalGroup(
405 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
406 .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
417 return Bundle.AnnotationsContentViewer_title();
422 return Bundle.AnnotationsContentViewer_toolTip();
432 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
435 if (artifact != null) {
436 if (artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID()) != null) {
440 if (node.getLookup().lookup(AbstractFile.class) != null) {
444 }
catch (TskCoreException ex) {
445 logger.log(Level.SEVERE, String.format(
446 "Exception while trying to retrieve a Content instance from the BlackboardArtifact '%s' (id=%d).",
447 artifact.getDisplayName(), artifact.getArtifactID()), ex);
static List< CorrelationAttributeInstance > makeInstancesFromBlackboardArtifact(BlackboardArtifact artifact, boolean checkEnabled)
static CorrelationDataSource fromTSKDataSource(CorrelationCase correlationCase, Content dataSource)
void addCentralRepositoryEntry(StringBuilder html, CorrelationAttributeInstance attributeInstance)
List< CorrelationAttributeInstance > getArtifactInstancesByTypeValue(CorrelationAttributeInstance.Type aType, String value)
void populateTagData(StringBuilder html, Content content)
List< CorrelationAttributeInstance.Type > getDefinedCorrelationTypes()
void startTable(StringBuilder html)
String formatHtmlString(String text)
void addTagEntry(StringBuilder html, Tag tag)
void setText(String text)
Type getCorrelationType()
static EamDb getInstance()
static void configureTextPaneAsHtml(JTextPane pane)
DataContentViewer createInstance()
void populateCentralRepositoryData(StringBuilder html, BlackboardArtifact artifact, AbstractFile sourceFile)
void addRow(StringBuilder html, String key, String value)
javax.swing.JTextPane jTextPane1
static boolean isEnabled()
AnnotationsContentViewer()
SleuthkitCase getSleuthkitCase()
void endSection(StringBuilder html)
void populateTagData(StringBuilder html, BlackboardArtifact artifact, Content sourceFile)
boolean isSupported(Node node)
CorrelationCase getCase(Case autopsyCase)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
CorrelationCase getCorrelationCase()
javax.swing.JScrollPane jScrollPane5
void endTable(StringBuilder html)
void addMessage(StringBuilder html, String message)
int isPreferred(Node node)
void startSection(StringBuilder html, String sectionName)
static final int FILES_TYPE_ID