cleanup, remove useless methods and unneeded bundle messages, and unused fields

This commit is contained in:
millmanorama 2017-02-09 13:40:16 +01:00
parent 0d1d3f610c
commit 636eb11f27
3 changed files with 177 additions and 184 deletions

View File

@ -170,10 +170,6 @@ ExtractedContentViewer.hasPreviousItem.exception.msg=Not supported, not a search
ExtractedContentViewer.nextItem.exception.msg=Not supported, not a searchable source.
ExtractedContentViewer.previousItem.exception.msg=Not supported, not a searchable source.
ExtractedContentViewer.currentItem.exception.msg=Not supported, not a searchable source.
HighlightedMatchesSource.nextPage.exception.msg=No next page.
HighlightedMatchesSource.previousPage.exception.msg=No previous page.
HighlightedMatchesSource.nextItem.exception.msg=No next item.
HighlightedMatchesSource.previousItem.exception.msg=No previous item.
Ingester.ingest.exception.unknownImgId.msg=Skipping indexing the file, unknown image id, for file\: {0}
Ingester.ingest.exception.cantReadStream.msg=Could not read content stream\: {0}
Ingester.ingest.exception.err.msg=Error ingesting document\: {0}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2016 Basis Technology Corp.
* Copyright 2011-2017 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -96,76 +96,35 @@ public class ExtractedContentViewer implements DataContentViewer {
Lookup nodeLookup = node.getLookup();
Content content = nodeLookup.lookup(Content.class);
/*
* Assemble a collection of all of the indexed text "sources" associated
* with the node.
*/
List<IndexedText> sources = new ArrayList<>();
List<IndexedText> indexedTextSources = new ArrayList<>();
IndexedText highlightedHitText = null;
IndexedText rawContentText = null;
IndexedText rawArtifactText = null;
/*
* First add the text marked up with HTML to highlight keyword hits that
* will be present in the selected node's lookup if the node is for a
* keyword hit artifact or account.
*/
sources.addAll(nodeLookup.lookupAll(IndexedText.class));
indexedTextSources.addAll(nodeLookup.lookupAll(IndexedText.class));
if (!sources.isEmpty()) {
if (false == indexedTextSources.isEmpty()) {
//JMTODO: how do know the highlighted one is the first one? I think the assumption is really that it is the only one...
//if the look up had any sources use them and don't make a new one.
highlightedHitText = sources.get(0);
} else if (null != content && solrHasContent(content.getId())) {//if the lookup didn't have any sources, and solr has indexed the content...
highlightedHitText = indexedTextSources.get(0);
} else if (null != content && solrHasContent(content.getId())) {
/*
* get all the credit card artifacts and make a AccountsText object
* that will highlight them.
* if the lookup didn't have any sources, and solr has indexed the
* content,get an AccountsText object that will highlight any
* account numbers.
*/
String solrDocumentID = String.valueOf(content.getId()); //grab the object id as the solrDocumentID
Set<String> accountNumbers = new HashSet<>();
try {
//if the node had artifacts in the lookup use them, other wise look up all credit card artifacts for the content.
Collection<? extends BlackboardArtifact> artifacts = nodeLookup.lookupAll(BlackboardArtifact.class);
artifacts = (artifacts == null || artifacts.isEmpty())
? content.getArtifacts(TSK_ACCOUNT)
: artifacts;
/*
* For each artifact add the account number to the list of
* accountNumbers to highlight, and use the solrDocumentId
* attribute(in place of the content's object Id) if it exists
*
* NOTE: this assumes all the artifacts will be from the same
* solrDocumentId
*/
for (BlackboardArtifact artifact : artifacts) {
try {
BlackboardAttribute solrIDAttr = artifact.getAttribute(new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_DOCUMENT_ID));
if (solrIDAttr != null) {
String valueString = solrIDAttr.getValueString();
if (StringUtils.isNotBlank(valueString)) {
solrDocumentID = valueString;
}
}
BlackboardAttribute keyWordAttr = artifact.getAttribute(new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_CARD_NUMBER));
if (keyWordAttr != null) {
String valueString = keyWordAttr.getValueString();
if (StringUtils.isNotBlank(valueString)) {
accountNumbers.add(valueString);
}
}
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Failed to retrieve Blackboard Attributes", ex); //NON-NLS
}
}
if (accountNumbers.isEmpty() == false) {
highlightedHitText = new AccountsText(solrDocumentID, accountNumbers);
sources.add(highlightedHitText);
}
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Failed to retrieve Blackboard Artifacts", ex); //NON-NLS
highlightedHitText = getAccountsText(content, nodeLookup);
if (highlightedHitText != null) {
indexedTextSources.add(highlightedHitText);
}
}
@ -175,13 +134,40 @@ public class ExtractedContentViewer implements DataContentViewer {
*/
if (null != content && solrHasContent(content.getId())) {
rawContentText = new RawText(content, content.getId());
sources.add(rawContentText);
indexedTextSources.add(rawContentText);
}
/*
* Finally, add the "raw" (not highlighted) text, if any, for any
* artifact associated with the node.
*/
IndexedText rawArtifactText = getRawArtifactText(nodeLookup);
if (rawArtifactText != null) {
indexedTextSources.add(rawArtifactText);
}
// Now set the default source to be displayed.
if (null != highlightedHitText) {
currentSource = highlightedHitText;
} else if (null != rawContentText) {
currentSource = rawContentText;
} else {
currentSource = rawArtifactText;
}
//JMTODO: What is this supposed to do?
// Push the text sources into the panel.
for (IndexedText source : indexedTextSources) {
int currentPage = source.getCurrentPage();
if (currentPage == 0 && source.hasNextPage()) {
source.nextPage();
}
}
panel.updateControls(currentSource);
setPanel(indexedTextSources);
}
private IndexedText getRawArtifactText(Lookup nodeLookup) {
IndexedText rawArtifactText = null;
BlackboardArtifact artifact = nodeLookup.lookup(BlackboardArtifact.class);
if (null != artifact) {
/*
@ -195,36 +181,72 @@ public class ExtractedContentViewer implements DataContentViewer {
long artifactId = attribute.getValueLong();
BlackboardArtifact associatedArtifact = Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifact(artifactId);
rawArtifactText = new RawText(associatedArtifact, associatedArtifact.getArtifactID());
sources.add(rawArtifactText);
}
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Error getting associated artifact attributes", ex); //NON-NLS
}
} else {
rawArtifactText = new RawText(artifact, artifact.getArtifactID());
sources.add(rawArtifactText);
}
}
return rawArtifactText;
}
// Now set the default source to be displayed.
if (null != highlightedHitText) {
currentSource = highlightedHitText;
} else if (null != rawContentText) {
currentSource = rawContentText;
} else {
currentSource = rawArtifactText;
}
private IndexedText getAccountsText(Content content, Lookup nodeLookup) {
IndexedText highlightedHitText = null;
// Push the text sources into the panel.
for (IndexedText source : sources) {
int currentPage = source.getCurrentPage();
if (currentPage == 0 && source.hasNextPage()) {
source.nextPage();
/*
* get all the credit card artifacts
*/
String solrDocumentID = String.valueOf(content.getId()); //grab the object id as the solrDocumentID
Set<String> accountNumbers = new HashSet<>();
try {
//if the node had artifacts in the lookup use them, other wise look up all credit card artifacts for the content.
Collection<? extends BlackboardArtifact> artifacts = nodeLookup.lookupAll(BlackboardArtifact.class);
artifacts = (artifacts == null || artifacts.isEmpty())
? content.getArtifacts(TSK_ACCOUNT)
: artifacts;
/*
* For each artifact add the account number to the list of
* accountNumbers to highlight, and use the solrDocumentId
* attribute(in place of the content's object Id) if it exists
*
* NOTE: this assumes all the artifacts will be from the same
* solrDocumentId
*/
for (BlackboardArtifact artifact : artifacts) {
try {
BlackboardAttribute solrIDAttr = artifact.getAttribute(new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_KEYWORD_SEARCH_DOCUMENT_ID));
if (solrIDAttr != null) {
String valueString = solrIDAttr.getValueString();
if (StringUtils.isNotBlank(valueString)) {
solrDocumentID = valueString;
}
}
BlackboardAttribute keyWordAttr = artifact.getAttribute(new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_CARD_NUMBER));
if (keyWordAttr != null) {
String valueString = keyWordAttr.getValueString();
if (StringUtils.isNotBlank(valueString)) {
accountNumbers.add(valueString);
}
}
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Failed to retrieve Blackboard Attributes", ex); //NON-NLS
}
}
if (accountNumbers.isEmpty() == false) {
highlightedHitText = new AccountsText(solrDocumentID, accountNumbers);
}
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Failed to retrieve Blackboard Artifacts", ex); //NON-NLS
}
updatePageControls();
setPanel(sources);
return highlightedHitText;
}
private void scrollToCurrentHit() {
@ -420,7 +442,7 @@ public class ExtractedContentViewer implements DataContentViewer {
}
final boolean hasNextItem = source.hasNextItem();
final boolean hasNextPage = source.hasNextPage();
int indexVal = 0;
int indexVal;
if (hasNextItem || hasNextPage) {
if (!hasNextItem) {
//flip the page
@ -455,7 +477,7 @@ public class ExtractedContentViewer implements DataContentViewer {
IndexedText source = panel.getSelectedSource();
final boolean hasPreviousItem = source.hasPreviousItem();
final boolean hasPreviousPage = source.hasPreviousPage();
int indexVal = 0;
int indexVal;
if (hasPreviousItem || hasPreviousPage) {
if (!hasPreviousItem) {
//flip the page
@ -487,7 +509,6 @@ public class ExtractedContentViewer implements DataContentViewer {
@Override
public void actionPerformed(ActionEvent e) {
currentSource = panel.getSelectedSource();
if (currentSource == null) {
@ -495,20 +516,11 @@ public class ExtractedContentViewer implements DataContentViewer {
return;
}
updatePageControls();
updateSearchControls();
panel.updateControls(currentSource);
panel.updateSearchControls(currentSource);
}
}
private void updateSearchControls() {
panel.updateSearchControls(currentSource);
}
private void updatePageControls() {
panel.updateControls(currentSource);
}
private void nextPage() {
// we should never have gotten here -- reset
if (currentSource == null) {
@ -538,7 +550,7 @@ public class ExtractedContentViewer implements DataContentViewer {
panel.enablePrevPageControl(true);
}
updateSearchControls();
panel.updateSearchControls(currentSource);
}
}
@ -571,7 +583,7 @@ public class ExtractedContentViewer implements DataContentViewer {
panel.enableNextPageControl(true);
}
updateSearchControls();
panel.updateSearchControls(currentSource);
}
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2015 Basis Technology Corp.
* Copyright 2011-2017 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -27,14 +27,13 @@ import java.util.TreeSet;
import java.util.logging.Level;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
import org.sleuthkit.autopsy.coreutils.Version;
import org.sleuthkit.autopsy.datamodel.TextMarkupLookup;
@ -47,9 +46,10 @@ import org.sleuthkit.autopsy.keywordsearch.KeywordQueryFilter.FilterType;
class HighlightedText implements IndexedText, TextMarkupLookup {
private static final Logger logger = Logger.getLogger(HighlightedText.class.getName());
private static final String HIGHLIGHT_PRE = "<span style='background:yellow'>"; //NON-NLS
private static final String HIGHLIGHT_POST = "</span>"; //NON-NLS
private static final String ANCHOR_PREFIX = HighlightedText.class.getName() + "_";
private static final String ANCHOR_PREFIX = HighlightedText.class.getName() + "_"; //NON-NLS
private long objectId;
private String keywordHitQuery;
@ -57,52 +57,48 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
private int numberPages;
private int currentPage;
private boolean isRegex = false;
private boolean group = true;
private boolean hasChunks = false;
//stores all pages/chunks that have hits as key, and number of hits as a value, or 0 if yet unknown
private LinkedHashMap<Integer, Integer> hitsPages;
//stored page num -> current hit number mapping
private HashMap<Integer, Integer> pagesToHits;
/**
* stores all pages/chunks that have hits as key, and number of hits as a
* value, or 0 if yet unknown
*/
private LinkedHashMap<Integer, Integer> numberOfHitsPerPage;
/*stored page num -> current hit number mapping*/
private HashMap<Integer, Integer> currentHitPerPage;
private List<Integer> pages;
private QueryResults hits = null; //original hits that may get passed in
private String originalQuery = null; //or original query if hits are not available
private boolean isPageInfoLoaded = false;
private static final boolean DEBUG = (Version.getBuildType() == Version.Type.DEVELOPMENT);
HighlightedText(long objectId, String keywordHitQuery, boolean isRegex) {
/**
* This constructor is used when keyword hits are accessed from the "Keyword
* Hits" node in the directory tree in Autopsy. In that case we only have
* the keyword for which a hit had previously been found so we will need to
* re-query to find hits for the keyword.
*
* @param objectId
* @param keyword The keyword that was found previously (e.g. during
* ingest)
* @param isRegex true if the keyword was found via a regular
* expression search
* @param originalQuery The original query string that produced the hit. If
* isRegex is true, this will be the regular expression
* that produced the hit.
*/
HighlightedText(long objectId, String keyword, boolean isRegex) {
// The keyword can be treated as a literal hit at this point so we
// surround it in quotes.
this.objectId = objectId;
this.keywordHitQuery = keywordHitQuery;
this.keywordHitQuery = KeywordSearchUtil.quoteQuery(keyword);
this.isRegex = isRegex;
this.group = true;
this.hitsPages = new LinkedHashMap<>();
this.numberOfHitsPerPage = new LinkedHashMap<>();
this.pages = new ArrayList<>();
this.pagesToHits = new HashMap<>();
this.currentHitPerPage = new HashMap<>();
this.solrServer = KeywordSearch.getServer();
this.numberPages = 0;
this.currentPage = 0;
//hits are unknown
}
/**
* This constructor is used when keyword hits are accessed from the
* "Keyword Hits" node in the directory tree in Autopsy.
* In that case we only have the keyword for which a hit had
* previously been found so we will need to re-query to find hits
* for the keyword.
*
* @param objectId
* @param keyword The keyword that was found previously (e.g. during ingest)
* @param isRegex true if the keyword was found via a regular expression search
* @param originalQuery The original query string that produced the hit. If
* isRegex is true, this will be the regular expression that produced the hit.
*/
HighlightedText(long objectId, String keyword, boolean isRegex, String originalQuery) {
// The keyword can be treated as a literal hit at this point so we
// surround it in quotes.
this(objectId, KeywordSearchUtil.quoteQuery(keyword), isRegex);
this.originalQuery = originalQuery;
}
HighlightedText(long objectId, String solrQuery, boolean isRegex, QueryResults hits) {
@ -110,11 +106,6 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
this.hits = hits;
}
HighlightedText(long objectId, String solrQuery, boolean isRegex, boolean group, QueryResults hits) {
this(objectId, solrQuery, isRegex, hits);
this.group = group;
}
/**
* The main goal of this method is to figure out which pages / chunks have
* hits.
@ -124,13 +115,11 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
if (isPageInfoLoaded) {
return;
}
try {
this.numberPages = solrServer.queryNumFileChunks(this.objectId);
} catch (KeywordSearchModuleException ex) {
logger.log(Level.WARNING, "Could not get number pages for content: " + this.objectId); //NON-NLS
return;
} catch (NoOpenCoreException ex) {
logger.log(Level.WARNING, "Could not get number pages for content: " + this.objectId); //NON-NLS
} catch (KeywordSearchModuleException | NoOpenCoreException ex) {
logger.log(Level.WARNING, "Could not get number pages for content: {0}", this.objectId); //NON-NLS
return;
}
@ -182,35 +171,33 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
}
for (Integer page : pagesSorted) {
hitsPages.put(page, 0); //unknown number of matches in the page
numberOfHitsPerPage.put(page, 0); //unknown number of matches in the page
pages.add(page);
pagesToHits.put(page, 0); //set current hit to 0th
currentHitPerPage.put(page, 0); //set current hit to 0th
}
} else {
//no chunks
this.numberPages = 1;
this.currentPage = 1;
hitsPages.put(1, 0);
numberOfHitsPerPage.put(1, 0);
pages.add(1);
pagesToHits.put(1, 0);
currentHitPerPage.put(1, 0);
}
isPageInfoLoaded = true;
}
//constructor for dummy singleton factory instance for Lookup
/**
* Constructor for dummy singleton factory instance for Lookup
*/
private HighlightedText() {
}
long getObjectId() {
return this.objectId;
}
@Override
public int getNumberPages() {
return this.numberPages;
//return number of pages that have hits
//return this.hitsPages.keySet().size();
return this.numberPages;
}
@Override
@ -235,9 +222,8 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
@Override
public int nextPage() {
if (!hasNextPage()) {
throw new IllegalStateException(
NbBundle.getMessage(this.getClass(), "HighlightedMatchesSource.nextPage.exception.msg"));
if (false == hasNextPage()) {
throw new IllegalStateException("No next page.");
}
int idx = pages.indexOf(this.currentPage);
currentPage = pages.get(idx + 1);
@ -247,8 +233,7 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
@Override
public int previousPage() {
if (!hasPreviousPage()) {
throw new IllegalStateException(
NbBundle.getMessage(this.getClass(), "HighlightedMatchesSource.previousPage.exception.msg"));
throw new IllegalStateException("No previous page.");
}
int idx = pages.indexOf(this.currentPage);
currentPage = pages.get(idx - 1);
@ -257,53 +242,51 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
@Override
public boolean hasNextItem() {
if (!this.pagesToHits.containsKey(currentPage)) {
if (!this.currentHitPerPage.containsKey(currentPage)) {
return false;
}
return this.pagesToHits.get(currentPage) < this.hitsPages.get(currentPage);
return this.currentHitPerPage.get(currentPage) < this.numberOfHitsPerPage.get(currentPage);
}
@Override
public boolean hasPreviousItem() {
if (!this.pagesToHits.containsKey(currentPage)) {
if (!this.currentHitPerPage.containsKey(currentPage)) {
return false;
}
return this.pagesToHits.get(currentPage) > 1;
return this.currentHitPerPage.get(currentPage) > 1;
}
@Override
public int nextItem() {
if (!hasNextItem()) {
throw new IllegalStateException(
NbBundle.getMessage(this.getClass(), "HighlightedMatchesSource.nextItem.exception.msg"));
throw new IllegalStateException("No next item.");
}
int cur = pagesToHits.get(currentPage) + 1;
pagesToHits.put(currentPage, cur);
int cur = currentHitPerPage.get(currentPage) + 1;
currentHitPerPage.put(currentPage, cur);
return cur;
}
@Override
public int previousItem() {
if (!hasPreviousItem()) {
throw new IllegalStateException(
NbBundle.getMessage(this.getClass(), "HighlightedMatchesSource.previousItem.exception.msg"));
throw new IllegalStateException("No previous item.");
}
int cur = pagesToHits.get(currentPage) - 1;
pagesToHits.put(currentPage, cur);
int cur = currentHitPerPage.get(currentPage) - 1;
currentHitPerPage.put(currentPage, cur);
return cur;
}
@Override
public int currentItem() {
if (!this.pagesToHits.containsKey(currentPage)) {
if (!this.currentHitPerPage.containsKey(currentPage)) {
return 0;
}
return pagesToHits.get(currentPage);
return currentHitPerPage.get(currentPage);
}
@Override
public LinkedHashMap<Integer, Integer> getHitsPages() {
return this.hitsPages;
return this.numberOfHitsPerPage;
}
@Override
@ -388,23 +371,24 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
@Override
public int getNumberHits() {
if (!this.hitsPages.containsKey(this.currentPage)) {
if (!this.numberOfHitsPerPage.containsKey(this.currentPage)) {
return 0;
}
return this.hitsPages.get(this.currentPage);
return this.numberOfHitsPerPage.get(this.currentPage);
}
/**
* If the Solr query does not produce valid highlighting, we attempt to
* add the highlighting ourselves. We do this by taking the text returned
* from the document that contains a hit and searching that text for the
* keyword that produced the hit.
* If the Solr query does not produce valid highlighting, we attempt to add
* the highlighting ourselves. We do this by taking the text returned from
* the document that contains a hit and searching that text for the keyword
* that produced the hit.
*
* @param solrDocumentList The list of Solr documents returned in response
* to a Solr query. We expect there to only ever be a single document.
* to a Solr query. We expect there to only ever be
* a single document.
*
* @return Either a string with the keyword highlighted or a string
* indicating that we did not find a hit in the document.
* indicating that we did not find a hit in the document.
*/
private String attemptManualHighlighting(SolrDocumentList solrDocumentList) {
if (solrDocumentList.isEmpty()) {
@ -453,10 +437,11 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
}
/**
* Anchors are used to navigate back and forth between hits on the same
* page and to navigate to hits on the next/previous page.
* Anchors are used to navigate back and forth between hits on the same page
* and to navigate to hits on the next/previous page.
*
* @param searchableContent
*
* @return
*/
private String insertAnchors(String searchableContent) {
@ -479,7 +464,7 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
}
//store total hits for this page, now that we know it
this.hitsPages.put(this.currentPage, count);
this.numberOfHitsPerPage.put(this.currentPage, count);
if (this.currentItem() == 0 && this.hasNextItem()) {
this.nextItem();
}
@ -501,6 +486,6 @@ class HighlightedText implements IndexedText, TextMarkupLookup {
@Override
// factory method to create an instance of this object
public TextMarkupLookup createInstance(long objectId, String keywordHitQuery, boolean isRegex, String originalQuery) {
return new HighlightedText(objectId, keywordHitQuery, isRegex, originalQuery);
return new HighlightedText(objectId, keywordHitQuery, isRegex);
}
}