19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.LinkedHashMap;
24 import java.util.List;
26 import java.util.logging.Level;
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Node;
30 import org.openide.util.NbBundle;
40 class KeywordSearchQueryDelegator {
42 private List<KeywordList> keywordLists;
43 private List<KeywordSearchQuery> queryDelegates;
44 private static int resultWindowCount = 0;
45 private static Logger logger = Logger.
getLogger(KeywordSearchQueryDelegator.class.getName());
47 public KeywordSearchQueryDelegator(List<KeywordList> keywordLists) {
48 this.keywordLists = keywordLists;
54 queryDelegates =
new ArrayList<>();
56 for (KeywordList keywordList : keywordLists) {
57 for (Keyword keyword : keywordList.getKeywords()) {
58 KeywordSearchQuery query = KeywordSearchUtil.getQueryForKeyword(keyword, keywordList);
59 queryDelegates.add(query);
68 public void execute() {
69 Collection<QueryRequest> queryRequests =
new ArrayList<>();
71 StringBuilder queryConcat =
new StringBuilder();
72 for (KeywordSearchQuery q : queryDelegates) {
73 Map<String, Object> kvs =
new LinkedHashMap<>();
74 final String queryStr = q.getQueryString();
75 queryConcat.append(queryStr).append(
" ");
76 queryRequests.add(
new QueryRequest(kvs, ++queryID, q));
79 String queryConcatStr = queryConcat.toString();
80 final int queryConcatStrLen = queryConcatStr.length();
81 final String queryStrShort = queryConcatStrLen > 15 ? queryConcatStr.substring(0, 14) +
"..." : queryConcatStr;
82 final String windowTitle = NbBundle.getMessage(this.getClass(),
"KeywordSearchQueryManager.execute.exeWinTitle", ++resultWindowCount, queryStrShort);
83 DataResultTopComponent searchResultWin = DataResultTopComponent.createInstance(windowTitle);
86 if (queryRequests.size() > 0) {
88 Children.create(
new KeywordSearchResultFactory(queryRequests),
true);
90 rootNode =
new AbstractNode(childNodes);
92 rootNode = Node.EMPTY;
95 final String pathText = NbBundle.getMessage(this.getClass(),
"KeywordSearchQueryManager.pathText.text");
97 DataResultTopComponent.initInstance(pathText,
new TableFilterNode(rootNode,
true, KeywordSearch.class.getName()),
98 queryRequests.size(), searchResultWin);
100 searchResultWin.requestActive();
108 public boolean validate() {
109 boolean allValid =
true;
110 for (KeywordSearchQuery tcq : queryDelegates) {
111 if (!tcq.validate()) {
112 logger.log(Level.WARNING,
"Query has invalid syntax: {0}", tcq.getQueryString());
synchronized static Logger getLogger(String name)