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 = TextViewer.class, position = 2)
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;
92 if (node.equals(currentNode)) {
102 List<IndexedText> sources =
new ArrayList<>();
103 Lookup nodeLookup = node.getLookup();
109 AdHocQueryResult adHocQueryResult = nodeLookup.lookup(AdHocQueryResult.class);
110 AbstractFile file = nodeLookup.lookup(AbstractFile.class);
111 BlackboardArtifact artifact = nodeLookup.lookup(BlackboardArtifact.class);
112 Report report = nodeLookup.lookup(Report.class);
118 IndexedText highlightedHitText = null;
119 if (adHocQueryResult != null) {
123 highlightedHitText =
new HighlightedText(adHocQueryResult.getSolrObjectId(), adHocQueryResult.getResults());
124 }
else if (artifact != null) {
125 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
130 highlightedHitText =
new HighlightedText(artifact);
131 }
catch (TskCoreException ex) {
132 logger.log(Level.SEVERE,
"Failed to create HighlightedText for " + artifact, ex);
134 }
else if (artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID() && file != null) {
136 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
137 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
141 highlightedHitText = getAccountsText(file, nodeLookup);
143 }
catch (TskCoreException ex) {
144 logger.log(Level.SEVERE,
"Failed to create AccountsText for " + file, ex);
148 if (highlightedHitText != null) {
149 sources.add(highlightedHitText);
156 IndexedText rawContentText = null;
158 rawContentText =
new RawText(file, file.getId());
159 sources.add(rawContentText);
166 if (report != null) {
167 rawContentText =
new RawText(report, report.getId());
168 sources.add(rawContentText);
175 IndexedText rawArtifactText = null;
177 rawArtifactText = getRawArtifactText(artifact);
178 if (rawArtifactText != null) {
179 sources.add(rawArtifactText);
182 logger.log(Level.SEVERE,
"Error creating RawText for " + file, ex);
186 if (highlightedHitText != null) {
187 currentSource = highlightedHitText;
188 }
else if (rawArtifactText != null) {
189 currentSource = rawArtifactText;
191 currentSource = rawContentText;
195 for (IndexedText source : sources) {
196 int currentPage = source.getCurrentPage();
197 if (currentPage == 0 && source.hasNextPage()) {
201 panel.updateControls(currentSource);
203 String contentName =
"";
205 contentName = file.getName();
207 setPanel(contentName, sources);
212 IndexedText rawArtifactText = null;
213 if (null != artifact) {
218 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()
219 || artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID()) {
221 BlackboardAttribute attribute = artifact.getAttribute(TSK_ASSOCIATED_ARTIFACT_TYPE);
222 if (attribute != null) {
223 long artifactId = attribute.getValueLong();
225 rawArtifactText =
new RawText(associatedArtifact, associatedArtifact.getArtifactID());
230 rawArtifactText =
new RawText(artifact, artifact.getArtifactID());
233 return rawArtifactText;
236 static private IndexedText
getAccountsText(Content content, Lookup nodeLookup)
throws TskCoreException {
241 Collection<? extends BlackboardArtifact> artifacts = nodeLookup.lookupAll(BlackboardArtifact.class);
242 artifacts = (artifacts == null || artifacts.isEmpty())
243 ? content.getArtifacts(TSK_ACCOUNT)
246 return new AccountsText(content.getId(), artifacts);
250 final IndexedText source = panel.getSelectedSource();
251 if (source == null || !source.isSearchable()) {
255 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(source.currentItem()));
260 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.getTitle");
265 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.toolTip");
276 panel =
new ExtractedContentPanel();
288 panel.resetDisplay();
290 currentSource = null;
291 panel.updateControls(currentSource);
304 AdHocQueryResult adHocQueryResult = node.getLookup().lookup(AdHocQueryResult.class);
305 if (adHocQueryResult != null) {
314 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
315 if (artifact != null) {
316 final int artifactTypeID = artifact.getArtifactTypeID();
317 if (artifactTypeID == TSK_KEYWORD_HIT.getTypeID()) {
319 }
else if (artifactTypeID == TSK_ACCOUNT.getTypeID()) {
321 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
322 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
325 }
catch (TskCoreException ex) {
331 logger.log(Level.SEVERE,
"Error getting TSK_ACCOUNT_TYPE attribute from artifact " + artifact.getArtifactID(), ex);
342 AbstractFile file = node.getLookup().lookup(AbstractFile.class);
343 if (file != null && solrHasContent(file.getId())) {
353 if (artifact != null) {
354 return solrHasContent(artifact.getArtifactID());
362 Report report = node.getLookup().lookup(Report.class);
363 if (report != null) {
364 return solrHasContent(report.getId());
376 AdHocQueryResult adhocResult = node.getLookup().lookup(AdHocQueryResult.class);
377 if (adhocResult != null) {
382 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
383 if (artifact == null) {
385 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
387 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
389 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
390 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
395 }
catch (TskCoreException ex) {
396 logger.log(Level.SEVERE,
"Error getting TSK_ACCOUNT_TYPE attribute from artifact " + artifact.getArtifactID(), ex);
412 private void setPanel(String contentName, List<IndexedText> sources) {
414 panel.setSources(contentName, sources);
427 if (solrServer.coreIsOpen() ==
false) {
434 logger.log(Level.SEVERE,
"Error querying Solr server", ex);
446 IndexedText source = panel.getSelectedSource();
447 if (source == null) {
449 panel.updateControls(null);
452 final boolean hasNextItem = source.hasNextItem();
453 final boolean hasNextPage = source.hasNextPage();
455 if (hasNextItem || hasNextPage) {
459 indexVal = source.currentItem();
461 indexVal = source.nextItem();
465 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
468 panel.updateCurrentMatchDisplay(source.currentItem());
469 panel.updateTotaMatcheslDisplay(source.getNumberHits());
472 if (!source.hasNextItem() && !source.hasNextPage()) {
473 panel.enableNextMatchControl(
false);
475 if (source.hasPreviousItem() || source.hasPreviousPage()) {
476 panel.enablePrevMatchControl(
true);
489 IndexedText source = panel.getSelectedSource();
490 final boolean hasPreviousItem = source.hasPreviousItem();
491 final boolean hasPreviousPage = source.hasPreviousPage();
493 if (hasPreviousItem || hasPreviousPage) {
494 if (!hasPreviousItem) {
497 indexVal = source.currentItem();
499 indexVal = source.previousItem();
503 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
506 panel.updateCurrentMatchDisplay(source.currentItem());
507 panel.updateTotaMatcheslDisplay(source.getNumberHits());
510 if (!source.hasPreviousItem() && !source.hasPreviousPage()) {
511 panel.enablePrevMatchControl(
false);
513 if (source.hasNextItem() || source.hasNextPage()) {
514 panel.enableNextMatchControl(
true);
527 currentSource = panel.getSelectedSource();
529 if (currentSource == null) {
534 panel.updateControls(currentSource);
540 if (currentSource == null) {
541 panel.updateControls(null);
545 if (currentSource.hasNextPage()) {
546 currentSource.nextPage();
549 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
550 panel.refreshCurrentMarkup();
551 panel.setCursor(null);
554 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
557 scrollToCurrentHit();
560 if (!currentSource.hasNextPage()) {
561 panel.enableNextPageControl(
false);
563 if (currentSource.hasPreviousPage()) {
564 panel.enablePrevPageControl(
true);
567 panel.updateSearchControls(currentSource);
573 if (currentSource == null) {
574 panel.updateControls(null);
578 if (currentSource.hasPreviousPage()) {
579 currentSource.previousPage();
582 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
583 panel.refreshCurrentMarkup();
584 panel.setCursor(null);
587 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
590 scrollToCurrentHit();
593 if (!currentSource.hasPreviousPage()) {
594 panel.enablePrevPageControl(
false);
596 if (currentSource.hasNextPage()) {
597 panel.enableNextPageControl(
true);
600 panel.updateSearchControls(currentSource);
static synchronized Server getServer()
SleuthkitCase getSleuthkitCase()
boolean queryIsIndexed(long contentID)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()