Autopsy  3.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 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.Logger;
27 import java.util.logging.SimpleFormatter;
28 import org.openide.util.Exceptions;
29 import org.openide.util.NbBundle;
34 import java.util.logging.Level;
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  public enum QueryType {
48  LITERAL, REGEX
49  };
50  public static final String NUM_FILES_CHANGE_EVT = "NUM_FILES_CHANGE_EVT"; //NON-NLS
51  private static PropertyChangeSupport changeSupport = new PropertyChangeSupport(KeywordSearch.class);
52 
59  public static synchronized Server getServer() {
60  if (server == null) {
61  server = new Server();
62  }
63  return server;
64  }
65 
66  static {
67  try {
68  final int MAX_TIKA_LOG_FILES = 3;
69  FileHandler tikaLogHandler = new FileHandler(PlatformUtil.getUserDirectory().getAbsolutePath() + "/var/log/tika.log", //NON-NLS
70  0, MAX_TIKA_LOG_FILES);
71  tikaLogHandler.setFormatter(new SimpleFormatter());
72  tikaLogHandler.setEncoding(PlatformUtil.getLogFileEncoding());
73  TIKA_LOGGER.addHandler(tikaLogHandler);
74  //do not forward to the parent autopsy logger
75  TIKA_LOGGER.setUseParentHandlers(false);
76  } catch (IOException ex) {
77  Exceptions.printStackTrace(ex);
78  } catch (SecurityException ex) {
79  Exceptions.printStackTrace(ex);
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 
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  }
106  catch (Exception e) {
107  logger.log(Level.SEVERE, "KeywordSearch listener threw exception", e); //NON-NLS
108  MessageNotifyUtil.Notify.show(NbBundle.getMessage(KeywordSearch.class, "KeywordSearch.moduleErr"),
109  NbBundle.getMessage(KeywordSearch.class,
110  "KeywordSearch.fireNumIdxFileChg.moduleErr.msg"),
112  }
113  }
114 
118  static class CaseChangeListener implements PropertyChangeListener {
119 
120  CaseChangeListener() {
121  }
122 
123  @Override
124  public void propertyChange(PropertyChangeEvent evt) {
125  String changed = evt.getPropertyName();
126  Object oldValue = evt.getOldValue();
127  Object newValue = evt.getNewValue();
128 
129  final Logger logger = Logger.getLogger(CaseChangeListener.class.getName());
130  if (changed.equals(Case.Events.CURRENT_CASE.toString())) {
131  if (newValue != null) {
132  // new case is open
133  try {
134  server.openCore();
135  } catch (Exception e) {
136  logger.log(Level.WARNING, "Could not open core."); //NON-NLS
137  }
138  } else if (oldValue != null) {
139  // a case was closed
140  try {
141  BlackboardResultWriter.stopAllWriters();
142  Thread.sleep(2000);
143  server.closeCore();
144  } catch (Exception e) {
145  logger.log(Level.WARNING, "Could not close core."); //NON-NLS
146  }
147  }
148  }
149  }
150  }
151 }
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)
static void show(String title, String message, MessageType type, ActionListener actionListener)
static Logger getLogger(String name)
Definition: Logger.java:131

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