TSK-318 Hide special chars escaping from user in List search

- additionally, allow for user to add and search 2 identical keywords from the list, where one is regex and another is literal (escaped)
- add Regex column to result view that makes the like queries distinct
This commit is contained in:
adam-m 2012-01-19 17:20:38 -05:00
parent 91bdf52fe1
commit e061b4ec3b
13 changed files with 205 additions and 129 deletions

View File

@ -23,7 +23,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.Map; import java.util.List;
import org.openide.util.lookup.ServiceProvider; import org.openide.util.lookup.ServiceProvider;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer; import org.sleuthkit.autopsy.corecomponentinterfaces.DataExplorer;
import org.sleuthkit.autopsy.keywordsearch.KeywordSearch.QueryType; import org.sleuthkit.autopsy.keywordsearch.KeywordSearch.QueryType;
@ -74,7 +74,7 @@ public class KeywordSearchDataExplorer implements DataExplorer {
private void search() { private void search() {
KeywordSearchQueryManager man = null; KeywordSearchQueryManager man = null;
if (tc.isMultiwordQuery()) { if (tc.isMultiwordQuery()) {
final Map<String, Boolean> keywords = tc.getQueryList(); final List<Keyword> keywords = tc.getQueryList();
if (keywords.isEmpty()) { if (keywords.isEmpty()) {
KeywordSearchUtil.displayDialog("Keyword Search Error", "Keyword list is empty, please add at least one keyword to the list", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR); KeywordSearchUtil.displayDialog("Keyword Search Error", "Keyword list is empty, please add at least one keyword to the list", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.ERROR);
return; return;

View File

@ -20,7 +20,7 @@ package org.sleuthkit.autopsy.keywordsearch;
import java.awt.Component; import java.awt.Component;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Map; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableCellRenderer;
@ -264,7 +264,7 @@ public final class KeywordSearchHistoryTopComponent extends TopComponent impleme
} }
@Override @Override
public Map<String, Boolean> getQueryList() { public List<Keyword> getQueryList() {
return null; return null;
} }

View File

@ -416,7 +416,7 @@ public final class KeywordSearchListImportExportTopComponent extends TopComponen
} }
@Override @Override
public Map<String, Boolean> getQueryList() { public List<Keyword> getQueryList() {
return null; return null;
} }

View File

@ -167,19 +167,19 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
//some hardcoded keywords for testing //some hardcoded keywords for testing
//phone number //phone number
tableModel.addKeyword("\\d\\d\\d[\\.-]\\d\\d\\d[\\.-]\\d\\d\\d\\d", false); tableModel.addKeyword(new Keyword("\\d\\d\\d[\\.-]\\d\\d\\d[\\.-]\\d\\d\\d\\d", false));
tableModel.addKeyword("\\d{8,10}", false); tableModel.addKeyword(new Keyword("\\d{8,10}", false));
tableModel.addKeyword("phone|fax", false); tableModel.addKeyword(new Keyword("phone|fax", false));
//IP address //IP address
tableModel.addKeyword("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])", false); tableModel.addKeyword(new Keyword("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])", false));
//email //email
tableModel.addKeyword("[e\\-]{0,2}mail", false); tableModel.addKeyword(new Keyword("[e\\-]{0,2}mail", false));
tableModel.addKeyword("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}", false); tableModel.addKeyword(new Keyword("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}", false));
//URL //URL
tableModel.addKeyword("ftp|sftp|ssh|http|https|www", false); tableModel.addKeyword(new Keyword("ftp|sftp|ssh|http|https|www", false));
//escaped literal word \d\d\d //escaped literal word \d\d\d
tableModel.addKeyword("\\Q\\d\\d\\d\\E", false); tableModel.addKeyword(new Keyword("\\Q\\d\\d\\d\\E", false));
tableModel.addKeyword("\\d\\d\\d\\d", true); tableModel.addKeyword(new Keyword("\\d\\d\\d\\d", true));
} }
/** This method is called from within the constructor to /** This method is called from within the constructor to
@ -399,10 +399,11 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
String newWord = addWordField.getText().trim(); String newWord = addWordField.getText().trim();
boolean isLiteral = !chRegex.isSelected(); boolean isLiteral = !chRegex.isSelected();
final Keyword keyword = new Keyword(newWord, isLiteral);
if (newWord.equals("")) { if (newWord.equals("")) {
return; return;
} else if (keywordExists(newWord, isLiteral)) { } else if (keywordExists(keyword)) {
KeywordSearchUtil.displayDialog("New Keyword Entry", "Keyword already exists in the list.", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); KeywordSearchUtil.displayDialog("New Keyword Entry", "Keyword already exists in the list.", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
return; return;
} }
@ -423,7 +424,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
} }
//add & reset checkbox //add & reset checkbox
tableModel.addKeyword(newWord, isLiteral); tableModel.addKeyword(keyword);
chRegex.setSelected(false); chRegex.setSelected(false);
addWordField.setText(""); addWordField.setText("");
@ -445,7 +446,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
final String FEATURE_NAME = "Save Keyword List"; final String FEATURE_NAME = "Save Keyword List";
KeywordSearchListsXML writer = KeywordSearchListsXML.getCurrent(); KeywordSearchListsXML writer = KeywordSearchListsXML.getCurrent();
Map<String,Boolean> keywords = tableModel.getAllKeywords(); List<Keyword> keywords = tableModel.getAllKeywords();
if (keywords.isEmpty()) { if (keywords.isEmpty()) {
KeywordSearchUtil.displayDialog(FEATURE_NAME, "Keyword List is empty and cannot be saved", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO); KeywordSearchUtil.displayDialog(FEATURE_NAME, "Keyword List is empty and cannot be saved", KeywordSearchUtil.DIALOG_MESSAGE_TYPE.INFO);
return; return;
@ -714,7 +715,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
} }
@Override @Override
public Map<String, Boolean> getQueryList() { public List<Keyword> getQueryList() {
return getAllKeywords(); return getAllKeywords();
} }
@ -738,16 +739,16 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
} }
} }
public Map<String,Boolean> getAllKeywords() { List<Keyword> getAllKeywords() {
return tableModel.getAllKeywords(); return tableModel.getAllKeywords();
} }
public Map<String,Boolean> getSelectedKeywords() { List<Keyword> getSelectedKeywords() {
return tableModel.getSelectedKeywords(); return tableModel.getSelectedKeywords();
} }
private boolean keywordExists(String keyword, boolean isLiteral) { private boolean keywordExists(Keyword keyword) {
return tableModel.keywordExists(keyword, isLiteral); return tableModel.keywordExists(keyword);
} }
private class KeywordTableModel extends AbstractTableModel { private class KeywordTableModel extends AbstractTableModel {
@ -842,41 +843,40 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
return getValueAt(0, c).getClass(); return getValueAt(0, c).getClass();
} }
Map<String,Boolean> getAllKeywords() { List<Keyword> getAllKeywords() {
Map<String,Boolean> ret = new LinkedHashMap<String,Boolean>(); List<Keyword> ret = new ArrayList<Keyword>();
for (TableEntry e : keywordData) { for (TableEntry e : keywordData) {
ret.put(e.keyword, e.isLiteral); ret.add(new Keyword(e.keyword, e.isLiteral));
} }
return ret; return ret;
} }
Map<String,Boolean> getSelectedKeywords() { List<Keyword> getSelectedKeywords() {
Map<String,Boolean> ret = new LinkedHashMap<String,Boolean>(); List<Keyword> ret = new ArrayList<Keyword>();
for (TableEntry e : keywordData) { for (TableEntry e : keywordData) {
if (e.isActive && !e.keyword.equals("")) { if (e.isActive && !e.keyword.equals("")) {
ret.put(e.keyword, e.isLiteral); ret.add(new Keyword(e.keyword, e.isLiteral));
} }
} }
return ret; return ret;
} }
boolean keywordExists(String keyword, boolean isLiteral) { boolean keywordExists(Keyword keyword) {
Map<String,Boolean> all = getAllKeywords(); List<Keyword> all = getAllKeywords();
return all.containsKey(keyword) && all.get(keyword) == isLiteral; return all.contains(keyword);
} }
void addKeyword(String keyword, boolean isLiteral) { void addKeyword(Keyword keyword) {
if (!keywordExists(keyword, isLiteral)) { if (!keywordExists(keyword)) {
keywordData.add(new TableEntry(keyword, isLiteral)); keywordData.add(new TableEntry(keyword));
} }
fireTableDataChanged(); fireTableDataChanged();
} }
void addKeywords(Map<String,Boolean> keywords) { void addKeywords(List<Keyword> keywords) {
for (String keyword : keywords.keySet()) { for (Keyword keyword : keywords) {
boolean isLiteral = keywords.get(keyword); if (!keywordExists(keyword)) {
if (!keywordExists(keyword, isLiteral)) { keywordData.add(new TableEntry(keyword));
keywordData.add(new TableEntry(keyword, isLiteral));
} }
} }
fireTableDataChanged(); fireTableDataChanged();
@ -885,7 +885,7 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
void resync(String listName) { void resync(String listName) {
KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent(); KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent();
KeywordSearchList list = loader.getList(listName); KeywordSearchList list = loader.getList(listName);
Map<String,Boolean> keywords = list.getKeywords(); List<Keyword> keywords = list.getKeywords();
deleteAll(); deleteAll();
addKeywords(keywords); addKeywords(keywords);
@ -917,12 +917,18 @@ public final class KeywordSearchListTopComponent extends TopComponent implements
Boolean isLiteral; Boolean isLiteral;
Boolean isActive; Boolean isActive;
TableEntry(String keyword, Boolean isLiteral, Boolean isActive) { TableEntry(Keyword keyword, Boolean isActive) {
this.keyword = keyword; this.keyword = keyword.getQuery();
this.isLiteral = isLiteral; this.isLiteral = keyword.isLiteral();
this.isActive = isActive; this.isActive = isActive;
} }
TableEntry(Keyword keyword) {
this.keyword = keyword.getQuery();
this.isLiteral = keyword.isLiteral();
this.isActive = false;
}
TableEntry(String keyword, Boolean isLiteral) { TableEntry(String keyword, Boolean isLiteral) {
this.keyword = keyword; this.keyword = keyword;
this.isLiteral = isLiteral; this.isLiteral = isLiteral;

View File

@ -183,7 +183,7 @@ public class KeywordSearchListsXML {
* @param newList list of keywords * @param newList list of keywords
* @return true if old list was replaced * @return true if old list was replaced
*/ */
boolean addList(String name, Map<String,Boolean> newList) { boolean addList(String name, List<Keyword> newList) {
boolean replaced = false; boolean replaced = false;
KeywordSearchList curList = getList(name); KeywordSearchList curList = getList(name);
final Date now = new Date(); final Date now = new Date();
@ -265,18 +265,18 @@ public class KeywordSearchListsXML {
KeywordSearchList list = theLists.get(listName); KeywordSearchList list = theLists.get(listName);
String created = dateFormatter.format(list.getDateCreated()); String created = dateFormatter.format(list.getDateCreated());
String modified = dateFormatter.format(list.getDateModified()); String modified = dateFormatter.format(list.getDateModified());
Map<String,Boolean> keywords = list.getKeywords(); List<Keyword> keywords = list.getKeywords();
Element listEl = doc.createElement(LIST_EL); Element listEl = doc.createElement(LIST_EL);
listEl.setAttribute(LIST_NAME_ATTR, listName); listEl.setAttribute(LIST_NAME_ATTR, listName);
listEl.setAttribute(LIST_CREATE_ATTR, created); listEl.setAttribute(LIST_CREATE_ATTR, created);
listEl.setAttribute(LIST_MOD_ATTR, modified); listEl.setAttribute(LIST_MOD_ATTR, modified);
for (String keyword : keywords.keySet()) { for (Keyword keyword : keywords) {
Element keywordEl = doc.createElement(KEYWORD_EL); Element keywordEl = doc.createElement(KEYWORD_EL);
String regex = keywords.get(keyword)==true?"true":"false"; String regex = keyword.isLiteral()==false?"true":"false";
keywordEl.setAttribute(KEYWORD_LITERAL_ATTR, regex); keywordEl.setAttribute(KEYWORD_LITERAL_ATTR, regex);
keywordEl.setTextContent(keyword); keywordEl.setTextContent(keyword.getQuery());
listEl.appendChild(keywordEl); listEl.appendChild(keywordEl);
} }
rootEl.appendChild(listEl); rootEl.appendChild(listEl);
@ -313,7 +313,7 @@ public class KeywordSearchListsXML {
final String modified = listEl.getAttribute(LIST_MOD_ATTR); final String modified = listEl.getAttribute(LIST_MOD_ATTR);
Date createdDate = dateFormatter.parse(created); Date createdDate = dateFormatter.parse(created);
Date modDate = dateFormatter.parse(modified); Date modDate = dateFormatter.parse(modified);
Map<String,Boolean> words = new LinkedHashMap<String,Boolean>(); List<Keyword> words = new ArrayList<Keyword>();
KeywordSearchList list = new KeywordSearchList(name, createdDate, modDate, words); KeywordSearchList list = new KeywordSearchList(name, createdDate, modDate, words);
//parse all words //parse all words
@ -323,7 +323,7 @@ public class KeywordSearchListsXML {
Element wordEl = (Element) wordsNList.item(j); Element wordEl = (Element) wordsNList.item(j);
String regex = wordEl.getAttribute(KEYWORD_LITERAL_ATTR); String regex = wordEl.getAttribute(KEYWORD_LITERAL_ATTR);
boolean isRegex = regex.equals("true"); boolean isRegex = regex.equals("true");
words.put(wordEl.getTextContent(), isRegex); words.add(new Keyword(wordEl.getTextContent(), isRegex));
} }
theLists.put(name, list); theLists.put(name, list);
@ -410,9 +410,9 @@ class KeywordSearchList {
private String name; private String name;
private Date created; private Date created;
private Date modified; private Date modified;
private Map<String,Boolean> keywords; private List<Keyword> keywords;
KeywordSearchList(String name, Date created, Date modified, Map<String,Boolean> keywords) { KeywordSearchList(String name, Date created, Date modified, List<Keyword> keywords) {
this.name = name; this.name = name;
this.created = created; this.created = created;
this.modified = modified; this.modified = modified;
@ -452,7 +452,7 @@ class KeywordSearchList {
return modified; return modified;
} }
Map<String,Boolean> getKeywords() { List<Keyword> getKeywords() {
return keywords; return keywords;
} }
} }

View File

@ -49,6 +49,12 @@ public interface KeywordSearchQuery {
*/ */
public void escape(); public void escape();
/**
*
* @return true if query was escaped
*/
public boolean isEscaped();
/** /**
* return original query string * return original query string
* @return the query String supplied originally * @return the query String supplied originally

View File

@ -45,14 +45,14 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
COLLAPSE, DETAIL COLLAPSE, DETAIL
}; };
//map query->boolean (true if literal, false otherwise)
private Map<String, Boolean> queries; private List<Keyword> queries;
private Presentation presentation; private Presentation presentation;
private List<KeywordSearchQuery> queryDelegates; private List<KeywordSearchQuery> queryDelegates;
private QueryType queryType; private QueryType queryType;
private static Logger logger = Logger.getLogger(KeywordSearchQueryManager.class.getName()); private static Logger logger = Logger.getLogger(KeywordSearchQueryManager.class.getName());
public KeywordSearchQueryManager(Map<String, Boolean> queries, Presentation presentation) { public KeywordSearchQueryManager(List<Keyword> queries, Presentation presentation) {
this.queries = queries; this.queries = queries;
this.presentation = presentation; this.presentation = presentation;
queryType = QueryType.REGEX; queryType = QueryType.REGEX;
@ -60,16 +60,16 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
} }
public KeywordSearchQueryManager(String query, QueryType qt, Presentation presentation) { public KeywordSearchQueryManager(String query, QueryType qt, Presentation presentation) {
queries = new LinkedHashMap<String, Boolean>(); queries = new ArrayList<Keyword>();
queries.put(query, false); queries.add(new Keyword(query, false));
this.presentation = presentation; this.presentation = presentation;
queryType = qt; queryType = qt;
init(); init();
} }
public KeywordSearchQueryManager(String query, boolean isLiteral, Presentation presentation) { public KeywordSearchQueryManager(String query, boolean isLiteral, Presentation presentation) {
queries = new LinkedHashMap<String, Boolean>(); queries = new ArrayList<Keyword>();
queries.put(query, isLiteral); queries.add(new Keyword(query, isLiteral));
this.presentation = presentation; this.presentation = presentation;
queryType = QueryType.REGEX; queryType = QueryType.REGEX;
init(); init();
@ -77,22 +77,24 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
private void init() { private void init() {
queryDelegates = new ArrayList<KeywordSearchQuery>(); queryDelegates = new ArrayList<KeywordSearchQuery>();
for (String query : queries.keySet()) { for (Keyword query : queries) {
KeywordSearchQuery del = null; KeywordSearchQuery del = null;
switch (queryType) { switch (queryType) {
case WORD: case WORD:
del = new LuceneQuery(query); del = new LuceneQuery(query.getQuery());
break; break;
case REGEX: case REGEX:
del = new TermComponentQuery(query); del = new TermComponentQuery(query.getQuery());
break; break;
default: default:
; ;
} }
if (query.isLiteral())
del.escape();
queryDelegates.add(del); queryDelegates.add(del);
} }
escape(); //escape();
} }
@ -115,16 +117,17 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
} }
Node rootNode = null; Node rootNode = null;
if (things.size() > 0) { if (things.size() > 0) {
Children childThingNodes = Children childThingNodes =
Children.create(new KeywordSearchResultFactory(queries.keySet(), things, Presentation.COLLAPSE), true); Children.create(new KeywordSearchResultFactory(queries, things, Presentation.COLLAPSE), true);
rootNode = new AbstractNode(childThingNodes); rootNode = new AbstractNode(childThingNodes);
} else { } else {
rootNode = Node.EMPTY; rootNode = Node.EMPTY;
} }
final String pathText = "Keyword query"; final String pathText = "Keyword search";
TopComponent searchResultWin = DataResultTopComponent.createInstance("Keyword search", pathText, rootNode, things.size()); TopComponent searchResultWin = DataResultTopComponent.createInstance("Keyword search", pathText, rootNode, things.size());
searchResultWin.requestActive(); searchResultWin.requestActive();
} }
@ -132,13 +135,7 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
@Override @Override
public void escape() { public void escape() {
for (KeywordSearchQuery q : queryDelegates) {
boolean shouldEscape = queries.get(q.getQueryString());
if (shouldEscape) {
q.escape();
}
}
} }
@Override @Override
@ -169,6 +166,11 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
} }
return sb.toString(); return sb.toString();
} }
@Override
public boolean isEscaped() {
return false;
}
@Override @Override
public String getQueryString() { public String getQueryString() {
@ -186,7 +188,7 @@ public class KeywordSearchQueryManager implements KeywordSearchQuery {
} }
} }
/* /**
* custom KeyValueThing that also stores query object to execute * custom KeyValueThing that also stores query object to execute
*/ */
class KeyValueThingQuery extends KeyValueThing { class KeyValueThingQuery extends KeyValueThing {
@ -202,3 +204,47 @@ class KeyValueThingQuery extends KeyValueThing {
this.query = query; this.query = query;
} }
} }
/**
* representation of Keyword input from user
*/
class Keyword {
private String query;
private boolean isLiteral;
Keyword(String query, boolean isLiteral) {
this.query = query;
this.isLiteral = isLiteral;
}
String getQuery() {return query;}
boolean isLiteral() {return isLiteral;}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Keyword other = (Keyword) obj;
if ((this.query == null) ? (other.query != null) : !this.query.equals(other.query)) {
return false;
}
if (this.isLiteral != other.isLiteral) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 17 * hash + (this.query != null ? this.query.hashCode() : 0);
hash = 17 * hash + (this.isLiteral ? 1 : 0);
return hash;
}
}

View File

@ -58,11 +58,17 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
//these are merged with FsContentPropertyType defined properties //these are merged with FsContentPropertyType defined properties
public static enum CommonPropertyTypes { public static enum CommonPropertyTypes {
QUERY { KEYWORD {
@Override @Override
public String toString() { public String toString() {
return "Query"; return "Keyword";
}
},
REGEX {
@Override
public String toString() {
return "Regex";
} }
}, },
MATCH { MATCH {
@ -73,19 +79,19 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
} }
},} },}
private Presentation presentation; private Presentation presentation;
private Collection<String> queries; private List<Keyword> queries;
private Collection<KeyValueThing> things; private Collection<KeyValueThing> things;
private static final Logger logger = Logger.getLogger(KeywordSearchResultFactory.class.getName()); private static final Logger logger = Logger.getLogger(KeywordSearchResultFactory.class.getName());
KeywordSearchResultFactory(Collection<String> queries, Collection<KeyValueThing> things, Presentation presentation) { KeywordSearchResultFactory(List<Keyword> queries, Collection<KeyValueThing> things, Presentation presentation) {
this.queries = queries; this.queries = queries;
this.things = things; this.things = things;
this.presentation = presentation; this.presentation = presentation;
} }
KeywordSearchResultFactory(String query, Collection<KeyValueThing> things, Presentation presentation) { KeywordSearchResultFactory(String query, Collection<KeyValueThing> things, Presentation presentation) {
queries = new ArrayList<String>(); queries = new ArrayList<Keyword>();
queries.add(query); queries.add(new Keyword(query, false));
this.presentation = presentation; this.presentation = presentation;
this.things = things; this.things = things;
} }
@ -115,15 +121,21 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
final String typeStr = type.toString(); final String typeStr = type.toString();
toSet.put(typeStr, value); toSet.put(typeStr, value);
} }
public static void setCommonProperty(Map<String, Object> toSet, CommonPropertyTypes type, Boolean value) {
final String typeStr = type.toString();
toSet.put(typeStr, value);
}
@Override @Override
protected boolean createKeys(List<KeyValueThing> toPopulate) { protected boolean createKeys(List<KeyValueThing> toPopulate) {
int id = 0; int id = 0;
if (presentation == Presentation.DETAIL) { if (presentation == Presentation.DETAIL) {
for (String query : queries) { for (Keyword keyword : queries) {
Map<String, Object> map = new LinkedHashMap<String, Object>(); Map<String, Object> map = new LinkedHashMap<String, Object>();
final String query = keyword.getQuery();
initCommonProperties(map); initCommonProperties(map);
setCommonProperty(map, CommonPropertyTypes.QUERY, query); setCommonProperty(map, CommonPropertyTypes.KEYWORD, query);
setCommonProperty(map, CommonPropertyTypes.REGEX, Boolean.valueOf(!keyword.isLiteral()));
toPopulate.add(new KeyValueThing(query, map, ++id)); toPopulate.add(new KeyValueThing(query, map, ++id));
} }
} else { } else {
@ -132,7 +144,9 @@ public class KeywordSearchResultFactory extends ChildFactory<KeyValueThing> {
Map<String, Object> map = thing.getMap(); Map<String, Object> map = thing.getMap();
initCommonProperties(map); initCommonProperties(map);
final String query = thing.getName(); final String query = thing.getName();
setCommonProperty(map, CommonPropertyTypes.QUERY, query); setCommonProperty(map, CommonPropertyTypes.KEYWORD, query);
KeyValueThingQuery thingQuery = (KeyValueThingQuery) thing;
setCommonProperty(map, CommonPropertyTypes.REGEX, Boolean.valueOf(!thingQuery.getQuery().isEscaped()));
//toPopulate.add(new KeyValueThing(query, map, ++id)); //toPopulate.add(new KeyValueThing(query, map, ++id));
toPopulate.add(thing); toPopulate.add(thing);
} }

View File

@ -19,8 +19,7 @@
package org.sleuthkit.autopsy.keywordsearch; package org.sleuthkit.autopsy.keywordsearch;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Map; import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.openide.windows.TopComponent; import org.openide.windows.TopComponent;
@ -194,7 +193,7 @@ public class KeywordSearchSimpleTopComponent extends TopComponent implements Key
} }
@Override @Override
public Map<String, Boolean> getQueryList() { public List<Keyword> getQueryList() {
return null; return null;
} }

View File

@ -18,11 +18,10 @@
*/ */
package org.sleuthkit.autopsy.keywordsearch; package org.sleuthkit.autopsy.keywordsearch;
import java.awt.Component;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.Map; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.SolrServerException;
@ -146,7 +145,7 @@ public final class KeywordSearchTabsTopComponent extends TopComponent implements
} }
@Override @Override
public Map<String, Boolean> getQueryList() { public List<Keyword> getQueryList() {
KeywordSearchTopComponentInterface selected = (KeywordSearchTopComponentInterface) tabs.getSelectedComponent(); KeywordSearchTopComponentInterface selected = (KeywordSearchTopComponentInterface) tabs.getSelectedComponent();
if (selected == null) { if (selected == null) {
return null; return null;

View File

@ -19,20 +19,20 @@
package org.sleuthkit.autopsy.keywordsearch; package org.sleuthkit.autopsy.keywordsearch;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.Map; import java.util.List;
/** /**
* common methods for the KeywordSearch TCs / tabs * common methods for the KeywordSearch TCs / tabs
* *
*/ */
public interface KeywordSearchTopComponentInterface { interface KeywordSearchTopComponentInterface {
boolean isMultiwordQuery(); boolean isMultiwordQuery();
boolean isLuceneQuerySelected(); boolean isLuceneQuerySelected();
boolean isRegexQuerySelected(); boolean isRegexQuerySelected();
String getQueryText(); String getQueryText();
Map<String, Boolean> getQueryList(); List<Keyword> getQueryList();
void setFilesIndexed(int filesIndexed); void setFilesIndexed(int filesIndexed);
void addSearchButtonListener(ActionListener l); void addSearchButtonListener(ActionListener l);

View File

@ -59,6 +59,11 @@ public class LuceneQuery implements KeywordSearchQuery {
queryEscaped = KeywordSearchUtil.escapeLuceneQuery(query, true, false); queryEscaped = KeywordSearchUtil.escapeLuceneQuery(query, true, false);
isEscaped = true; isEscaped = true;
} }
@Override
public boolean isEscaped() {
return isEscaped;
}
@Override @Override
public String getEscapedQueryString() { public String getEscapedQueryString() {

View File

@ -49,7 +49,7 @@ import org.sleuthkit.autopsy.keywordsearch.KeywordSearchQueryManager.Presentatio
import org.sleuthkit.datamodel.FsContent; import org.sleuthkit.datamodel.FsContent;
public class TermComponentQuery implements KeywordSearchQuery { public class TermComponentQuery implements KeywordSearchQuery {
private static final int TERMS_UNLIMITED = -1; private static final int TERMS_UNLIMITED = -1;
//corresponds to field in Solr schema, analyzed with white-space tokenizer only //corresponds to field in Solr schema, analyzed with white-space tokenizer only
private static final String TERMS_SEARCH_FIELD = "content_ws"; private static final String TERMS_SEARCH_FIELD = "content_ws";
@ -60,30 +60,26 @@ public class TermComponentQuery implements KeywordSearchQuery {
private String queryEscaped; private String queryEscaped;
private boolean isEscaped; private boolean isEscaped;
private List<Term> terms; private List<Term> terms;
public TermComponentQuery(String query) { public TermComponentQuery(String query) {
this.termsQuery = query; this.termsQuery = query;
this.queryEscaped = query; this.queryEscaped = query;
isEscaped = false; isEscaped = false;
terms = null; terms = null;
} }
@Override @Override
public void escape() { public void escape() {
//treat as literal
//TODO for actual literal query to work in Java/Solr
//might need to either: use terms prefix (not regex) query with the literal
//or append .* to the literal regex
queryEscaped = Pattern.quote(termsQuery); queryEscaped = Pattern.quote(termsQuery);
isEscaped = true; isEscaped = true;
} }
@Override @Override
public boolean validate() { public boolean validate() {
if (queryEscaped.equals("")) { if (queryEscaped.equals("")) {
return false; return false;
} }
boolean valid = true; boolean valid = true;
try { try {
Pattern.compile(queryEscaped); Pattern.compile(queryEscaped);
@ -95,6 +91,11 @@ public class TermComponentQuery implements KeywordSearchQuery {
return valid; return valid;
} }
@Override
public boolean isEscaped() {
return isEscaped;
}
/* /*
* helper method to create a Solr terms component query * helper method to create a Solr terms component query
*/ */
@ -110,9 +111,9 @@ public class TermComponentQuery implements KeywordSearchQuery {
q.setTermsRegex(queryEscaped); q.setTermsRegex(queryEscaped);
q.addTermsField(TERMS_SEARCH_FIELD); q.addTermsField(TERMS_SEARCH_FIELD);
q.setTimeAllowed(TERMS_TIMEOUT); q.setTimeAllowed(TERMS_TIMEOUT);
return q; return q;
} }
/* /*
@ -120,7 +121,7 @@ public class TermComponentQuery implements KeywordSearchQuery {
*/ */
protected List<Term> executeQuery(SolrQuery q) { protected List<Term> executeQuery(SolrQuery q) {
Server.Core solrCore = KeywordSearch.getServer().getCore(); Server.Core solrCore = KeywordSearch.getServer().getCore();
List<Term> termsCol = null; List<Term> termsCol = null;
try { try {
TermsResponse tr = solrCore.queryTerms(q); TermsResponse tr = solrCore.queryTerms(q);
@ -131,17 +132,17 @@ public class TermComponentQuery implements KeywordSearchQuery {
return null; //no need to create result view, just display error dialog return null; //no need to create result view, just display error dialog
} }
} }
@Override @Override
public String getEscapedQueryString() { public String getEscapedQueryString() {
return this.queryEscaped; return this.queryEscaped;
} }
@Override @Override
public String getQueryString() { public String getQueryString() {
return this.termsQuery; return this.termsQuery;
} }
@Override @Override
public Collection<Term> getTerms() { public Collection<Term> getTerms() {
return terms; return terms;
@ -154,7 +155,7 @@ public class TermComponentQuery implements KeywordSearchQuery {
@Override @Override
public List<FsContent> performQuery() { public List<FsContent> performQuery() {
List<FsContent> results = new ArrayList<FsContent>(); List<FsContent> results = new ArrayList<FsContent>();
final SolrQuery q = createQuery(); final SolrQuery q = createQuery();
terms = executeQuery(q); terms = executeQuery(q);
@ -179,7 +180,7 @@ public class TermComponentQuery implements KeywordSearchQuery {
++curTerm; ++curTerm;
} }
List<FsContent> uniqueMatches = new ArrayList<FsContent>(); List<FsContent> uniqueMatches = new ArrayList<FsContent>();
if (!terms.isEmpty()) { if (!terms.isEmpty()) {
LuceneQuery filesQuery = new LuceneQuery(filesQueryB.toString()); LuceneQuery filesQuery = new LuceneQuery(filesQueryB.toString());
//filesQuery.escape(); //filesQuery.escape();
@ -206,18 +207,18 @@ public class TermComponentQuery implements KeywordSearchQuery {
} else { } else {
results.addAll(uniqueMatches); results.addAll(uniqueMatches);
} }
return results; return results;
} }
@Override @Override
public void execute() { public void execute() {
SolrQuery q = createQuery(); SolrQuery q = createQuery();
logger.log(Level.INFO, "Executing TermsComponent query: " + q.toString()); logger.log(Level.INFO, "Executing TermsComponent query: " + q.toString());
final SwingWorker worker = new TermsQueryWorker(q); final SwingWorker worker = new TermsQueryWorker(q);
worker.execute(); worker.execute();
} }
@ -227,9 +228,9 @@ public class TermComponentQuery implements KeywordSearchQuery {
* @param terms * @param terms
*/ */
private void publishNodes(List<Term> terms) { private void publishNodes(List<Term> terms) {
Collection<KeyValueThing> things = new ArrayList<KeyValueThing>(); Collection<KeyValueThing> things = new ArrayList<KeyValueThing>();
Iterator<Term> it = terms.iterator(); Iterator<Term> it = terms.iterator();
int termID = 0; int termID = 0;
//long totalMatches = 0; //long totalMatches = 0;
@ -243,17 +244,17 @@ public class TermComponentQuery implements KeywordSearchQuery {
things.add(new KeyValueThing(match, kvs, ++termID)); things.add(new KeyValueThing(match, kvs, ++termID));
//totalMatches += matches; //totalMatches += matches;
} }
Node rootNode = null; Node rootNode = null;
if (things.size() > 0) { if (things.size() > 0) {
Children childThingNodes = Children childThingNodes =
Children.create(new KeywordSearchResultFactory(termsQuery, things, Presentation.DETAIL), true); Children.create(new KeywordSearchResultFactory(termsQuery, things, Presentation.DETAIL), true);
rootNode = new AbstractNode(childThingNodes); rootNode = new AbstractNode(childThingNodes);
} else { } else {
rootNode = Node.EMPTY; rootNode = Node.EMPTY;
} }
final String pathText = "Term query"; final String pathText = "Term query";
// String pathText = "RegEx query: " + termsQuery // String pathText = "RegEx query: " + termsQuery
//+ " Files with exact matches: " + Long.toString(totalMatches) + " (also listing approximate matches)"; //+ " Files with exact matches: " + Long.toString(totalMatches) + " (also listing approximate matches)";
@ -262,29 +263,29 @@ public class TermComponentQuery implements KeywordSearchQuery {
searchResultWin.requestActive(); // make it the active top component searchResultWin.requestActive(); // make it the active top component
} }
class TermsQueryWorker extends SwingWorker<List<Term>, Void> { class TermsQueryWorker extends SwingWorker<List<Term>, Void> {
private SolrQuery q; private SolrQuery q;
private ProgressHandle progress; private ProgressHandle progress;
TermsQueryWorker(SolrQuery q) { TermsQueryWorker(SolrQuery q) {
this.q = q; this.q = q;
} }
@Override @Override
protected List<Term> doInBackground() throws Exception { protected List<Term> doInBackground() throws Exception {
progress = ProgressHandleFactory.createHandle("Terms query task"); progress = ProgressHandleFactory.createHandle("Terms query task");
progress.start(); progress.start();
progress.progress("Running Terms query."); progress.progress("Running Terms query.");
terms = executeQuery(q); terms = executeQuery(q);
progress.progress("Terms query completed."); progress.progress("Terms query completed.");
return terms; return terms;
} }
@Override @Override
protected void done() { protected void done() {
if (!this.isCancelled()) { if (!this.isCancelled()) {
@ -293,7 +294,7 @@ public class TermComponentQuery implements KeywordSearchQuery {
publishNodes(terms); publishNodes(terms);
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.log(Level.INFO, "Exception while executing regex query,", e); logger.log(Level.INFO, "Exception while executing regex query,", e);
} catch (ExecutionException e) { } catch (ExecutionException e) {
logger.log(Level.INFO, "Exception while executing regex query,", e); logger.log(Level.INFO, "Exception while executing regex query,", e);
} finally { } finally {