19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.Component;
22 import java.awt.Cursor;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.List;
28 import java.util.logging.Level;
29 import org.openide.nodes.Node;
30 import org.openide.util.Lookup;
31 import org.openide.util.NbBundle;
32 import org.openide.util.lookup.ServiceProvider;
41 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT;
42 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT;
44 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT;
53 @ServiceProvider(service = DataContentViewer.class, position = 4)
58 private static final BlackboardAttribute.Type TSK_ASSOCIATED_ARTIFACT_TYPE =
new BlackboardAttribute.Type(TSK_ASSOCIATED_ARTIFACT);
59 private static final BlackboardAttribute.Type TSK_ACCOUNT_TYPE =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ACCOUNT_TYPE);
61 private ExtractedContentPanel
panel;
62 private volatile Node currentNode = null;
63 private IndexedText currentSource = null;
91 if (node == currentNode) {
101 List<IndexedText> sources =
new ArrayList<>();
102 Lookup nodeLookup = node.getLookup();
108 AdHocQueryResult adHocQueryResult = nodeLookup.lookup(AdHocQueryResult.class);
109 AbstractFile file = nodeLookup.lookup(AbstractFile.class);
110 BlackboardArtifact artifact = nodeLookup.lookup(BlackboardArtifact.class);
111 Report report = nodeLookup.lookup(Report.class);
117 IndexedText highlightedHitText = null;
118 if (adHocQueryResult != null) {
122 highlightedHitText =
new HighlightedText(adHocQueryResult.getSolrObjectId(), adHocQueryResult.getResults());
123 }
else if (artifact != null) {
124 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
129 highlightedHitText =
new HighlightedText(artifact);
130 }
catch (TskCoreException ex) {
131 logger.log(Level.SEVERE,
"Failed to create HighlightedText for " + artifact, ex);
133 }
else if (artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID() && file != null) {
135 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
136 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
140 highlightedHitText = getAccountsText(file, nodeLookup);
142 }
catch (TskCoreException ex) {
143 logger.log(Level.SEVERE,
"Failed to create AccountsText for " + file, ex);
147 if (highlightedHitText != null) {
148 sources.add(highlightedHitText);
155 IndexedText rawContentText = null;
157 rawContentText =
new RawText(file, file.getId());
158 sources.add(rawContentText);
165 if (report != null) {
166 rawContentText =
new RawText(report, report.getId());
167 sources.add(rawContentText);
174 IndexedText rawArtifactText = null;
176 rawArtifactText = getRawArtifactText(artifact);
177 if (rawArtifactText != null) {
178 sources.add(rawArtifactText);
181 logger.log(Level.SEVERE,
"Error creating RawText for " + file, ex);
185 if (highlightedHitText != null) {
186 currentSource = highlightedHitText;
187 }
else if (rawArtifactText != null) {
188 currentSource = rawArtifactText;
190 currentSource = rawContentText;
194 for (IndexedText source : sources) {
195 int currentPage = source.getCurrentPage();
196 if (currentPage == 0 && source.hasNextPage()) {
200 panel.updateControls(currentSource);
202 String contentName =
"";
204 contentName = file.getName();
206 setPanel(contentName, sources);
211 IndexedText rawArtifactText = null;
212 if (null != artifact) {
217 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()
218 || artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID()) {
220 BlackboardAttribute attribute = artifact.getAttribute(TSK_ASSOCIATED_ARTIFACT_TYPE);
221 if (attribute != null) {
222 long artifactId = attribute.getValueLong();
224 rawArtifactText =
new RawText(associatedArtifact, associatedArtifact.getArtifactID());
229 rawArtifactText =
new RawText(artifact, artifact.getArtifactID());
232 return rawArtifactText;
235 static private IndexedText
getAccountsText(Content content, Lookup nodeLookup)
throws TskCoreException {
240 Collection<? extends BlackboardArtifact> artifacts = nodeLookup.lookupAll(BlackboardArtifact.class);
241 artifacts = (artifacts == null || artifacts.isEmpty())
242 ? content.getArtifacts(TSK_ACCOUNT)
245 return new AccountsText(content.getId(), artifacts);
249 final IndexedText source = panel.getSelectedSource();
250 if (source == null || !source.isSearchable()) {
254 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(source.currentItem()));
259 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.getTitle");
264 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.toolTip");
275 panel =
new ExtractedContentPanel();
288 panel.resetDisplay();
290 currentSource = null;
303 AdHocQueryResult adHocQueryResult = node.getLookup().lookup(AdHocQueryResult.class);
304 if (adHocQueryResult != null) {
313 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
314 if (artifact != null) {
315 final int artifactTypeID = artifact.getArtifactTypeID();
316 if (artifactTypeID == TSK_KEYWORD_HIT.getTypeID()) {
318 }
else if (artifactTypeID == TSK_ACCOUNT.getTypeID()) {
320 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
321 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
324 }
catch (TskCoreException ex) {
330 logger.log(Level.SEVERE,
"Error getting TSK_ACCOUNT_TYPE attribute from artifact " + artifact.getArtifactID(), ex);
341 AbstractFile file = node.getLookup().lookup(AbstractFile.class);
342 if (file != null && solrHasContent(file.getId())) {
352 if (artifact != null) {
353 return solrHasContent(artifact.getArtifactID());
361 Report report = node.getLookup().lookup(Report.class);
362 if (report != null) {
363 return solrHasContent(report.getId());
375 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
376 if (artifact == null) {
378 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
380 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
382 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
383 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
388 }
catch (TskCoreException ex) {
389 logger.log(Level.SEVERE,
"Error getting TSK_ACCOUNT_TYPE attribute from artifact " + artifact.getArtifactID(), ex);
405 private void setPanel(String contentName, List<IndexedText> sources) {
407 panel.setSources(contentName, sources);
420 if (solrServer.coreIsOpen() ==
false) {
427 logger.log(Level.SEVERE,
"Error querying Solr server", ex);
436 IndexedText source = panel.getSelectedSource();
437 if (source == null) {
439 panel.updateControls(null);
442 final boolean hasNextItem = source.hasNextItem();
443 final boolean hasNextPage = source.hasNextPage();
445 if (hasNextItem || hasNextPage) {
449 indexVal = source.currentItem();
451 indexVal = source.nextItem();
455 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
458 panel.updateCurrentMatchDisplay(source.currentItem());
459 panel.updateTotaMatcheslDisplay(source.getNumberHits());
462 if (!source.hasNextItem() && !source.hasNextPage()) {
463 panel.enableNextMatchControl(
false);
465 if (source.hasPreviousItem() || source.hasPreviousPage()) {
466 panel.enablePrevMatchControl(
true);
476 IndexedText source = panel.getSelectedSource();
477 final boolean hasPreviousItem = source.hasPreviousItem();
478 final boolean hasPreviousPage = source.hasPreviousPage();
480 if (hasPreviousItem || hasPreviousPage) {
481 if (!hasPreviousItem) {
484 indexVal = source.currentItem();
486 indexVal = source.previousItem();
490 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
493 panel.updateCurrentMatchDisplay(source.currentItem());
494 panel.updateTotaMatcheslDisplay(source.getNumberHits());
497 if (!source.hasPreviousItem() && !source.hasPreviousPage()) {
498 panel.enablePrevMatchControl(
false);
500 if (source.hasNextItem() || source.hasNextPage()) {
501 panel.enableNextMatchControl(
true);
511 currentSource = panel.getSelectedSource();
513 if (currentSource == null) {
518 panel.updateControls(currentSource);
519 panel.updateSearchControls(currentSource);
525 if (currentSource == null) {
526 panel.updateControls(null);
530 if (currentSource.hasNextPage()) {
531 currentSource.nextPage();
534 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
535 panel.refreshCurrentMarkup();
536 panel.setCursor(null);
539 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
545 if (!currentSource.hasNextPage()) {
546 panel.enableNextPageControl(
false);
548 if (currentSource.hasPreviousPage()) {
549 panel.enablePrevPageControl(
true);
552 panel.updateSearchControls(currentSource);
558 if (currentSource == null) {
559 panel.updateControls(null);
563 if (currentSource.hasPreviousPage()) {
564 currentSource.previousPage();
567 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
568 panel.refreshCurrentMarkup();
569 panel.setCursor(null);
572 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
578 if (!currentSource.hasPreviousPage()) {
579 panel.enablePrevPageControl(
false);
581 if (currentSource.hasNextPage()) {
582 panel.enableNextPageControl(
true);
585 panel.updateSearchControls(currentSource);
static synchronized Server getServer()
SleuthkitCase getSleuthkitCase()
boolean queryIsIndexed(long contentID)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()