19package org.sleuthkit.autopsy.keywordsearch;
21import java.awt.Component;
22import java.awt.Cursor;
23import java.awt.event.ActionEvent;
24import java.awt.event.ActionListener;
25import java.beans.PropertyChangeEvent;
26import java.util.ArrayList;
27import java.util.Collection;
28import java.util.EnumSet;
29import java.util.LinkedHashMap;
32import java.util.logging.Level;
33import org.apache.tika.mime.MimeTypes;
34import org.openide.nodes.Node;
35import org.openide.util.Lookup;
36import org.openide.util.NbBundle;
37import org.openide.util.lookup.ServiceProvider;
38import org.sleuthkit.autopsy.casemodule.Case;
39import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
40import org.sleuthkit.autopsy.corecomponentinterfaces.TextViewer;
41import org.sleuthkit.autopsy.coreutils.Logger;
42import org.sleuthkit.autopsy.keywordsearch.AdHocSearchChildFactory.AdHocQueryResult;
43import org.sleuthkit.autopsy.modules.filetypeid.FileTypeDetector;
44import org.sleuthkit.autopsy.textextractors.TextExtractor;
45import org.sleuthkit.autopsy.textextractors.TextExtractorFactory;
46import org.sleuthkit.datamodel.AbstractFile;
47import org.sleuthkit.datamodel.Account;
48import org.sleuthkit.datamodel.BlackboardArtifact;
49import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT;
50import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT;
51import org.sleuthkit.datamodel.BlackboardAttribute;
52import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT;
53import org.sleuthkit.datamodel.Content;
54import org.sleuthkit.datamodel.Report;
55import org.sleuthkit.datamodel.TskCoreException;
56import org.sleuthkit.datamodel.TskData;
62@ServiceProvider(service =
TextViewer.class, position = 2)
68 private static final BlackboardAttribute.Type
TSK_ACCOUNT_TYPE =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ACCOUNT_TYPE);
70 private ExtractedContentPanel
panel;
88 logger.log(Level.SEVERE,
"Failed to initialize FileTypeDetector", ex);
94 solrCache.clearCache();
126 List<ExtractedText> sources =
new ArrayList<>();
127 Lookup nodeLookup = node.getLookup();
133 AdHocQueryResult adHocQueryResult = nodeLookup.lookup(AdHocQueryResult.class);
134 AbstractFile file = nodeLookup.lookup(AbstractFile.class);
135 BlackboardArtifact artifact = nodeLookup.lookup(BlackboardArtifact.class);
136 Report
report = nodeLookup.lookup(Report.class);
143 if (adHocQueryResult !=
null) {
147 highlightedHitText =
new HighlightedText(adHocQueryResult.getSolrObjectId(), adHocQueryResult.getResults());
148 }
else if (artifact !=
null) {
149 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
154 highlightedHitText =
new HighlightedText(artifact);
155 }
catch (TskCoreException ex) {
156 logger.log(Level.SEVERE,
"Failed to create HighlightedText for " + artifact, ex);
158 }
else if (artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID() && file !=
null) {
161 if (attribute !=
null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
167 }
catch (TskCoreException ex) {
168 logger.log(Level.SEVERE,
"Failed to create AccountsText for " + file, ex);
172 if (highlightedHitText !=
null) {
173 sources.add(highlightedHitText);
185 rawContentText =
new SolrIndexedText(file, file.getId());
186 sources.add(rawContentText);
192 rawContentText =
new FileReaderExtractedText(file);
193 sources.add(rawContentText);
208 rawContentText =
new SolrIndexedText(
report,
report.getId());
209 sources.add(rawContentText);
220 if (rawArtifactText !=
null) {
221 sources.add(rawArtifactText);
224 logger.log(Level.SEVERE,
"Error creating RawText for " + file, ex);
228 if (highlightedHitText !=
null) {
230 }
else if (rawArtifactText !=
null) {
238 int currentPage = source.getCurrentPage();
239 if (currentPage == 0 && source.hasNextPage()) {
245 String contentName =
"";
247 contentName = file.getName();
255 if (
null != artifact) {
260 if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()
261 || artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID()) {
264 if (attribute !=
null) {
265 long artifactId = attribute.getValueLong();
268 rawArtifactText =
new SolrIndexedText(associatedArtifact, associatedArtifact.getArtifactID());
274 rawArtifactText =
new SolrIndexedText(artifact, artifact.getArtifactID());
278 return rawArtifactText;
286 Collection<? extends BlackboardArtifact> artifacts = nodeLookup.lookupAll(BlackboardArtifact.class);
287 artifacts = (artifacts ==
null || artifacts.isEmpty())
288 ? content.getArtifacts(TSK_ACCOUNT)
291 return new AccountsText(content.getId(), artifacts);
305 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.getTitle");
310 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.toolTip");
321 panel =
new ExtractedContentPanel();
333 panel.resetDisplay();
349 AdHocQueryResult adHocQueryResult = node.getLookup().lookup(AdHocQueryResult.class);
350 if (adHocQueryResult !=
null) {
359 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
360 if (artifact !=
null) {
361 final int artifactTypeID = artifact.getArtifactTypeID();
362 if (artifactTypeID == TSK_KEYWORD_HIT.getTypeID()) {
364 }
else if (artifactTypeID == TSK_ACCOUNT.getTypeID()) {
367 if (attribute !=
null && Account.Type.CREDIT_CARD.getTypeName().equals(attribute.getValueString())) {
370 }
catch (TskCoreException ex) {
376 logger.log(Level.SEVERE,
"Error getting TSK_ACCOUNT_TYPE attribute from artifact " + artifact.getArtifactID(), ex);
387 AbstractFile file = node.getLookup().lookup(AbstractFile.class);
408 if (artifact !=
null) {
417 Report
report = node.getLookup().lookup(Report.class);
442 private void setPanel(String contentName, List<ExtractedText> sources) {
444 panel.setSources(contentName, sources);
464 return solrCache.getCombination(objectId);
468 if (solrServer.coreIsOpen() ==
false) {
469 solrCache.putCombination(objectId,
false);
476 solrCache.putCombination(objectId, isFullyIndexed);
477 return isFullyIndexed;
479 logger.log(Level.SEVERE,
"Error querying Solr server", ex);
480 solrCache.putCombination(objectId,
false);
496 TskData.TSK_DB_FILES_TYPE_ENUM fileType = file.getType();
498 if (fileType.equals(TskData.TSK_DB_FILES_TYPE_ENUM.VIRTUAL_DIR)) {
502 if ((fileType.equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)
503 || fileType.equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNUSED_BLOCKS))
504 || (fileType.equals(TskData.TSK_DB_FILES_TYPE_ENUM.CARVED))) {
508 final long size = file.getSize();
509 if (file.isDir() || size == 0) {
519 if (MimeTypes.OCTET_STREAM.equals(mimeType)) {
527 FileReaderExtractedText tmp =
new FileReaderExtractedText(file);
543 if (source ==
null) {
545 panel.updateControls(
null);
551 if (hasNextItem || hasNextPage) {
569 panel.enableNextMatchControl(
false);
572 panel.enablePrevMatchControl(
true);
589 if (hasPreviousItem || hasPreviousPage) {
590 if (!hasPreviousItem) {
607 panel.enablePrevMatchControl(
false);
610 panel.enableNextMatchControl(
true);
637 panel.updateControls(
null);
645 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
646 panel.refreshCurrentMarkup();
647 panel.setCursor(
null);
657 panel.enableNextPageControl(
false);
660 panel.enablePrevPageControl(
true);
670 panel.updateControls(
null);
678 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
679 panel.refreshCurrentMarkup();
680 panel.setCursor(
null);
690 panel.enablePrevPageControl(
false);
693 panel.enableNextPageControl(
true);
730 private final LinkedHashMap<Long, Boolean>
cache;
733 this.cache =
new LinkedHashMap<Long, Boolean>(
CACHE_SIZE, 0.75f,
true) {
735 protected boolean removeEldestEntry(Map.Entry<Long, Boolean> eldest) {
742 cache.put(key, value);
746 return cache.get(key);
754 return cache.containsKey(key);
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
synchronized static Logger getLogger(String name)
static synchronized Server getServer()
boolean queryIsFullyIndexed(long contentID)