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.HashSet;
 
   28 import java.util.List;
 
   30 import java.util.logging.Level;
 
   31 import org.apache.commons.lang.StringUtils;
 
   32 import org.openide.nodes.Node;
 
   33 import org.openide.util.Lookup;
 
   34 import org.openide.util.NbBundle;
 
   35 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 org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE;
 
   44 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT;
 
   52 @ServiceProvider(service = DataContentViewer.class, position = 4)
 
   57     private static final long INVALID_DOCUMENT_ID = 0L;
 
   58     private static final BlackboardAttribute.Type TSK_ASSOCIATED_ARTIFACT_TYPE = 
new BlackboardAttribute.Type(TSK_ASSOCIATED_ARTIFACT);
 
   60     private ExtractedContentPanel 
panel;
 
   61     private volatile Node currentNode = null;
 
   62     private IndexedText currentSource = null;
 
   90         if (node == currentNode) {
 
   96         Lookup nodeLookup = node.getLookup();
 
   97         Content content = nodeLookup.lookup(Content.class);
 
  104         List<IndexedText> sources = 
new ArrayList<>();
 
  105         IndexedText highlightedHitText = null;
 
  106         IndexedText rawContentText = null;
 
  107         IndexedText rawArtifactText = null;
 
  114         sources.addAll(nodeLookup.lookupAll(IndexedText.class));
 
  116         if (!sources.isEmpty()) {
 
  118             highlightedHitText = sources.get(0);
 
  119         } 
else if (null != content && solrHasContent(content.getId())) {
 
  124             String solrDocumentID = String.valueOf(content.getId()); 
 
  125             Set<String> accountNumbers = 
new HashSet<>();
 
  128                 Collection<? extends BlackboardArtifact> artifacts = nodeLookup.lookupAll(BlackboardArtifact.class);
 
  129                 artifacts = (artifacts == null || artifacts.isEmpty())
 
  130                         ? content.getArtifacts(TSK_ACCOUNT)
 
  141                 for (BlackboardArtifact artifact : artifacts) {
 
  143                         BlackboardAttribute solrIDAttr = artifact.getAttribute(
new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_DOCUMENT_ID));
 
  144                         if (solrIDAttr != null) {
 
  145                             String valueString = solrIDAttr.getValueString();
 
  146                             if (StringUtils.isNotBlank(valueString)) {
 
  147                                 solrDocumentID = valueString;
 
  151                         BlackboardAttribute keyWordAttr = artifact.getAttribute(
new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_CARD_NUMBER));
 
  152                         if (keyWordAttr != null) {
 
  153                             String valueString = keyWordAttr.getValueString();
 
  154                             if (StringUtils.isNotBlank(valueString)) {
 
  155                                 accountNumbers.add(valueString);
 
  159                     } 
catch (TskCoreException ex) {
 
  160                         logger.log(Level.SEVERE, 
"Failed to retrieve Blackboard Attributes", ex); 
 
  163                 if (accountNumbers.isEmpty() == 
false) {
 
  164                     highlightedHitText = 
new AccountsText(solrDocumentID, accountNumbers);
 
  165                     sources.add(highlightedHitText);
 
  167             } 
catch (TskCoreException ex) {
 
  168                 logger.log(Level.SEVERE, 
"Failed to retrieve Blackboard Artifacts", ex); 
 
  176         if (null != content && solrHasContent(content.getId())) {
 
  177             rawContentText = 
new RawText(content, content.getId());
 
  178             sources.add(rawContentText);
 
  185         BlackboardArtifact artifact = nodeLookup.lookup(BlackboardArtifact.class);
 
  186         if (null != artifact) {
 
  191             if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID() || artifact.getArtifactTypeID() == TSK_ACCOUNT.getTypeID()) {
 
  193                     BlackboardAttribute attribute = artifact.getAttribute(TSK_ASSOCIATED_ARTIFACT_TYPE);
 
  194                     if (attribute != null) {
 
  195                         long artifactId = attribute.getValueLong();
 
  197                         rawArtifactText = 
new RawText(associatedArtifact, associatedArtifact.getArtifactID());
 
  198                         sources.add(rawArtifactText);
 
  200                 } 
catch (TskCoreException ex) {
 
  201                     logger.log(Level.SEVERE, 
"Error getting associated artifact attributes", ex); 
 
  204                 rawArtifactText = 
new RawText(artifact, artifact.getArtifactID());
 
  205                 sources.add(rawArtifactText);
 
  211         if (null != highlightedHitText) {
 
  212             currentSource = highlightedHitText;
 
  213         } 
else if (null != rawContentText) {
 
  214             currentSource = rawContentText;
 
  216             currentSource = rawArtifactText;
 
  220         for (IndexedText source : sources) {
 
  221             int currentPage = source.getCurrentPage();
 
  222             if (currentPage == 0 && source.hasNextPage()) {
 
  226         updatePageControls();
 
  231         final IndexedText source = panel.getSelectedSource();
 
  232         if (source == null || !source.isSearchable()) {
 
  236         panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(source.currentItem()));
 
  242         return NbBundle.getMessage(this.getClass(), 
"ExtractedContentViewer.getTitle");
 
  247         return NbBundle.getMessage(this.getClass(), 
"ExtractedContentViewer.toolTip");
 
  258             panel = 
new ExtractedContentPanel();
 
  262             panel.addNextPageControlListener(
new NextPageActionListener());
 
  270         setPanel(
new ArrayList<>());
 
  271         panel.resetDisplay();
 
  273         currentSource = null;
 
  288         Collection<? extends IndexedText> sources = node.getLookup().lookupAll(IndexedText.class);
 
  289         if (sources.isEmpty() == 
false) {
 
  296         Collection<? extends BlackboardArtifact> artifacts = node.getLookup().lookupAll(BlackboardArtifact.class);
 
  297         if (artifacts != null) {
 
  298             for (BlackboardArtifact art : artifacts) {
 
  299                 if (art.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
 
  309         long documentID = getDocumentId(node);
 
  310         if (INVALID_DOCUMENT_ID == documentID) {
 
  314         return solrHasContent(documentID);
 
  319         BlackboardArtifact art = node.getLookup().lookup(BlackboardArtifact.class);
 
  323         } 
else if (art.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()
 
  324                 || art.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_ACCOUNT.getTypeID()) {
 
  339             panel.setSources(sources);
 
  355             logger.log(Level.SEVERE, 
"Error querying Solr server", ex); 
 
  377         BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
 
  378         if (null != artifact) {
 
  379             if (artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
 
  380                 return artifact.getArtifactID();
 
  384                     BlackboardAttribute blackboardAttribute = artifact.getAttribute(TSK_ASSOCIATED_ARTIFACT_TYPE);
 
  385                     if (blackboardAttribute != null) {
 
  386                         return blackboardAttribute.getValueLong();
 
  388                 } 
catch (TskCoreException ex) {
 
  389                     logger.log(Level.SEVERE, 
"Error getting associated artifact attributes", ex); 
 
  400         Content content = node.getLookup().lookup(Content.class);
 
  401         if (content != null) {
 
  402             return content.getId();
 
  415             IndexedText source = panel.getSelectedSource();
 
  416             if (source == null) {
 
  418                 panel.updateControls(null);
 
  421             final boolean hasNextItem = source.hasNextItem();
 
  422             final boolean hasNextPage = source.hasNextPage();
 
  424             if (hasNextItem || hasNextPage) {
 
  428                     indexVal = source.currentItem();
 
  430                     indexVal = source.nextItem();
 
  434                 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
 
  437                 panel.updateCurrentMatchDisplay(source.currentItem());
 
  438                 panel.updateTotaMatcheslDisplay(source.getNumberHits());
 
  441                 if (!source.hasNextItem() && !source.hasNextPage()) {
 
  442                     panel.enableNextMatchControl(
false);
 
  444                 if (source.hasPreviousItem() || source.hasPreviousPage()) {
 
  445                     panel.enablePrevMatchControl(
true);
 
  455             IndexedText source = panel.getSelectedSource();
 
  456             final boolean hasPreviousItem = source.hasPreviousItem();
 
  457             final boolean hasPreviousPage = source.hasPreviousPage();
 
  459             if (hasPreviousItem || hasPreviousPage) {
 
  460                 if (!hasPreviousItem) {
 
  463                     indexVal = source.currentItem();
 
  465                     indexVal = source.previousItem();
 
  469                 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
 
  472                 panel.updateCurrentMatchDisplay(source.currentItem());
 
  473                 panel.updateTotaMatcheslDisplay(source.getNumberHits());
 
  476                 if (!source.hasPreviousItem() && !source.hasPreviousPage()) {
 
  477                     panel.enablePrevMatchControl(
false);
 
  479                 if (source.hasNextItem() || source.hasNextPage()) {
 
  480                     panel.enableNextMatchControl(
true);
 
  491             currentSource = panel.getSelectedSource();
 
  493             if (currentSource == null) {
 
  498             updatePageControls();
 
  499             updateSearchControls();
 
  505         panel.updateSearchControls(currentSource);
 
  509         panel.updateControls(currentSource);
 
  514         if (currentSource == null) {
 
  515             panel.updateControls(null);
 
  519         if (currentSource.hasNextPage()) {
 
  520             currentSource.nextPage();
 
  523             panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
  524             panel.refreshCurrentMarkup();
 
  525             panel.setCursor(null);
 
  528             panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
 
  534             if (!currentSource.hasNextPage()) {
 
  535                 panel.enableNextPageControl(
false);
 
  537             if (currentSource.hasPreviousPage()) {
 
  538                 panel.enablePrevPageControl(
true);
 
  541             updateSearchControls();
 
  547         if (currentSource == null) {
 
  548             panel.updateControls(null);
 
  552         if (currentSource.hasPreviousPage()) {
 
  553             currentSource.previousPage();
 
  556             panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
 
  557             panel.refreshCurrentMarkup();
 
  558             panel.setCursor(null);
 
  561             panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
 
  567             if (!currentSource.hasPreviousPage()) {
 
  568                 panel.enablePrevPageControl(
false);
 
  570             if (currentSource.hasNextPage()) {
 
  571                 panel.enableNextPageControl(
true);
 
  574             updateSearchControls();
 
  579     class NextPageActionListener 
implements ActionListener {
 
  582         public void actionPerformed(ActionEvent e) {
 
static synchronized Server getServer()
SleuthkitCase getSleuthkitCase()
boolean queryIsIndexed(long contentID)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)