0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 package org.apache.hive.service.cli;
0020
0021 import org.apache.log4j.Layout;
0022 import org.apache.log4j.PatternLayout;
0023
0024
0025
0026
0027
0028 public class CLIServiceUtils {
0029
0030
0031 private static final char SEARCH_STRING_ESCAPE = '\\';
0032 public static final Layout verboseLayout = new PatternLayout(
0033 "%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n");
0034 public static final Layout nonVerboseLayout = new PatternLayout(
0035 "%-5p : %m%n");
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 public static String patternToRegex(String pattern) {
0046 if (pattern == null) {
0047 return ".*";
0048 } else {
0049 StringBuilder result = new StringBuilder(pattern.length());
0050
0051 boolean escaped = false;
0052 for (int i = 0, len = pattern.length(); i < len; i++) {
0053 char c = pattern.charAt(i);
0054 if (escaped) {
0055 if (c != SEARCH_STRING_ESCAPE) {
0056 escaped = false;
0057 }
0058 result.append(c);
0059 } else {
0060 if (c == SEARCH_STRING_ESCAPE) {
0061 escaped = true;
0062 continue;
0063 } else if (c == '%') {
0064 result.append(".*");
0065 } else if (c == '_') {
0066 result.append('.');
0067 } else {
0068 result.append(Character.toLowerCase(c));
0069 }
0070 }
0071 }
0072 return result.toString();
0073 }
0074 }
0075
0076 }