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;
 
   38 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT;
 
   39 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT;
 
   41 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT;
 
   49 @ServiceProvider(service = DataContentViewer.class, position = 4)
 
   54     private static final long INVALID_DOCUMENT_ID = 0L;
 
   55     private static final BlackboardAttribute.Type TSK_ASSOCIATED_ARTIFACT_TYPE = 
new BlackboardAttribute.Type(TSK_ASSOCIATED_ARTIFACT);
 
   57     private ExtractedContentPanel 
panel;
 
   58     private volatile Node currentNode = null;
 
   59     private IndexedText currentSource = null;
 
   87         if (node == currentNode) {
 
   93         Lookup nodeLookup = node.getLookup();
 
   94         AbstractFile content = nodeLookup.lookup(AbstractFile.class);
 
  100         List<IndexedText> sources = 
new ArrayList<>();
 
  101         IndexedText highlightedHitText = null;
 
  102         IndexedText rawContentText = null;
 
  104         if (null != content && solrHasContent(content.getId())) {
 
  105             QueryResults hits = nodeLookup.lookup(QueryResults.class);
 
  106             BlackboardArtifact artifact = nodeLookup.lookup(BlackboardArtifact.class);
 
  112                 highlightedHitText = 
new HighlightedText(content.getId(), hits);
 
  113             } 
else if (artifact != null
 
  114                     && artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID()) {
 
  117                     highlightedHitText = getAccountsText(content, nodeLookup);
 
  118                 } 
catch (TskCoreException ex) {
 
  119                     logger.log(Level.SEVERE, 
"Failed to create AccountsText for " + content, ex); 
 
  122             } 
else if (artifact != null
 
  123                     && artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
 
  126                     highlightedHitText = 
new HighlightedText(artifact);
 
  127                 } 
catch (TskCoreException ex) {
 
  128                     logger.log(Level.SEVERE, 
"Failed to create HighlightedText for " + artifact, ex); 
 
  132             if (highlightedHitText != null) {
 
  133                 sources.add(highlightedHitText);
 
  140             rawContentText = 
new RawText(content, content.getId());
 
  141             sources.add(rawContentText);
 
  148         IndexedText rawArtifactText = null;
 
  150             rawArtifactText = getRawArtifactText(nodeLookup);
 
  151         } 
catch (TskCoreException ex) {
 
  152             logger.log(Level.SEVERE, 
"Error creating RawText for " + content, ex); 
 
  155         if (rawArtifactText != null) {
 
  156             sources.add(rawArtifactText);
 
  160         if (null != highlightedHitText) {
 
  161             currentSource = highlightedHitText;
 
  162         } 
else if (null != rawContentText) {
 
  163             currentSource = rawContentText;
 
  165             currentSource = rawArtifactText;
 
  169         for (IndexedText source : sources) {
 
  170             int currentPage = source.getCurrentPage();
 
  171             if (currentPage == 0 && source.hasNextPage()) {
 
  175         panel.updateControls(currentSource);
 
  176         setPanel(content.getName(), sources);
 
  180         IndexedText rawArtifactText = null;
 
  181         BlackboardArtifact artifact = nodeLookup.lookup(BlackboardArtifact.class);
 
  182         if (null != artifact) {
 
  187             if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()
 
  188                     || artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID()) {
 
  190                 BlackboardAttribute attribute = artifact.getAttribute(TSK_ASSOCIATED_ARTIFACT_TYPE);
 
  191                 if (attribute != null) {
 
  192                     long artifactId = attribute.getValueLong();
 
  194                     rawArtifactText = 
new RawText(associatedArtifact, associatedArtifact.getArtifactID());
 
  199                 rawArtifactText = 
new RawText(artifact, artifact.getArtifactID());
 
  202         return rawArtifactText;
 
  205     static private IndexedText 
getAccountsText(Content content, Lookup nodeLookup) 
throws TskCoreException {
 
  210         Collection<? extends BlackboardArtifact> artifacts = nodeLookup.lookupAll(BlackboardArtifact.class);
 
  211         artifacts = (artifacts == null || artifacts.isEmpty())
 
  212                 ? content.getArtifacts(TSK_ACCOUNT)
 
  215         return new AccountsText(content.getId(), artifacts);
 
  219         final IndexedText source = panel.getSelectedSource();
 
  220         if (source == null || !source.isSearchable()) {
 
  224         panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(source.currentItem()));
 
  229         return NbBundle.getMessage(this.getClass(), 
"ExtractedContentViewer.getTitle");
 
  234         return NbBundle.getMessage(this.getClass(), 
"ExtractedContentViewer.toolTip");
 
  245             panel = 
new ExtractedContentPanel();
 
  258         panel.resetDisplay();
 
  260         currentSource = null;
 
  272         Collection<? extends BlackboardArtifact> artifacts = node.getLookup().lookupAll(BlackboardArtifact.class);
 
  273         if (artifacts != null) {
 
  274             for (BlackboardArtifact art : artifacts) {
 
  275                 final int artifactTypeID = art.getArtifactTypeID();
 
  276                 if (artifactTypeID == TSK_ACCOUNT.getTypeID()
 
  277                         || artifactTypeID == TSK_KEYWORD_HIT.getTypeID()) {
 
  287         long documentID = getDocumentId(node);
 
  288         if (INVALID_DOCUMENT_ID == documentID) {
 
  292         return solrHasContent(documentID);
 
  297         BlackboardArtifact art = node.getLookup().lookup(BlackboardArtifact.class);
 
  301         } 
else if (art.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()
 
  302                 || art.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
 
  317     private void setPanel(String contentName, List<IndexedText> sources) {
 
  319             panel.setSources(contentName, sources);
 
  332         if (solrServer.coreIsOpen() == 
false) {
 
  339             logger.log(Level.SEVERE, 
"Error querying Solr server", ex); 
 
  361         BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
 
  362         if (null != artifact) {
 
  363             if (artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
 
  364                 return artifact.getArtifactID();
 
  368                     BlackboardAttribute blackboardAttribute = artifact.getAttribute(TSK_ASSOCIATED_ARTIFACT_TYPE);
 
  369                     if (blackboardAttribute != null) {
 
  370                         return blackboardAttribute.getValueLong();
 
  372                 } 
catch (TskCoreException ex) {
 
  373                     logger.log(Level.SEVERE, 
"Error getting associated artifact attributes", ex); 
 
  384         Content content = node.getLookup().lookup(Content.class);
 
  385         if (content != null) {
 
  386             return content.getId();
 
  399             IndexedText source = panel.getSelectedSource();
 
  400             if (source == null) {
 
  402                 panel.updateControls(null);
 
  405             final boolean hasNextItem = source.hasNextItem();
 
  406             final boolean hasNextPage = source.hasNextPage();
 
  408             if (hasNextItem || hasNextPage) {
 
  412                     indexVal = source.currentItem();
 
  414                     indexVal = source.nextItem();
 
  418                 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
 
  421                 panel.updateCurrentMatchDisplay(source.currentItem());
 
  422                 panel.updateTotaMatcheslDisplay(source.getNumberHits());
 
  425                 if (!source.hasNextItem() && !source.hasNextPage()) {
 
  426                     panel.enableNextMatchControl(
false);
 
  428                 if (source.hasPreviousItem() || source.hasPreviousPage()) {
 
  429                     panel.enablePrevMatchControl(
true);
 
  439             IndexedText source = panel.getSelectedSource();
 
  440             final boolean hasPreviousItem = source.hasPreviousItem();
 
  441             final boolean hasPreviousPage = source.hasPreviousPage();
 
  443             if (hasPreviousItem || hasPreviousPage) {
 
  444                 if (!hasPreviousItem) {
 
  447                     indexVal = source.currentItem();
 
  449                     indexVal = source.previousItem();
 
  453                 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
 
  456                 panel.updateCurrentMatchDisplay(source.currentItem());
 
  457                 panel.updateTotaMatcheslDisplay(source.getNumberHits());
 
  460                 if (!source.hasPreviousItem() && !source.hasPreviousPage()) {
 
  461                     panel.enablePrevMatchControl(
false);
 
  463                 if (source.hasNextItem() || source.hasNextPage()) {
 
  464                     panel.enableNextMatchControl(
true);
 
  474             currentSource = panel.getSelectedSource();
 
  476             if (currentSource == null) {
 
  481             panel.updateControls(currentSource);
 
  482             panel.updateSearchControls(currentSource);
 
  488         if (currentSource == null) {
 
  489             panel.updateControls(null);
 
  493         if (currentSource.hasNextPage()) {
 
  494             currentSource.nextPage();
 
  497             panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
  498             panel.refreshCurrentMarkup();
 
  499             panel.setCursor(null);
 
  502             panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
 
  508             if (!currentSource.hasNextPage()) {
 
  509                 panel.enableNextPageControl(
false);
 
  511             if (currentSource.hasPreviousPage()) {
 
  512                 panel.enablePrevPageControl(
true);
 
  515             panel.updateSearchControls(currentSource);
 
  521         if (currentSource == null) {
 
  522             panel.updateControls(null);
 
  526         if (currentSource.hasPreviousPage()) {
 
  527             currentSource.previousPage();
 
  530             panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
  531             panel.refreshCurrentMarkup();
 
  532             panel.setCursor(null);
 
  535             panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
 
  541             if (!currentSource.hasPreviousPage()) {
 
  542                 panel.enablePrevPageControl(
false);
 
  544             if (currentSource.hasNextPage()) {
 
  545                 panel.enableNextPageControl(
true);
 
  548             panel.updateSearchControls(currentSource);
 
static synchronized Server getServer()
 
SleuthkitCase getSleuthkitCase()
 
boolean queryIsIndexed(long contentID)
 
static Case getCurrentCase()
 
synchronized static Logger getLogger(String name)