19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.Component;
24 import javax.swing.JOptionPane;
25 import org.openide.windows.WindowManager;
27 class KeywordSearchUtil {
42 public static String quoteQuery(String query) {
44 final int length = query.length();
45 if (length > 1 && query.charAt(0) ==
'"'
46 && query.charAt(length - 1) ==
'"') {
50 return "\""+query+
"\"";
62 public static String escapeLuceneQuery(String query) {
63 String queryEscaped = null;
64 String inputString = query.trim();
66 if (inputString.length() == 0) {
70 final String ESCAPE_CHARS =
"/+-&|!(){}[]^\"~*?:\\";
71 StringBuilder sb =
new StringBuilder();
72 final int length = inputString.length();
75 boolean quotedQuery =
false;
76 if (length > 1 && inputString.charAt(0) ==
'"' && inputString.charAt(length - 1) ==
'"') {
80 for (
int i = 0; i < length; ++i) {
81 final char c = inputString.charAt(i);
83 if (ESCAPE_CHARS.contains(Character.toString(c))) {
85 if (quotedQuery ==
false || (i > 0 && i < length - 1)) {
91 queryEscaped = inputString = sb.toString();
96 public static void displayDialog(
final String title,
final String message,
final DIALOG_MESSAGE_TYPE type) {
98 if (type == DIALOG_MESSAGE_TYPE.ERROR) {
99 messageType = JOptionPane.ERROR_MESSAGE;
100 }
else if (type == DIALOG_MESSAGE_TYPE.WARN) {
101 messageType = JOptionPane.WARNING_MESSAGE;
103 messageType = JOptionPane.INFORMATION_MESSAGE;
106 final Component parentComponent = WindowManager.getDefault().getMainWindow();
107 JOptionPane.showMessageDialog(
114 public static boolean displayConfirmDialog(
final String title,
final String message,
final DIALOG_MESSAGE_TYPE type) {
116 if (type == DIALOG_MESSAGE_TYPE.ERROR) {
117 messageType = JOptionPane.ERROR_MESSAGE;
118 }
else if (type == DIALOG_MESSAGE_TYPE.WARN) {
119 messageType = JOptionPane.WARNING_MESSAGE;
121 messageType = JOptionPane.INFORMATION_MESSAGE;
123 if (JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), message, title, JOptionPane.YES_NO_OPTION, messageType) == JOptionPane.YES_OPTION) {
130 static KeywordSearchQuery getQueryForKeyword(Keyword keyword, KeywordList keywordList) {
131 KeywordSearchQuery query = null;
132 if (keyword.searchTermIsLiteral() && keyword.searchTermIsWholeWord()) {
134 query =
new LuceneQuery(keywordList, keyword);
138 query =
new RegexQuery(keywordList, keyword);
139 if (keyword.searchTermIsLiteral()) {
153 static boolean isXMLList(String absPath) {
155 return new File(absPath).getName().endsWith(
".xml");
synchronized static Logger getLogger(String name)