19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.Component;
23 import java.util.logging.Level;
25 import javax.swing.JOptionPane;
26 import org.openide.windows.WindowManager;
31 class KeywordSearchUtil {
46 public static String quoteQuery(String query) {
48 final int length = query.length();
49 if (length > 1 && query.charAt(0) ==
'"'
50 && query.charAt(length - 1) ==
'"') {
54 StringBuilder sb =
new StringBuilder();
55 sb.append(
"\"").append(query).append(
"\"");
68 public static String escapeLuceneQuery(String query) {
69 String queryEscaped = null;
70 String inputString = query.trim();
72 if (inputString.length() == 0) {
76 final String ESCAPE_CHARS =
"/+-&|!(){}[]^\"~*?:\\";
77 StringBuilder sb =
new StringBuilder();
78 final int length = inputString.length();
81 boolean quotedQuery =
false;
82 if (length > 1 && inputString.charAt(0) ==
'"' && inputString.charAt(length - 1) ==
'"') {
86 for (
int i = 0; i < length; ++i) {
87 final char c = inputString.charAt(i);
89 if (ESCAPE_CHARS.contains(Character.toString(c))) {
91 if (quotedQuery ==
false || (i > 0 && i < length - 1)) {
97 queryEscaped = inputString = sb.toString();
102 public static void displayDialog(
final String title,
final String message,
final DIALOG_MESSAGE_TYPE type) {
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;
109 messageType = JOptionPane.INFORMATION_MESSAGE;
112 final Component parentComponent = WindowManager.getDefault().getMainWindow();
113 JOptionPane.showMessageDialog(
120 public static boolean displayConfirmDialog(
final String title,
final String message,
final DIALOG_MESSAGE_TYPE type) {
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;
127 messageType = JOptionPane.INFORMATION_MESSAGE;
129 if (JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION, messageType) == JOptionPane.YES_OPTION) {
143 static boolean isXMLList(String absPath) {
145 return new File(absPath).getName().endsWith(
".xml");
synchronized static Logger getLogger(String name)