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;
40 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT;
41 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT;
43 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT;
51 @ServiceProvider(service = DataContentViewer.class, position = 4)
56 private static final BlackboardAttribute.Type TSK_ASSOCIATED_ARTIFACT_TYPE =
new BlackboardAttribute.Type(TSK_ASSOCIATED_ARTIFACT);
57 public static final BlackboardAttribute.Type TSK_ACCOUNT_TYPE =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ACCOUNT_TYPE);
59 private ExtractedContentPanel
panel;
60 private volatile Node currentNode = null;
61 private IndexedText currentSource = null;
89 if (node == currentNode) {
99 List<IndexedText> sources =
new ArrayList<>();
100 Lookup nodeLookup = node.getLookup();
102 AdHocQueryResult adHocQueryResult = nodeLookup.lookup(AdHocQueryResult.class);
103 AbstractFile file = null;
104 BlackboardArtifact artifact;
110 if (adHocQueryResult != null) {
111 artifact = adHocQueryResult.getArtifact();
112 Content content = adHocQueryResult.getContent();
113 if (content instanceof AbstractFile) {
114 file = (AbstractFile) content;
117 artifact = nodeLookup.lookup(BlackboardArtifact.class);
118 file = nodeLookup.lookup(AbstractFile.class);
125 IndexedText highlightedHitText = null;
126 if (adHocQueryResult != null) {
130 highlightedHitText =
new HighlightedText(adHocQueryResult.getSolrObjectId(), adHocQueryResult.getResults());
131 }
else if (artifact != null) {
132 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
137 highlightedHitText =
new HighlightedText(artifact);
138 }
catch (TskCoreException ex) {
139 logger.log(Level.SEVERE,
"Failed to create HighlightedText for " + artifact, ex);
141 }
else if (artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID() && file != null) {
143 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
144 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
148 highlightedHitText = getAccountsText(file, nodeLookup);
150 }
catch (TskCoreException ex) {
151 logger.log(Level.SEVERE,
"Failed to create AccountsText for " + file, ex);
155 if (highlightedHitText != null) {
156 sources.add(highlightedHitText);
163 IndexedText rawContentText = null;
165 rawContentText =
new RawText(file, file.getId());
166 sources.add(rawContentText);
173 IndexedText rawArtifactText = null;
175 rawArtifactText = getRawArtifactText(artifact);
176 if (rawArtifactText != null) {
177 sources.add(rawArtifactText);
179 }
catch (TskCoreException ex) {
180 logger.log(Level.SEVERE,
"Error creating RawText for " + file, ex);
184 if (highlightedHitText != null) {
185 currentSource = highlightedHitText;
186 }
else if (rawArtifactText != null) {
187 currentSource = rawArtifactText;
189 currentSource = rawContentText;
193 for (IndexedText source : sources) {
194 int currentPage = source.getCurrentPage();
195 if (currentPage == 0 && source.hasNextPage()) {
199 panel.updateControls(currentSource);
201 String contentName =
"";
203 contentName = file.getName();
205 setPanel(contentName, sources);
210 IndexedText rawArtifactText = null;
211 if (null != artifact) {
216 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()
217 || artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID()) {
219 BlackboardAttribute attribute = artifact.getAttribute(TSK_ASSOCIATED_ARTIFACT_TYPE);
220 if (attribute != null) {
221 long artifactId = attribute.getValueLong();
223 rawArtifactText =
new RawText(associatedArtifact, associatedArtifact.getArtifactID());
228 rawArtifactText =
new RawText(artifact, artifact.getArtifactID());
231 return rawArtifactText;
234 static private IndexedText
getAccountsText(Content content, Lookup nodeLookup)
throws TskCoreException {
239 Collection<? extends BlackboardArtifact> artifacts = nodeLookup.lookupAll(BlackboardArtifact.class);
240 artifacts = (artifacts == null || artifacts.isEmpty())
241 ? content.getArtifacts(TSK_ACCOUNT)
244 return new AccountsText(content.getId(), artifacts);
248 final IndexedText source = panel.getSelectedSource();
249 if (source == null || !source.isSearchable()) {
253 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(source.currentItem()));
258 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.getTitle");
263 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.toolTip");
274 panel =
new ExtractedContentPanel();
287 panel.resetDisplay();
289 currentSource = null;
302 AdHocQueryResult adHocQueryResult = node.getLookup().lookup(AdHocQueryResult.class);
303 if (adHocQueryResult != null) {
312 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
313 if (artifact != null) {
314 final int artifactTypeID = artifact.getArtifactTypeID();
315 if (artifactTypeID == TSK_KEYWORD_HIT.getTypeID()) {
317 }
else if (artifactTypeID == TSK_ACCOUNT.getTypeID()) {
319 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
320 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
323 }
catch (TskCoreException ex) {
329 logger.log(Level.SEVERE,
"Error getting TSK_ACCOUNT_TYPE attribute from artifact " + artifact.getArtifactID(), ex);
340 AbstractFile file = node.getLookup().lookup(AbstractFile.class);
341 if (file != null && solrHasContent(file.getId())) {
351 if (artifact != null) {
352 return solrHasContent(artifact.getArtifactID());
360 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
361 if (artifact == null) {
363 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
365 }
else if (artifact.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
367 BlackboardAttribute attribute = artifact.getAttribute(TSK_ACCOUNT_TYPE);
368 if (attribute != null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
373 }
catch (TskCoreException ex) {
374 logger.log(Level.SEVERE,
"Error getting TSK_ACCOUNT_TYPE attribute from artifact " + artifact.getArtifactID(), ex);
390 private void setPanel(String contentName, List<IndexedText> sources) {
392 panel.setSources(contentName, sources);
405 if (solrServer.coreIsOpen() ==
false) {
412 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);
461 IndexedText source = panel.getSelectedSource();
462 final boolean hasPreviousItem = source.hasPreviousItem();
463 final boolean hasPreviousPage = source.hasPreviousPage();
465 if (hasPreviousItem || hasPreviousPage) {
466 if (!hasPreviousItem) {
469 indexVal = source.currentItem();
471 indexVal = source.previousItem();
475 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
478 panel.updateCurrentMatchDisplay(source.currentItem());
479 panel.updateTotaMatcheslDisplay(source.getNumberHits());
482 if (!source.hasPreviousItem() && !source.hasPreviousPage()) {
483 panel.enablePrevMatchControl(
false);
485 if (source.hasNextItem() || source.hasNextPage()) {
486 panel.enableNextMatchControl(
true);
496 currentSource = panel.getSelectedSource();
498 if (currentSource == null) {
503 panel.updateControls(currentSource);
504 panel.updateSearchControls(currentSource);
510 if (currentSource == null) {
511 panel.updateControls(null);
515 if (currentSource.hasNextPage()) {
516 currentSource.nextPage();
519 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
520 panel.refreshCurrentMarkup();
521 panel.setCursor(null);
524 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
530 if (!currentSource.hasNextPage()) {
531 panel.enableNextPageControl(
false);
533 if (currentSource.hasPreviousPage()) {
534 panel.enablePrevPageControl(
true);
537 panel.updateSearchControls(currentSource);
543 if (currentSource == null) {
544 panel.updateControls(null);
548 if (currentSource.hasPreviousPage()) {
549 currentSource.previousPage();
552 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
553 panel.refreshCurrentMarkup();
554 panel.setCursor(null);
557 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
563 if (!currentSource.hasPreviousPage()) {
564 panel.enablePrevPageControl(
false);
566 if (currentSource.hasNextPage()) {
567 panel.enableNextPageControl(
true);
570 panel.updateSearchControls(currentSource);
static synchronized Server getServer()
SleuthkitCase getSleuthkitCase()
boolean queryIsIndexed(long contentID)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)