Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeywordSearchQueryDelegator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.keywordsearch;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25 import java.util.Map;
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;
33 
39 class KeywordSearchQueryDelegator {
40 
41  private List<KeywordList> keywordLists;
42  private List<KeywordSearchQuery> queryDelegates;
43  private static int resultWindowCount = 0; //keep track of unique window ids to display
44  private static Logger logger = Logger.getLogger(KeywordSearchQueryDelegator.class.getName());
45 
46  public KeywordSearchQueryDelegator(List<KeywordList> keywordLists) {
47  this.keywordLists = keywordLists;
48  init();
49  }
50 
51  private void init() {
52  // make a query for each keyword
53  queryDelegates = new ArrayList<>();
54 
55  for (KeywordList keywordList : keywordLists) {
56  for (Keyword keyword : keywordList.getKeywords()) {
57  KeywordSearchQuery query;
58  if (keyword.searchTermIsLiteral()) {
59  // literal, exact match
60  if (keyword.searchTermIsWholeWord()) {
61  query = new LuceneQuery(keywordList, keyword);
62  query.escape();
63  } // literal, substring match
64  else {
65  query = new TermsComponentQuery(keywordList, keyword);
66  query.escape();
67  query.setSubstringQuery();
68  }
69  } // regexp
70  else {
71  query = new TermsComponentQuery(keywordList, keyword);
72  }
73  queryDelegates.add(query);
74  }
75  }
76  }
77 
82  public void execute() {
83  Collection<QueryRequest> queryRequests = new ArrayList<>();
84  int queryID = 0;
85  StringBuilder queryConcat = new StringBuilder(); // concatenation of all query strings
86  for (KeywordSearchQuery q : queryDelegates) {
87  Map<String, Object> kvs = new LinkedHashMap<>();
88  final String queryStr = q.getQueryString();
89  queryConcat.append(queryStr).append(" ");
90  queryRequests.add(new QueryRequest(kvs, ++queryID, q));
91  }
92 
93  String queryConcatStr = queryConcat.toString();
94  final int queryConcatStrLen = queryConcatStr.length();
95  final String queryStrShort = queryConcatStrLen > 15 ? queryConcatStr.substring(0, 14) + "..." : queryConcatStr;
96  final String windowTitle = NbBundle.getMessage(this.getClass(), "KeywordSearchQueryManager.execute.exeWinTitle", ++resultWindowCount, queryStrShort);
97  DataResultTopComponent searchResultWin = DataResultTopComponent.createInstance(windowTitle);
98 
99  Node rootNode;
100  if (queryRequests.size() > 0) {
101  Children childNodes =
102  Children.create(new KeywordSearchResultFactory(queryRequests, searchResultWin), true);
103 
104  rootNode = new AbstractNode(childNodes);
105  } else {
106  rootNode = Node.EMPTY;
107  }
108 
109  final String pathText = NbBundle.getMessage(this.getClass(), "KeywordSearchQueryManager.pathText.text");
110 
111  DataResultTopComponent.initInstance(pathText, rootNode, queryRequests.size(), searchResultWin);
112 
113  searchResultWin.requestActive();
114  }
115 
121  public boolean validate() {
122  boolean allValid = true;
123  for (KeywordSearchQuery tcq : queryDelegates) {
124  if (!tcq.validate()) {
125  logger.log(Level.WARNING, "Query has invalid syntax: {0}", tcq.getQueryString()); //NON-NLS
126  allValid = false;
127  break;
128  }
129  }
130  return allValid;
131  }
132 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.