Autopsy  3.1
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;
29 
30 class KeywordSearchUtil {
31 
32  public enum DIALOG_MESSAGE_TYPE {
33 
34  ERROR, WARN, INFO
35  };
36  private static final Logger logger = Logger.getLogger(KeywordSearchUtil.class.getName());
37 
38 
39 
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 
67  public static String escapeLuceneQuery(String query) {
68  String queryEscaped = null;
69  String inputString = query.trim();
70 
71  if (inputString.length() == 0) {
72  return inputString;
73  }
74 
75  final String ESCAPE_CHARS = "/+-&|!(){}[]^\"~*?:\\";
76  StringBuilder sb = new StringBuilder();
77  final int length = inputString.length();
78 
79  //see if the quoery is quoted
80  boolean quotedQuery = false;
81  if (length > 1 && inputString.charAt(0) == '"' && inputString.charAt(length - 1) == '"') {
82  quotedQuery = true;
83  }
84 
85  for (int i = 0; i < length; ++i) {
86  final char c = inputString.charAt(i);
87 
88  if (ESCAPE_CHARS.contains(Character.toString(c))) {
89  //escape if not outter quotes
90  if (quotedQuery == false || (i > 0 && i < length - 1)) {
91  sb.append("\\");
92  }
93  }
94  sb.append(c);
95  }
96  queryEscaped = inputString = sb.toString();
97 
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 = null; // Use default window frame.
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 
142  static boolean isXMLList(String absPath) {
143  //TODO: make this more robust, if necessary
144  return new File(absPath).getName().endsWith(".xml"); //NON-NLS
145  }
146 }
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.