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()));
223 boolean commentDataFound =
false;
226 List<CorrelationAttributeInstance> correlatedInstancesList =
229 if (correlatedInstance.getComment() != null && correlatedInstance.getComment().isEmpty() ==
false) {
230 commentDataFound =
true;
231 addCentralRepositoryEntry(html, correlatedInstance);
236 if (commentDataFound ==
false) {
237 addMessage(html,
"There is no comment data for the selected content in the Central Repository.");
240 logger.log(Level.SEVERE,
"Error connecting to the Central Repository database.", ex);
242 logger.log(Level.SEVERE,
"Error normalizing instance from Central Repository database.", ex);
254 jTextPane1.setText(
"<html><body>" + text +
"</body></html>");
264 html.append(
"<p style=\"font-size:14px;font-weight:bold;\">")
275 private void addMessage(StringBuilder html, String message) {
276 html.append(
"<p style=\"font-size:11px;font-style:italic;\">")
288 "AnnotationsContentViewer.tagEntryDataLabel.tag=Tag:",
289 "AnnotationsContentViewer.tagEntryDataLabel.tagUser=Tag User:",
290 "AnnotationsContentViewer.tagEntryDataLabel.comment=Comment:"
294 addRow(html, Bundle.AnnotationsContentViewer_tagEntryDataLabel_tag(), tag.getName().getDisplayName());
295 addRow(html, Bundle.AnnotationsContentViewer_tagEntryDataLabel_tagUser(), tag.getUserName());
296 addRow(html, Bundle.AnnotationsContentViewer_tagEntryDataLabel_comment(), formatHtmlString(tag.getComment()));
309 "AnnotationsContentViewer.centralRepositoryEntryDataLabel.case=Case:",
310 "AnnotationsContentViewer.centralRepositoryEntryDataLabel.type=Type:",
311 "AnnotationsContentViewer.centralRepositoryEntryDataLabel.comment=Comment:",
312 "AnnotationsContentViewer.centralRepositoryEntryDataLabel.path=Path:"
318 addRow(html, Bundle.AnnotationsContentViewer_centralRepositoryEntryDataLabel_comment(), formatHtmlString(attributeInstance.
getComment()));
319 addRow(html, Bundle.AnnotationsContentViewer_centralRepositoryEntryDataLabel_path(), attributeInstance.
getFilePath());
329 html.append(
"<table>");
339 private void addRow(StringBuilder html, String key, String value) {
340 html.append(
"<tr><td valign=\"top\">");
342 html.append(
"</td><td>");
344 html.append(
"</td></tr>");
353 html.append(
"</table><br><br>");
373 String formattedString = StringEscapeUtils.escapeHtml4(text);
374 return formattedString.replaceAll(
"(\r\n|\r|\n|\n\r)",
"<br>");
382 @SuppressWarnings(
"unchecked")
384 private
void initComponents() {
386 jScrollPane5 =
new javax.swing.JScrollPane();
387 jTextPane1 =
new javax.swing.JTextPane();
389 setPreferredSize(
new java.awt.Dimension(100, 58));
391 jTextPane1.setEditable(
false);
392 jTextPane1.setName(
"");
393 jTextPane1.setPreferredSize(
new java.awt.Dimension(600, 52));
394 jScrollPane5.setViewportView(jTextPane1);
396 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
397 this.setLayout(layout);
398 layout.setHorizontalGroup(
399 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
400 .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 907, Short.MAX_VALUE)
402 layout.setVerticalGroup(
403 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
404 .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 435, Short.MAX_VALUE)
415 return Bundle.AnnotationsContentViewer_title();
420 return Bundle.AnnotationsContentViewer_toolTip();
430 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
433 if (artifact != null) {
434 if (artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID()) != null) {
438 if (node.getLookup().lookup(AbstractFile.class) != null) {
442 }
catch (TskCoreException ex) {
443 logger.log(Level.SEVERE, String.format(
444 "Exception while trying to retrieve a Content instance from the BlackboardArtifact '%s' (id=%d).",
445 artifact.getDisplayName(), artifact.getArtifactID()), ex);
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)
static List< CorrelationAttributeInstance > makeInstancesFromBlackboardArtifact(BlackboardArtifact bbArtifact, boolean checkEnabled)
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