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.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;
35 
40 public class KeywordSearch {
41 
42  private static Server server;
43  //we want a custom java.util.logging.Logger here for a reason
44  //a separate logger from framework logs
45  private static final Logger TIKA_LOGGER = Logger.getLogger("Tika"); //NON-NLS
47 
48  public enum QueryType {
49 
50  LITERAL, REGEX
51  };
52  public static final String NUM_FILES_CHANGE_EVT = "NUM_FILES_CHANGE_EVT"; //NON-NLS
53  private static PropertyChangeSupport changeSupport = new PropertyChangeSupport(KeywordSearch.class);
54 
61  public static synchronized Server getServer() {
62  if (server == null) {
63  server = new Server();
64  }
65  return server;
66  }
67 
68  static {
69  try {
70  final int MAX_TIKA_LOG_FILES = 3;
71  FileHandler tikaLogHandler = new FileHandler(PlatformUtil.getUserDirectory().getAbsolutePath() + "/var/log/tika.log", //NON-NLS
72  0, MAX_TIKA_LOG_FILES);
73  tikaLogHandler.setFormatter(new SimpleFormatter());
74  tikaLogHandler.setEncoding(PlatformUtil.getLogFileEncoding());
75  TIKA_LOGGER.addHandler(tikaLogHandler);
76  //do not forward to the parent autopsy logger
77  TIKA_LOGGER.setUseParentHandlers(false);
78  } catch (IOException | SecurityException ex) {
79  logger.log(Level.SEVERE, "Error setting up tika logging", ex); //NON-NLS
80  }
81  }
82 
83  // don't instantiate
84  private KeywordSearch() {
85  throw new AssertionError();
86  }
87 
88  static Logger getTikaLogger() {
89  return TIKA_LOGGER;
90  }
91 
92  public static void addNumIndexedFilesChangeListener(PropertyChangeListener l) {
93  changeSupport.addPropertyChangeListener(NUM_FILES_CHANGE_EVT, l);
94  }
95 
96  public static void removeNumIndexedFilesChangeListener(PropertyChangeListener l) {
97  changeSupport.removePropertyChangeListener(l);
98  }
99 
100  public static void fireNumIndexedFilesChange(Integer oldNum, Integer newNum) {
101 
102  try {
103  changeSupport.firePropertyChange(NUM_FILES_CHANGE_EVT, oldNum, newNum);
104  } catch (Exception e) {
105  logger.log(Level.SEVERE, "KeywordSearch listener threw exception", e); //NON-NLS
106  MessageNotifyUtil.Notify.show(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.moduleErr"),
107  NbBundle.getMessage(KeywordSearch.class,
108  "KeywordSearch.fireNumIdxFileChg.moduleErr.msg"),
110  }
111  }
112 
117  static class CaseChangeListener implements PropertyChangeListener {
118 
119  @Override
120  public void propertyChange(PropertyChangeEvent evt) {
121  if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
122  if (null != evt.getOldValue()) {
123  /*
124  * A case is being closed.
125  */
126  Case closedCase = (Case) evt.getOldValue();
127  try {
128  BlackboardResultWriter.stopAllWriters();
129  /*
130  * TODO (AUT-2084): The following code
131  * KeywordSearch.CaseChangeListener gambles that any
132  * BlackboardResultWriters (SwingWorkers) will complete
133  * in less than roughly two seconds
134  */
135  Thread.sleep(2000);
136  server.closeCore();
137  } catch (Exception ex) {
138  logger.log(Level.SEVERE, String.format("Failed to close core for %s", closedCase.getCaseDirectory()), ex); //NON-NLS
139  if (RuntimeProperties.coreComponentsAreActive()) {
140  MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.closeCore.notification.msg"), ex.getMessage());
141  }
142  }
143  }
144 
145  if (null != evt.getNewValue()) {
146  /*
147  * A case is being created/opened.
148  */
149  Case openedCase = (Case) evt.getNewValue();
150  try {
151  server.openCoreForCase(openedCase);
152  } catch (Exception ex) {
153  logger.log(Level.SEVERE, String.format("Failed to open or create core for %s", openedCase.getCaseDirectory()), ex); //NON-NLS
154  if (RuntimeProperties.coreComponentsAreActive()) {
155  MessageNotifyUtil.Notify.error(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.openCore.notification.msg"), ex.getMessage());
156  }
157  }
158  }
159  }
160  }
161  }
162 }
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: Mon Jan 2 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.