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());
387 private void setPanel(String contentName, List<IndexedText> sources) {
389 panel.setSources(contentName, sources);
402 if (solrServer.coreIsOpen() ==
false) {
409 logger.log(Level.SEVERE,
"Error querying Solr server", ex);
421 IndexedText source = panel.getSelectedSource();
422 if (source == null) {
424 panel.updateControls(null);
427 final boolean hasNextItem = source.hasNextItem();
428 final boolean hasNextPage = source.hasNextPage();
430 if (hasNextItem || hasNextPage) {
434 indexVal = source.currentItem();
436 indexVal = source.nextItem();
440 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
443 panel.updateCurrentMatchDisplay(source.currentItem());
444 panel.updateTotaMatcheslDisplay(source.getNumberHits());
447 if (!source.hasNextItem() && !source.hasNextPage()) {
448 panel.enableNextMatchControl(
false);
450 if (source.hasPreviousItem() || source.hasPreviousPage()) {
451 panel.enablePrevMatchControl(
true);
464 IndexedText source = panel.getSelectedSource();
465 final boolean hasPreviousItem = source.hasPreviousItem();
466 final boolean hasPreviousPage = source.hasPreviousPage();
468 if (hasPreviousItem || hasPreviousPage) {
469 if (!hasPreviousItem) {
472 indexVal = source.currentItem();
474 indexVal = source.previousItem();
478 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
481 panel.updateCurrentMatchDisplay(source.currentItem());
482 panel.updateTotaMatcheslDisplay(source.getNumberHits());
485 if (!source.hasPreviousItem() && !source.hasPreviousPage()) {
486 panel.enablePrevMatchControl(
false);
488 if (source.hasNextItem() || source.hasNextPage()) {
489 panel.enableNextMatchControl(
true);
502 currentSource = panel.getSelectedSource();
504 if (currentSource == null) {
509 panel.updateControls(currentSource);
515 if (currentSource == null) {
516 panel.updateControls(null);
520 if (currentSource.hasNextPage()) {
521 currentSource.nextPage();
524 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
525 panel.refreshCurrentMarkup();
526 panel.setCursor(null);
529 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
532 scrollToCurrentHit();
535 if (!currentSource.hasNextPage()) {
536 panel.enableNextPageControl(
false);
538 if (currentSource.hasPreviousPage()) {
539 panel.enablePrevPageControl(
true);
542 panel.updateSearchControls(currentSource);
548 if (currentSource == null) {
549 panel.updateControls(null);
553 if (currentSource.hasPreviousPage()) {
554 currentSource.previousPage();
557 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
558 panel.refreshCurrentMarkup();
559 panel.setCursor(null);
562 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
565 scrollToCurrentHit();
568 if (!currentSource.hasPreviousPage()) {
569 panel.enablePrevPageControl(
false);
571 if (currentSource.hasNextPage()) {
572 panel.enableNextPageControl(
true);
575 panel.updateSearchControls(currentSource);
static synchronized Server getServer()
SleuthkitCase getSleuthkitCase()
boolean queryIsIndexed(long contentID)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()