19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.util.logging.Level;
22 import org.apache.solr.client.solrj.SolrServerException;
23 import org.openide.util.NbBundle;
35 class SolrIndexedText
implements ExtractedText {
37 private int numPages = 0;
38 private int currentPage = 0;
39 private boolean hasChunks =
false;
40 private final Content content;
41 private final BlackboardArtifact blackboardArtifact;
42 private final long objectId;
43 private static final Logger logger = Logger.getLogger(SolrIndexedText.class.getName());
56 SolrIndexedText(Content content,
long objectId) {
57 this.content = content;
58 this.blackboardArtifact = null;
59 this.objectId = objectId;
63 SolrIndexedText(BlackboardArtifact bba,
long objectId) {
65 this.blackboardArtifact = bba;
66 this.objectId = objectId;
75 public long getObjectId() {
80 public int getCurrentPage() {
81 return this.currentPage;
85 public boolean hasNextPage() {
86 return currentPage < numPages;
90 public boolean hasPreviousPage() {
91 return currentPage > 1;
95 public int nextPage() {
97 throw new IllegalStateException(
98 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.nextPage.exception.msg"));
105 public int previousPage() {
106 if (!hasPreviousPage()) {
107 throw new IllegalStateException(
108 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.previousPage.exception.msg"));
115 public boolean hasNextItem() {
116 throw new UnsupportedOperationException(
117 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.hasNextItem.exception.msg"));
121 public boolean hasPreviousItem() {
122 throw new UnsupportedOperationException(
123 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.hasPreviousItem.exception.msg"));
127 public int nextItem() {
128 throw new UnsupportedOperationException(
129 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.nextItem.exception.msg"));
133 public int previousItem() {
134 throw new UnsupportedOperationException(
135 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.previousItem.exception.msg"));
139 public int currentItem() {
140 throw new UnsupportedOperationException(
141 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.currentItem.exception.msg"));
145 public String getText() {
147 if (this.content != null) {
148 return getContentText(currentPage, hasChunks);
149 }
else if (this.blackboardArtifact != null) {
150 return getArtifactText();
152 }
catch (SolrServerException | NoOpenCoreException ex) {
153 logger.log(Level.SEVERE,
"Couldn't get extracted text", ex);
155 return Bundle.ExtractedText_errorMessage_errorGettingText();
159 "SolrIndexedText.FileText=File Text",
160 "SolrIndexedText.ResultText=Result Text"})
162 public String toString() {
163 if (null != content) {
164 return Bundle.SolrIndexedText_FileText();
166 return Bundle.SolrIndexedText_ResultText();
171 public boolean isSearchable() {
176 public String getAnchorPrefix() {
181 public int getNumberHits() {
186 public int getNumberPages() {
193 private void initialize() {
194 final Server solrServer = KeywordSearch.getServer();
198 numPages = solrServer.queryNumFileChunks(this.objectId);
205 }
catch (KeywordSearchModuleException | NoOpenCoreException ex) {
206 logger.log(Level.SEVERE,
"Could not get number of chunks: ", ex);
226 private String getContentText(
int currentPage,
boolean hasChunks)
throws NoOpenCoreException, SolrServerException {
227 final Server solrServer = KeywordSearch.getServer();
229 if (hasChunks ==
false) {
235 if (content instanceof AbstractFile) {
237 boolean isKnown = TskData.FileKnown.KNOWN.equals(((AbstractFile) content).getKnown());
238 if (isKnown && KeywordSearchSettings.getSkipKnown()) {
239 msg = Bundle.ExtractedText_warningMessage_knownFile();
243 msg = Bundle.ExtractedText_warningMessage_noTextAvailable();
248 int chunkId = currentPage;
250 String indexedText = solrServer.getSolrContent(this.objectId, chunkId);
251 if (indexedText == null) {
252 if (content instanceof AbstractFile) {
253 return Bundle.ExtractedText_errorMessage_errorGettingText();
255 return Bundle.ExtractedText_warningMessage_noTextAvailable();
257 }
else if (indexedText.isEmpty()) {
258 return Bundle.ExtractedText_warningMessage_noTextAvailable();
261 indexedText = EscapeUtil.escapeHtml(indexedText).trim();
262 StringBuilder sb =
new StringBuilder(indexedText.length() + 20);
263 sb.append(
"<pre>").append(indexedText).append(
"</pre>");
264 return sb.toString();
276 private String getArtifactText() throws NoOpenCoreException, SolrServerException {
277 String indexedText = KeywordSearch.getServer().getSolrContent(this.objectId, 1);
278 if (indexedText == null || indexedText.isEmpty()) {
279 return Bundle.ExtractedText_errorMessage_errorGettingText();
282 indexedText = EscapeUtil.escapeHtml(indexedText).trim();
283 StringBuilder sb =
new StringBuilder(indexedText.length() + 20);
284 sb.append(
"<pre>").append(indexedText).append(
"</pre>");
286 return sb.toString();