19 package org.sleuthkit.autopsy.keywordsearch;
 
   21 import java.util.LinkedHashMap;
 
   22 import java.util.logging.Level;
 
   23 import org.apache.solr.client.solrj.SolrServerException;
 
   24 import org.openide.util.NbBundle;
 
   35 class RawTextMarkup 
implements TextMarkup {
 
   36     private int numPages = 0;
 
   37     private int currentPage = 0;
 
   38     private boolean hasChunks = 
false;
 
   40     private final Content content;
 
   41     private final long objectId;
 
   43     private String cachedString;
 
   44     private int cachedChunk;
 
   45     private static final Logger logger = Logger.getLogger(RawTextMarkup.class.getName());
 
   57     RawTextMarkup(Content content, 
long objectId) {
 
   58         this.content = content;
 
   59         this.objectId = objectId;
 
   67     public long getObjectId() {
 
   72     public int getCurrentPage() {
 
   73         return this.currentPage;
 
   77     public boolean hasNextPage() {
 
   78         return currentPage < numPages;
 
   82     public boolean hasPreviousPage() {
 
   83         return currentPage > 1;
 
   87     public int nextPage() {
 
   89             throw new IllegalStateException(
 
   90                     NbBundle.getMessage(
this.getClass(), 
"ExtractedContentViewer.nextPage.exception.msg"));
 
   97     public int previousPage() {
 
   98         if (!hasPreviousPage()) {
 
   99             throw new IllegalStateException(
 
  100                     NbBundle.getMessage(
this.getClass(), 
"ExtractedContentViewer.previousPage.exception.msg"));
 
  107     public boolean hasNextItem() {
 
  108         throw new UnsupportedOperationException(
 
  109                 NbBundle.getMessage(
this.getClass(), 
"ExtractedContentViewer.hasNextItem.exception.msg"));
 
  113     public boolean hasPreviousItem() {
 
  114         throw new UnsupportedOperationException(
 
  115                 NbBundle.getMessage(
this.getClass(), 
"ExtractedContentViewer.hasPreviousItem.exception.msg"));
 
  119     public int nextItem() {
 
  120         throw new UnsupportedOperationException(
 
  121                 NbBundle.getMessage(
this.getClass(), 
"ExtractedContentViewer.nextItem.exception.msg"));
 
  125     public int previousItem() {
 
  126         throw new UnsupportedOperationException(
 
  127                 NbBundle.getMessage(
this.getClass(), 
"ExtractedContentViewer.previousItem.exception.msg"));
 
  131     public int currentItem() {
 
  132         throw new UnsupportedOperationException(
 
  133                 NbBundle.getMessage(
this.getClass(), 
"ExtractedContentViewer.currentItem.exception.msg"));
 
  137     public String getMarkup() {
 
  139             return getSolrContent(currentPage, hasChunks);
 
  140         } 
catch (SolrServerException ex) {
 
  141             logger.log(Level.WARNING, 
"Couldn't get extracted content.", ex); 
 
  147     public String toString() {
 
  148         return NbBundle.getMessage(this.getClass(), 
"ExtractedContentViewer.toString");
 
  152     public boolean isSearchable() {
 
  157     public String getAnchorPrefix() {
 
  162     public int getNumberHits() {
 
  167     public LinkedHashMap<Integer, Integer> getHitsPages() {
 
  172     public int getNumberPages() {
 
  179     private void initialize() {
 
  180         final Server solrServer = KeywordSearch.getServer();
 
  184             numPages = solrServer.queryNumFileChunks(this.objectId);
 
  191         } 
catch (KeywordSearchModuleException ex) {
 
  192             logger.log(Level.WARNING, 
"Could not get number of chunks: ", ex); 
 
  194         } 
catch (NoOpenCoreException ex) {
 
  195             logger.log(Level.WARNING, 
"Could not get number of chunks: ", ex); 
 
  211     private String getSolrContent(
int currentPage, 
boolean hasChunks) 
throws SolrServerException {
 
  212         final Server solrServer = KeywordSearch.getServer();
 
  214         if (hasChunks == 
false) {
 
  218             String name = content.getName();
 
  220             if (content instanceof AbstractFile) {
 
  222                 boolean isKnown = TskData.FileKnown.KNOWN.equals(((AbstractFile) content).getKnown());
 
  223                 if (isKnown && KeywordSearchSettings.getSkipKnown()) {
 
  224                     msg = NbBundle.getMessage(this.getClass(), 
"ExtractedContentViewer.getSolrContent.knownFileMsg", name);
 
  228                 msg = NbBundle.getMessage(this.getClass(), 
"ExtractedContentViewer.getSolrContent.noTxtYetMsg", name);
 
  230             String htmlMsg = NbBundle.getMessage(this.getClass(), 
"ExtractedContentViewer.getSolrContent.txtBodyItal", msg);
 
  234         int chunkId = currentPage;
 
  237         if (cachedString != null) {
 
  238             if (cachedChunk == chunkId) {
 
  245             String indexedText = solrServer.getSolrContent(this.objectId, chunkId);
 
  246             cachedString = EscapeUtil.escapeHtml(indexedText).trim();
 
  247             StringBuilder sb = 
new StringBuilder(cachedString.length() + 20);
 
  248             sb.append(
"<pre>").append(cachedString).append(
"</pre>"); 
 
  249             cachedString = sb.toString();
 
  250             cachedChunk = chunkId;
 
  251         } 
catch (NoOpenCoreException ex) {
 
  252             logger.log(Level.WARNING, 
"Couldn't get text content.", ex);