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;
36 class RawText
implements IndexedText {
38 private int numPages = 0;
39 private int currentPage = 0;
40 private boolean hasChunks =
false;
41 private final Content content;
42 private final BlackboardArtifact blackboardArtifact;
43 private final long objectId;
45 private String cachedString;
46 private int cachedChunk;
47 private static final Logger logger = Logger.getLogger(RawText.class.getName());
60 RawText(Content content,
long objectId) {
61 this.content = content;
62 this.blackboardArtifact = null;
63 this.objectId = objectId;
67 RawText(BlackboardArtifact bba,
long objectId) {
69 this.blackboardArtifact = bba;
70 this.objectId = objectId;
79 public long getObjectId() {
84 public int getCurrentPage() {
85 return this.currentPage;
89 public boolean hasNextPage() {
90 return currentPage < numPages;
94 public boolean hasPreviousPage() {
95 return currentPage > 1;
99 public int nextPage() {
100 if (!hasNextPage()) {
101 throw new IllegalStateException(
102 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.nextPage.exception.msg"));
109 public int previousPage() {
110 if (!hasPreviousPage()) {
111 throw new IllegalStateException(
112 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.previousPage.exception.msg"));
119 public boolean hasNextItem() {
120 throw new UnsupportedOperationException(
121 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.hasNextItem.exception.msg"));
125 public boolean hasPreviousItem() {
126 throw new UnsupportedOperationException(
127 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.hasPreviousItem.exception.msg"));
131 public int nextItem() {
132 throw new UnsupportedOperationException(
133 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.nextItem.exception.msg"));
137 public int previousItem() {
138 throw new UnsupportedOperationException(
139 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.previousItem.exception.msg"));
143 public int currentItem() {
144 throw new UnsupportedOperationException(
145 NbBundle.getMessage(
this.getClass(),
"ExtractedContentViewer.currentItem.exception.msg"));
149 public String getText() {
151 if (this.content != null) {
152 return getContentText(currentPage, hasChunks);
153 }
else if (this.blackboardArtifact != null) {
154 return getArtifactText();
156 }
catch (SolrServerException ex) {
157 logger.log(Level.SEVERE,
"Couldn't get extracted content", ex);
159 return NbBundle.getMessage(this.getClass(),
"RawText.getText.error.msg");
163 "RawText.FileText=File Text",
164 "RawText.ResultText=Result Text"})
166 public String toString() {
167 if (null != content) {
168 return Bundle.RawText_FileText();
170 return Bundle.RawText_ResultText();
175 public boolean isSearchable() {
180 public String getAnchorPrefix() {
185 public int getNumberHits() {
191 public int getNumberPages() {
198 private void initialize() {
199 final Server solrServer = KeywordSearch.getServer();
203 numPages = solrServer.queryNumFileChunks(this.objectId);
210 }
catch (KeywordSearchModuleException ex) {
211 logger.log(Level.WARNING,
"Could not get number of chunks: ", ex);
213 }
catch (NoOpenCoreException ex) {
214 logger.log(Level.WARNING,
"Could not get number of chunks: ", ex);
232 private String getContentText(
int currentPage,
boolean hasChunks)
throws SolrServerException {
233 final Server solrServer = KeywordSearch.getServer();
235 if (hasChunks ==
false) {
239 String name = content.getName();
241 if (content instanceof AbstractFile) {
243 boolean isKnown = TskData.FileKnown.KNOWN.equals(((AbstractFile) content).getKnown());
244 if (isKnown && KeywordSearchSettings.getSkipKnown()) {
245 msg = NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.getSolrContent.knownFileMsg", name);
249 msg = NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.getSolrContent.noTxtYetMsg", name);
251 String htmlMsg = NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.getSolrContent.txtBodyItal", msg);
255 int chunkId = currentPage;
258 if (cachedString != null) {
259 if (cachedChunk == chunkId) {
266 String indexedText = solrServer.getSolrContent(this.objectId, chunkId);
267 cachedString = EscapeUtil.escapeHtml(indexedText).trim();
268 StringBuilder sb =
new StringBuilder(cachedString.length() + 20);
269 sb.append(
"<pre>").append(cachedString).append(
"</pre>");
270 cachedString = sb.toString();
271 cachedChunk = chunkId;
272 }
catch (NoOpenCoreException ex) {
273 logger.log(Level.SEVERE,
"No open core", ex);
279 private String getArtifactText() throws SolrServerException{
281 String indexedText = KeywordSearch.getServer().getSolrContent(this.objectId, 1);
282 indexedText = EscapeUtil.escapeHtml(indexedText).trim();
283 StringBuilder sb =
new StringBuilder(indexedText.length() + 20);
284 sb.append(
"<pre>").append(indexedText).append(
"</pre>");
285 return sb.toString();
286 }
catch (NoOpenCoreException ex) {
287 logger.log(Level.SEVERE,
"No open core", ex);