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;
30 import org.openide.util.NbBundle;
32 import org.openide.nodes.Node;
33 import org.openide.util.lookup.ServiceProvider;
46 @ServiceProvider(service = DataContentViewer.class, position = 4)
50 private static final long INVALID_DOCUMENT_ID = 0L;
51 private ExtractedContentPanel
panel;
52 private volatile Node currentNode = null;
53 private IndexedText currentSource = null;
60 public void setNode(
final Node selectedNode) {
64 if (selectedNode == null) {
74 if (selectedNode == currentNode) {
77 currentNode = selectedNode;
86 final List<IndexedText> sources =
new ArrayList<>();
87 sources.addAll(selectedNode.getLookup().lookupAll(IndexedText.class));
93 long documentID = getDocumentId(currentNode);
94 if (INVALID_DOCUMENT_ID == documentID) {
98 IndexedText rawSource;
99 if (documentID > INVALID_DOCUMENT_ID) {
101 Content content = currentNode.getLookup().lookup(Content.class);
102 rawSource =
new RawText(content, content.getId());
105 BlackboardArtifact blackboardArtifact = currentNode.getLookup().lookup(BlackboardArtifact.class);
106 rawSource =
new RawText(blackboardArtifact, documentID);
108 currentSource = rawSource;
109 sources.add(rawSource);
115 int currentPage = currentSource.getCurrentPage();
116 if (currentPage == 0 && currentSource.hasNextPage()) {
117 currentSource.nextPage();
119 updatePageControls();
124 final IndexedText source = panel.getSelectedSource();
125 if (source == null || !source.isSearchable()) {
129 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(source.currentItem()));
135 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.getTitle");
140 return NbBundle.getMessage(this.getClass(),
"ExtractedContentViewer.toolTip");
151 panel =
new ExtractedContentPanel();
155 panel.addNextPageControlListener(
new NextPageActionListener());
163 setPanel(
new ArrayList<IndexedText>());
164 panel.resetDisplay();
166 currentSource = null;
181 Collection<? extends IndexedText> sources = node.getLookup().lookupAll(IndexedText.class);
182 if (sources.isEmpty() ==
false) {
190 long documentID = getDocumentId(node);
191 if (INVALID_DOCUMENT_ID == documentID) {
195 return solrHasContent(documentID);
200 BlackboardArtifact art = node.getLookup().lookup(BlackboardArtifact.class);
204 }
else if (art.getArtifactTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
219 panel.setSources(sources);
248 logger.log(Level.SEVERE,
"Error querying Solr server", ex);
270 BlackboardArtifact artifact = node.getLookup().lookup(BlackboardArtifact.class);
271 if (null != artifact) {
272 if (artifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_KEYWORD_HIT.getTypeID()) {
273 return artifact.getArtifactID();
277 BlackboardAttribute blackboardAttribute = artifact.getAttribute(
278 new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ASSOCIATED_ARTIFACT));
279 if (blackboardAttribute != null) {
280 return blackboardAttribute.getValueLong();
282 }
catch (TskCoreException ex) {
283 logger.log(Level.SEVERE,
"Error getting associated artifact attributes", ex);
294 Content content = node.getLookup().lookup(Content.class);
295 if (content != null) {
296 return content.getId();
309 IndexedText source = panel.getSelectedSource();
310 if (source == null) {
312 panel.updateControls(null);
315 final boolean hasNextItem = source.hasNextItem();
316 final boolean hasNextPage = source.hasNextPage();
318 if (hasNextItem || hasNextPage) {
322 indexVal = source.currentItem();
324 indexVal = source.nextItem();
328 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
331 panel.updateCurrentMatchDisplay(source.currentItem());
332 panel.updateTotaMatcheslDisplay(source.getNumberHits());
335 if (!source.hasNextItem() && !source.hasNextPage()) {
336 panel.enableNextMatchControl(
false);
338 if (source.hasPreviousItem() || source.hasPreviousPage()) {
339 panel.enablePrevMatchControl(
true);
349 IndexedText source = panel.getSelectedSource();
350 final boolean hasPreviousItem = source.hasPreviousItem();
351 final boolean hasPreviousPage = source.hasPreviousPage();
353 if (hasPreviousItem || hasPreviousPage) {
354 if (!hasPreviousItem) {
357 indexVal = source.currentItem();
359 indexVal = source.previousItem();
363 panel.scrollToAnchor(source.getAnchorPrefix() + Integer.toString(indexVal));
366 panel.updateCurrentMatchDisplay(source.currentItem());
367 panel.updateTotaMatcheslDisplay(source.getNumberHits());
370 if (!source.hasPreviousItem() && !source.hasPreviousPage()) {
371 panel.enablePrevMatchControl(
false);
373 if (source.hasNextItem() || source.hasNextPage()) {
374 panel.enableNextMatchControl(
true);
385 currentSource = panel.getSelectedSource();
387 if (currentSource == null) {
392 updatePageControls();
393 updateSearchControls();
399 panel.updateSearchControls(currentSource);
403 panel.updateControls(currentSource);
408 if (currentSource == null) {
409 panel.updateControls(null);
413 if (currentSource.hasNextPage()) {
414 currentSource.nextPage();
417 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
418 panel.refreshCurrentMarkup();
419 panel.setCursor(null);
422 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
428 if (!currentSource.hasNextPage()) {
429 panel.enableNextPageControl(
false);
431 if (currentSource.hasPreviousPage()) {
432 panel.enablePrevPageControl(
true);
435 updateSearchControls();
441 if (currentSource == null) {
442 panel.updateControls(null);
446 if (currentSource.hasPreviousPage()) {
447 currentSource.previousPage();
450 panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
451 panel.refreshCurrentMarkup();
452 panel.setCursor(null);
455 panel.updateCurrentPageDisplay(currentSource.getCurrentPage());
461 if (!currentSource.hasPreviousPage()) {
462 panel.enablePrevPageControl(
false);
464 if (currentSource.hasNextPage()) {
465 panel.enableNextPageControl(
true);
468 updateSearchControls();
473 class NextPageActionListener
implements ActionListener {
476 public void actionPerformed(ActionEvent e) {
static synchronized Server getServer()
boolean queryIsIndexed(long contentID)
synchronized static Logger getLogger(String name)