Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
KeywordSearchUtil.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.awt.Component;
22 import java.io.File;
23 import java.util.logging.Level;
25 import javax.swing.JOptionPane;
26 import org.openide.windows.WindowManager;
27 import org.sleuthkit.datamodel.AbstractFile;
28 import org.sleuthkit.datamodel.FsContent;
29 import org.sleuthkit.datamodel.TskException;
30 
31 class KeywordSearchUtil {
32 
33  public enum DIALOG_MESSAGE_TYPE {
34 
35  ERROR, WARN, INFO
36  };
37  private static final Logger logger = Logger.getLogger(KeywordSearchUtil.class.getName());
38 
46  public static String quoteQuery(String query) {
47  //ensure a single pair of quotes around the query
48  final int length = query.length();
49  if (length > 1 && query.charAt(0) == '"'
50  && query.charAt(length - 1) == '"') {
51  return query;
52  }
53 
54  StringBuilder sb = new StringBuilder();
55  sb.append("\"").append(query).append("\"");
56  return sb.toString();
57  }
58 
68  public static String escapeLuceneQuery(String query) {
69  String queryEscaped = null;
70  String inputString = query.trim();
71 
72  if (inputString.length() == 0) {
73  return inputString;
74  }
75 
76  final String ESCAPE_CHARS = "/+-&|!(){}[]^\"~*?:\\";
77  StringBuilder sb = new StringBuilder();
78  final int length = inputString.length();
79 
80  //see if the quoery is quoted
81  boolean quotedQuery = false;
82  if (length > 1 && inputString.charAt(0) == '"' && inputString.charAt(length - 1) == '"') {
83  quotedQuery = true;
84  }
85 
86  for (int i = 0; i < length; ++i) {
87  final char c = inputString.charAt(i);
88 
89  if (ESCAPE_CHARS.contains(Character.toString(c))) {
90  //escape if not outter quotes
91  if (quotedQuery == false || (i > 0 && i < length - 1)) {
92  sb.append("\\");
93  }
94  }
95  sb.append(c);
96  }
97  queryEscaped = inputString = sb.toString();
98 
99  return queryEscaped;
100  }
101 
102  public static void displayDialog(final String title, final String message, final DIALOG_MESSAGE_TYPE type) {
103  int messageType;
104  if (type == DIALOG_MESSAGE_TYPE.ERROR) {
105  messageType = JOptionPane.ERROR_MESSAGE;
106  } else if (type == DIALOG_MESSAGE_TYPE.WARN) {
107  messageType = JOptionPane.WARNING_MESSAGE;
108  } else {
109  messageType = JOptionPane.INFORMATION_MESSAGE;
110  }
111 
112  final Component parentComponent = WindowManager.getDefault().getMainWindow();
113  JOptionPane.showMessageDialog(
114  parentComponent,
115  message,
116  title,
117  messageType);
118  }
119 
120  public static boolean displayConfirmDialog(final String title, final String message, final DIALOG_MESSAGE_TYPE type) {
121  int messageType;
122  if (type == DIALOG_MESSAGE_TYPE.ERROR) {
123  messageType = JOptionPane.ERROR_MESSAGE;
124  } else if (type == DIALOG_MESSAGE_TYPE.WARN) {
125  messageType = JOptionPane.WARNING_MESSAGE;
126  } else {
127  messageType = JOptionPane.INFORMATION_MESSAGE;
128  }
129  if (JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION, messageType) == JOptionPane.YES_OPTION) {
130  return true;
131  } else {
132  return false;
133  }
134  }
135 
143  static boolean isXMLList(String absPath) {
144  //TODO: make this more robust, if necessary
145  return new File(absPath).getName().endsWith(".xml"); //NON-NLS
146  }
147 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

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.