Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeywordSearch.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.beans.PropertyChangeSupport;
24 import java.io.IOException;
25 import java.nio.file.Paths;
26 import java.util.logging.FileHandler;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import java.util.logging.SimpleFormatter;
30 import org.openide.util.NbBundle;
36 
41 public class KeywordSearch {
42 
43  private static Server server;
44  //we want a custom java.util.logging.Logger here for a reason
45  //a separate logger from framework logs
46  private static final Logger TIKA_LOGGER = Logger.getLogger("Tika"); //NON-NLS
48 
49  public enum QueryType {
50 
51  LITERAL, REGEX
52  };
53  public static final String NUM_FILES_CHANGE_EVT = "NUM_FILES_CHANGE_EVT"; //NON-NLS
54  private static PropertyChangeSupport changeSupport = new PropertyChangeSupport(KeywordSearch.class);
55 
62  public static synchronized Server getServer() {
63  if (server == null) {
64  server = new Server();
65  }
66  return server;
67  }
68 
69  static {
70  try {
71  final int MAX_TIKA_LOG_FILES = 3;
72  FileHandler tikaLogHandler = new FileHandler(PlatformUtil.getUserDirectory().getAbsolutePath() + "/var/log/tika.log", //NON-NLS
73  0, MAX_TIKA_LOG_FILES);
74  tikaLogHandler.setFormatter(new SimpleFormatter());
75  tikaLogHandler.setEncoding(PlatformUtil.getLogFileEncoding());
76  TIKA_LOGGER.addHandler(tikaLogHandler);
77  //do not forward to the parent autopsy logger
78  TIKA_LOGGER.setUseParentHandlers(false);
79  } catch (IOException | SecurityException ex) {
80  logger.log(Level.SEVERE, "Error setting up tika logging", ex); //NON-NLS
81  }
82  }
83 
84  // don't instantiate
85  private KeywordSearch() {
86  throw new AssertionError();
87  }
88 
89  static Logger getTikaLogger() {
90  return TIKA_LOGGER;
91  }
92 
93  public static void addNumIndexedFilesChangeListener(PropertyChangeListener l) {
94  changeSupport.addPropertyChangeListener(NUM_FILES_CHANGE_EVT, l);
95  }
96 
97  public static void removeNumIndexedFilesChangeListener(PropertyChangeListener l) {
98  changeSupport.removePropertyChangeListener(l);
99  }
100 
101  public static void fireNumIndexedFilesChange(Integer oldNum, Integer newNum) {
102 
103  try {
104  changeSupport.firePropertyChange(NUM_FILES_CHANGE_EVT, oldNum, newNum);
105  } catch (Exception e) {
106  logger.log(Level.SEVERE, "KeywordSearch listener threw exception", e); //NON-NLS
107  MessageNotifyUtil.Notify.show(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.moduleErr"),
108  NbBundle.getMessage(KeywordSearch.class,
109  "KeywordSearch.fireNumIdxFileChg.moduleErr.msg"),
111  }
112  }
113 
118  static class CaseChangeListener implements PropertyChangeListener {
119 
120  @Override
121  public void propertyChange(PropertyChangeEvent evt) {
122  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
123  if (null != evt.getOldValue()) {
124  /*
125  * A case is being closed.
126  */
127  Case closedCase = (Case) evt.getOldValue();
128  try {
129  BlackboardResultWriter.stopAllWriters();
130  /*
131  * TODO (AUT-2084): The following code
132  * KeywordSearch.CaseChangeListener gambles that any
133  * BlackboardResultWriters (SwingWorkers) will complete
134  * in less than roughly two seconds
135  */
136  Thread.sleep(2000);
137  server.closeCore();
138  } catch (Exception ex) {
139  String caseId = Paths.get(closedCase.getCaseDirectory(), closedCase.getName()).toString();
140  logger.log(Level.SEVERE, String.format("Failed to close core for %s", caseId), ex); //NON-NLS
141  if (RuntimeProperties.coreComponentsAreActive()) {
142  MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.closeCore.notification.msg"), ex.getMessage());
143  }
144  }
145  }
146 
147  if (null != evt.getNewValue()) {
148  /*
149  * A case is being created/opened.
150  */
151  Case openedCase = (Case) evt.getNewValue();
152  try {
153  server.openCoreForCase(openedCase);
154  } catch (Exception ex) {
155  String caseId = Paths.get(openedCase.getCaseDirectory(), openedCase.getName()).toString();
156  logger.log(Level.SEVERE, String.format("Failed to open or create core for %s", caseId), ex); //NON-NLS
157  if (RuntimeProperties.coreComponentsAreActive()) {
158  MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.openCore.notification.msg"), ex.getMessage());
159  }
160  }
161  }
162  }
163  }
164  }
165 }
static final org.sleuthkit.autopsy.coreutils.Logger logger
static void fireNumIndexedFilesChange(Integer oldNum, Integer newNum)
static void addNumIndexedFilesChangeListener(PropertyChangeListener l)
static void removeNumIndexedFilesChangeListener(PropertyChangeListener l)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
static void show(String title, String message, MessageType type, ActionListener actionListener)

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.