KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > ircfw > data > MyInformationTracker


1 package rero.ircfw.data;
2
3 /* keep "my" information in IDL up to date
4    my information includes things such as my nickname and all that jazz... */

5
6 import rero.ircfw.interfaces.FrameworkConstants;
7 import rero.util.StringParser;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.regex.Pattern JavaDoc;
11
12 public class MyInformationTracker extends DataEventAction implements FrameworkConstants {
13   private static String JavaDoc supportPattern = ":.*? 005 .*? (.*?) :.*";
14   private static Pattern JavaDoc isSupport = Pattern.compile(supportPattern);
15
16   public boolean isEvent(HashMap JavaDoc data) {
17     String JavaDoc temp = (String JavaDoc) data.get($EVENT$);
18
19     if ("001".equals(temp)) {
20       return true;
21     }
22     if ("305".equals(temp)) {
23       return true;
24     } /* back from being away */
25     if ("306".equals(temp)) {
26       return true;
27     } /* set as away */
28     if ("005".equals(temp)) {
29       return true;
30     }
31
32     return false;
33   }
34
35   public void process(HashMap JavaDoc data) {
36     if ("001".equals(data.get($EVENT$))) {
37       dataList.setMyNick((String JavaDoc) data.get($TARGET$));
38     }
39
40     if ("305".equals(data.get($EVENT$))) {
41       dataList.getMyUserInformation().setBack();
42     }
43
44     if ("306".equals(data.get($EVENT$))) {
45       dataList.getMyUserInformation().setAway();
46     }
47
48     if ("005".equals(data.get($EVENT$))) {
49       StringParser parser = new StringParser(data.get($RAW$).toString(), isSupport);
50       if (parser.matches()) {
51         String JavaDoc[] temp = parser.getParsedString(0).split(" ");
52         for (int x = 0; x < temp.length; x++) {
53           String JavaDoc key, value;
54
55           if (temp[x].indexOf('=') > -1) {
56             key = temp[x].substring(0, temp[x].indexOf('='));
57             value = temp[x].substring(key.length() + 1, temp[x].length());
58
59             dataList.addSupportInfo(key, value);
60
61             if (key.equals("PREFIX")) {
62               String JavaDoc chars = value.substring(1, value.indexOf(')'));
63               String JavaDoc modes = value.substring(chars.length() + 2, value.length());
64
65               dataList.setPrefixInfo(chars, modes);
66               // split chanmodes to groups
67
} else if (key.equals("CHANMODES")) {
68               String JavaDoc[] groups = value.split(",");
69               // we should have 4 groups
70
if (groups.length == 4) {
71                 dataList.setChanGroupMode("A", groups[0]);
72                 dataList.setChanGroupMode("B", groups[1]);
73                 dataList.setChanGroupMode("C", groups[2]);
74                 dataList.setChanGroupMode("D", groups[3]);
75               }
76             }
77           } else {
78             dataList.addSupportInfo(temp[x], "true");
79           }
80         }
81       }
82     }
83
84   }
85 }
86
87
Popular Tags