1 36 37 package rero.ircfw; 38 39 import rero.ircfw.interfaces.FrameworkConstants; 40 41 import java.util.regex.Pattern ; 42 import java.util.HashMap ; 43 import rero.util.StringParser; 44 45 public class Parsed1459 implements FrameworkConstants 46 { 47 protected static String nickPattern = "(.+?)"; 58 protected static String userPattern = "(.+?)"; 59 protected static String hostPattern2 = "(.+?)"; 60 61 protected static String hostPattern = "([\\w\\-\\=]++[[\\.|\\:][\\w\\-\\=]++]*)"; 62 protected static String channelPattern = "([\\#|\\&]\\S++)"; 63 64 66 protected static Pattern isHost = Pattern.compile(hostPattern); 67 protected static Pattern isNickUserHost = Pattern.compile(nickPattern+"!("+userPattern+"@"+hostPattern2+")"); protected static Pattern isNick = Pattern.compile(nickPattern); 69 70 protected static Pattern isNumeric = Pattern.compile("\\d++"); 71 protected static Pattern isColonPresent = Pattern.compile(":(.++)"); 72 protected static Pattern isWhiteSpace = Pattern.compile("XXX"); 73 74 protected HashMap eventInformation; 75 76 public HashMap parseString (String data) 77 { 78 eventInformation = new HashMap (); 79 80 eventInformation.put($RAW$, data); 81 82 phase1(data, eventInformation); 83 84 return eventInformation; 85 } 86 87 private HashMap phase1 (String data, HashMap eventInformation) 92 { 93 StringParser parser; 94 95 parser = new StringParser(data, isColonPresent); 96 if (parser.matches()) 97 { 98 100 String [] text = parser.getParsedString(0).split("\\s", 2); 101 102 parseSourceInformation(text[0], eventInformation); 103 104 data = text[1]; 105 } 106 107 String text[] = data.split("\\s", 2); 109 110 if (isNumeric.matcher(text[0]).matches()) 111 { 112 eventInformation.put($NUMERIC$, text[0]); 113 } 114 115 eventInformation.put($EVENT$, text[0]); 116 117 if (text.length > 1) 118 { 119 data = text[1]; 120 } 121 else 122 { 123 data = ""; 124 } 125 126 parseParameterInformation(data, eventInformation); 127 128 return eventInformation; 129 } 130 131 private HashMap parseParameterInformation (String data, HashMap eventInformation) 132 { 133 135 StringParser parser = new StringParser(data, isColonPresent); 140 String text[] = data.split("\\s", 2); 141 int targetLength = 0; 142 143 if (!parser.matches()) 144 { 145 text = data.split("\\s", 2); 146 eventInformation.put($TARGET$, text[0]); 147 targetLength = text[0].length() + 1; 148 } 149 else 150 { 151 if (((data.charAt(1) == '#') || (data.charAt(1) == '&')) && data.indexOf(' ') == -1) 152 { 153 data = data.substring(1, data.length()); 156 157 return parseParameterInformation(data, eventInformation); 158 } 159 else 160 { 161 data = "<null> " + data; 162 targetLength = "<null>".length() + 1; 163 } 164 165 text = data.split("\\s", 2); 166 parser = new StringParser(data, isColonPresent); 167 } 168 169 StringBuffer parmsString = new StringBuffer (); 170 171 while (!parser.matches() && text.length > 1) 172 { 173 text = data.split("\\s", 2); 174 175 if (text.length > 1) 176 { 177 data = text[1]; 178 179 parmsString.append(text[0]); 180 parmsString.append(" "); 181 182 parser = new StringParser(data, isColonPresent); 183 } 184 } 185 186 if (parser.matches()) 187 { 188 parmsString.append(parser.getParsedString(0)); 189 } 190 else if (!data.equals(":")) 191 { 192 parmsString.append(data); 193 } 194 195 eventInformation.put($DATA$, parmsString.toString()); 196 197 if (targetLength < parmsString.toString().length()) 198 { 199 eventInformation.put($PARMS$, parmsString.toString().substring(targetLength, parmsString.toString().length() )); 200 } 201 else 202 { 203 eventInformation.put($PARMS$, ""); 204 } 205 206 return eventInformation; 207 } 208 209 private HashMap parseSourceInformation(String text, HashMap eventInformation) 210 { 211 StringParser parser = new StringParser(text, isNickUserHost); 212 if (parser.matches()) 213 { 214 222 String [] data = parser.getParsedStrings(); 223 eventInformation.put($NICK$, data[0]); 224 eventInformation.put($ADDRESS$, data[1]); 225 eventInformation.put($USER$, data[2]); 226 eventInformation.put($HOST$, data[3]); 227 228 eventInformation.put($SOURCE$, data[0]); 229 230 return eventInformation; 231 } 232 233 parser = new StringParser(text, isHost); 234 if (parser.matches()) 235 { 236 String [] data = parser.getParsedStrings(); 237 eventInformation.put($SERVER$, data[0]); 238 eventInformation.put($NICK$, data[0]); 239 eventInformation.put($SOURCE$, data[0]); 240 241 return eventInformation; 242 } 243 244 parser = new StringParser(text, isNick); 245 if (parser.matches()) 246 { 247 String [] data = parser.getParsedStrings(); 248 eventInformation.put($NICK$, data[0]); 249 eventInformation.put($SOURCE$, data[0]); 250 } 251 252 return eventInformation; 253 } 254 } 255 | Popular Tags |