Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AdHocSearchDelegator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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;
34 
40 class AdHocSearchDelegator {
41 
42  private final List<KeywordList> keywordLists;
43  private List<KeywordSearchQuery> queryDelegates;
44  private static int resultWindowCount = 0; //keep track of unique window ids to display
45  private static final Logger logger = Logger.getLogger(AdHocSearchDelegator.class.getName());
46 
47  public AdHocSearchDelegator(List<KeywordList> keywordLists) {
48  this.keywordLists = keywordLists;
49  init();
50  }
51 
52  private void init() {
53  // make a query for each keyword
54  queryDelegates = new ArrayList<>();
55 
56  for (KeywordList keywordList : keywordLists) {
57  for (Keyword keyword : keywordList.getKeywords()) {
58  KeywordSearchQuery query = KeywordSearchUtil.getQueryForKeyword(keyword, keywordList);
59  queryDelegates.add(query);
60  }
61  }
62  }
63 
68  public void execute() {
69  Collection<AdHocQueryRequest> queryRequests = new ArrayList<>();
70  int queryID = 0;
71  StringBuilder queryConcat = new StringBuilder(); // concatenation of all query strings
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 AdHocQueryRequest(kvs, ++queryID, q));
77  }
78 
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);
84 
85  Node rootNode;
86  if (queryRequests.size() > 0) {
87  Children childNodes =
88  Children.create(new AdHocSearchChildFactory(queryRequests), true);
89 
90  rootNode = new AbstractNode(childNodes);
91  } else {
92  rootNode = Node.EMPTY;
93  }
94 
95  final String pathText = NbBundle.getMessage(this.getClass(), "KeywordSearchQueryManager.pathText.text");
96 
97  DataResultTopComponent.initInstance(pathText, new TableFilterNode(rootNode, true, KeywordSearch.class.getName()),
98  queryRequests.size(), searchResultWin);
99 
100  searchResultWin.requestActive();
101  }
102 
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()); //NON-NLS
113  allValid = false;
114  break;
115  }
116  }
117  return allValid;
118  }
119 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.