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 AdHocQueryResult adhocResult = node.getLookup().lookup(AdHocQueryResult.class);
376 if (adhocResult != null) {
381 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
382 if (artifact == null) {
384 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
386 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
388 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
389 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
394 }
catch (TskCoreException ex) {
395 logger.log(Level.SEVERE,
"Error getting TSK_ACCOUNT_TYPE attribute from artifact " + artifact.getArtifactID(), ex);
411 private void setPanel(String contentName, List<IndexedText> sources) {
413 panel.setSources(contentName, sources);
426 if (solrServer.coreIsOpen() ==
false) {
433 logger.log(Level.SEVERE,
"Error querying Solr server", ex);
442 IndexedText source = panel.getSelectedSource();
443 if (source == null) {
445 panel.updateControls(null);
448 final boolean hasNextItem = source.hasNextItem();
449 final boolean hasNextPage = source.hasNextPage();
451 if (hasNextItem || hasNextPage) {
455 indexVal = source.currentItem();
457 indexVal = source.nextItem();
461 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
464 panel.updateCurrentMatchDisplay(source.currentItem());
465 panel.updateTotaMatcheslDisplay(source.getNumberHits());
468 if (!source.hasNextItem() && !source.hasNextPage()) {
469 panel.enableNextMatchControl(
false);
471 if (source.hasPreviousItem() || source.hasPreviousPage()) {
472 panel.enablePrevMatchControl(
true);
482 IndexedText source = panel.getSelectedSource();
483 final boolean hasPreviousItem = source.hasPreviousItem();
484 final boolean hasPreviousPage = source.hasPreviousPage();
486 if (hasPreviousItem || hasPreviousPage) {
487 if (!hasPreviousItem) {
490 indexVal = source.currentItem();
492 indexVal = source.previousItem();
496 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
499 panel.updateCurrentMatchDisplay(source.currentItem());
500 panel.updateTotaMatcheslDisplay(source.getNumberHits());
503 if (!source.hasPreviousItem() && !source.hasPreviousPage()) {
504 panel.enablePrevMatchControl(
false);
506 if (source.hasNextItem() || source.hasNextPage()) {
507 panel.enableNextMatchControl(
true);
517 currentSource = panel.getSelectedSource();
519 if (currentSource == null) {
524 panel.updateControls(currentSource);
525 panel.updateSearchControls(currentSource);
531 if (currentSource == null) {
532 panel.updateControls(null);
536 if (currentSource.hasNextPage()) {
537 currentSource.nextPage();
540 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
541 panel.refreshCurrentMarkup();
542 panel.setCursor(null);
545 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
551 if (!currentSource.hasNextPage()) {
552 panel.enableNextPageControl(
false);
554 if (currentSource.hasPreviousPage()) {
555 panel.enablePrevPageControl(
true);
558 panel.updateSearchControls(currentSource);
564 if (currentSource == null) {
565 panel.updateControls(null);
569 if (currentSource.hasPreviousPage()) {
570 currentSource.previousPage();
573 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
574 panel.refreshCurrentMarkup();
575 panel.setCursor(null);
578 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
584 if (!currentSource.hasPreviousPage()) {
585 panel.enablePrevPageControl(
false);
587 if (currentSource.hasNextPage()) {
588 panel.enableNextPageControl(
true);
591 panel.updateSearchControls(currentSource);
static synchronized Server getServer()
SleuthkitCase getSleuthkitCase()
boolean queryIsIndexed(long contentID)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()