Autopsy  4.0
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-2015 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.util.logging.FileHandler;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import java.util.logging.SimpleFormatter;
29 import org.openide.util.NbBundle;
34 
39 public class KeywordSearch {
40 
41  private static Server server;
42  //we want a custom java.util.logging.Logger here for a reason
43  //a separate logger from framework logs
44  private static final Logger TIKA_LOGGER = Logger.getLogger("Tika"); //NON-NLS
46 
47  public enum QueryType {
48 
49  LITERAL, REGEX
50  };
51  public static final String NUM_FILES_CHANGE_EVT = "NUM_FILES_CHANGE_EVT"; //NON-NLS
52  private static PropertyChangeSupport changeSupport = new PropertyChangeSupport(KeywordSearch.class);
53 
60  public static synchronized Server getServer() {
61  if (server == null) {
62  server = new Server();
63  }
64  return server;
65  }
66 
67  static {
68  try {
69  final int MAX_TIKA_LOG_FILES = 3;
70  FileHandler tikaLogHandler = new FileHandler(PlatformUtil.getUserDirectory().getAbsolutePath() + "/var/log/tika.log", //NON-NLS
71  0, MAX_TIKA_LOG_FILES);
72  tikaLogHandler.setFormatter(new SimpleFormatter());
73  tikaLogHandler.setEncoding(PlatformUtil.getLogFileEncoding());
74  TIKA_LOGGER.addHandler(tikaLogHandler);
75  //do not forward to the parent autopsy logger
76  TIKA_LOGGER.setUseParentHandlers(false);
77  } catch (IOException | SecurityException ex) {
78  logger.log(Level.SEVERE, "Error setting up tika logging", ex); //NON-NLS
79  }
80  }
81 
82  // don't instantiate
83  private KeywordSearch() {
84  throw new AssertionError();
85  }
86 
87  static Logger getTikaLogger() {
88  return TIKA_LOGGER;
89  }
90 
91  public static void addNumIndexedFilesChangeListener(PropertyChangeListener l) {
92  changeSupport.addPropertyChangeListener(NUM_FILES_CHANGE_EVT, l);
93  }
94 
95  public static void removeNumIndexedFilesChangeListener(PropertyChangeListener l) {
96  changeSupport.removePropertyChangeListener(l);
97  }
98 
99  public static void fireNumIndexedFilesChange(Integer oldNum, Integer newNum) {
100 
101  try {
102  changeSupport.firePropertyChange(NUM_FILES_CHANGE_EVT, oldNum, newNum);
103  } catch (Exception e) {
104  logger.log(Level.SEVERE, "KeywordSearch listener threw exception", e); //NON-NLS
105  MessageNotifyUtil.Notify.show(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.moduleErr"),
106  NbBundle.getMessage(KeywordSearch.class,
107  "KeywordSearch.fireNumIdxFileChg.moduleErr.msg"),
109  }
110  }
111 
115  static class CaseChangeListener implements PropertyChangeListener {
116 
117  @Override
118  public void propertyChange(PropertyChangeEvent evt) {
119  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
120  if (null != evt.getOldValue()) {
121  Case closedCase = (Case) evt.getOldValue();
122  try {
123  BlackboardResultWriter.stopAllWriters();
124  Thread.sleep(2000); // TODO (RC): This is a fragile way to wait here.
125  server.closeCore();
126  } catch (Exception ex) {
127  String caseName = closedCase.getName();
128  logger.log(Level.SEVERE, String.format("Failed to close core for %s", caseName), ex); //NON-NLS
129  MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.closeCore.notification.msg"), ex.getMessage());
130  }
131  }
132  if (null != evt.getNewValue()) {
133  Case openedCase = (Case) evt.getNewValue();
134  try {
135  server.openCoreForCase(openedCase);
136  } catch (Exception ex) {
137  String caseName = openedCase.getName();
138  logger.log(Level.SEVERE, String.format("Failed to open or create core for %s", caseName), ex); //NON-NLS
139  MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.openCore.notification.msg"), ex.getMessage());
140  }
141  }
142  }
143  }
144  }
145 }
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:166
static void show(String title, String message, MessageType type, ActionListener actionListener)

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.