Source code: org/alicebot/server/core/processor/ConditionProcessor.java
1 // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2 // Jad home page: http://www.geocities.com/kpdus/jad.html
3 // Decompiler options: packimports(3)
4
5 package org.alicebot.server.core.processor;
6
7 import java.util.LinkedList;
8 import java.util.ListIterator;
9 import org.alicebot.server.core.PredicateMaster;
10 import org.alicebot.server.core.parser.TemplateParser;
11 import org.alicebot.server.core.parser.XMLNode;
12 import org.alicebot.server.core.util.*;
13
14 // Referenced classes of package org.alicebot.server.core.processor:
15 // AIMLProcessor, AIMLProcessorException, ProcessorException
16
17 public class ConditionProcessor extends AIMLProcessor
18 {
19
20 public ConditionProcessor()
21 {
22 }
23
24 public String process(int i, XMLNode xmlnode, TemplateParser templateparser)
25 throws AIMLProcessorException
26 {
27 if(xmlnode.XMLType == 0)
28 {
29 if(xmlnode.XMLChild == null)
30 return "";
31 String s = Toolkit.getAttributeValue("name", xmlnode.XMLAttr);
32 String s1 = Toolkit.getAttributeValue("value", xmlnode.XMLAttr);
33 if(xmlnode.XMLAttr.indexOf("name=", 0) < 0 && xmlnode.XMLAttr.indexOf("value=", 0) < 0)
34 return processListItem(i, templateparser, xmlnode.XMLChild, 1, s, s1);
35 if(xmlnode.XMLAttr.indexOf("name=", 0) >= 0 && xmlnode.XMLAttr.indexOf("value=", 0) >= 0)
36 {
37 try
38 {
39 if(PatternArbiter.matches(PredicateMaster.get(s, templateparser.getUserID(), templateparser.getBotID()), s1, true))
40 return processListItem(i, templateparser, xmlnode.XMLChild, 2, "", "");
41 }
42 catch(NotAnAIMLPatternException notanaimlpatternexception)
43 {
44 Trace.devinfo(notanaimlpatternexception.getMessage());
45 return "";
46 }
47 return "";
48 }
49 if(xmlnode.XMLAttr.indexOf("name=", 0) >= 0 && xmlnode.XMLAttr.indexOf("value=", 0) < 0)
50 return processListItem(i, templateparser, xmlnode.XMLChild, 3, s, "");
51 else
52 return "";
53 } else
54 {
55 throw new AIMLProcessorException("<condition></condition> must have content!");
56 }
57 }
58
59 public String processListItem(int i, TemplateParser templateparser, LinkedList linkedlist, int j, String s, String s1)
60 {
61 String s2 = "";
62 if(linkedlist == null)
63 return "";
64 ListIterator listiterator = linkedlist.listIterator(0);
65 String s3 = "";
66 String s4 = "";
67 String s7 = "";
68 if(j == 3)
69 s3 = PredicateMaster.get(s, templateparser.getUserID(), templateparser.getBotID());
70 while(listiterator.hasNext())
71 {
72 XMLNode xmlnode = (XMLNode)listiterator.next();
73 if(xmlnode != null)
74 label0:
75 switch(xmlnode.XMLType)
76 {
77 default:
78 break;
79
80 case 2: // '\002'
81 case 3: // '\003'
82 s2 = s2 + xmlnode.XMLData;
83 break;
84
85 case 1: // '\001'
86 try
87 {
88 s2 = s2 + templateparser.processTag(i++, xmlnode);
89 }
90 catch(ProcessorException processorexception) { }
91 break;
92
93 case 0: // '\0'
94 if(!xmlnode.XMLData.equals("li"))
95 {
96 try
97 {
98 s2 = s2 + templateparser.processTag(i++, xmlnode);
99 }
100 catch(ProcessorException processorexception1) { }
101 break;
102 }
103 switch(j)
104 {
105 default:
106 break label0;
107
108 case 1: // '\001'
109 if(xmlnode.XMLAttr.indexOf("name=", 0) < 0 && xmlnode.XMLAttr.indexOf("value=", 0) < 0)
110 {
111 s2 = s2 + templateparser.evaluate(i++, xmlnode.XMLChild);
112 break label0;
113 }
114 if(xmlnode.XMLAttr.indexOf("name=", 0) < 0 || xmlnode.XMLAttr.indexOf("value=", 0) < 0)
115 break label0;
116 String s8 = Toolkit.getAttributeValue("name", xmlnode.XMLAttr);
117 String s5 = Toolkit.getAttributeValue("value", xmlnode.XMLAttr);
118 try
119 {
120 if(PatternArbiter.matches(PredicateMaster.get(s8, templateparser.getUserID(), templateparser.getBotID()), s5, true))
121 return s2 + templateparser.evaluate(i++, xmlnode.XMLChild);
122 }
123 catch(NotAnAIMLPatternException notanaimlpatternexception)
124 {
125 Trace.devinfo(notanaimlpatternexception.getMessage());
126 }
127 break label0;
128
129 case 2: // '\002'
130 s2 = s2 + templateparser.evaluate(i++, xmlnode.XMLChild);
131 break label0;
132
133 case 3: // '\003'
134 break;
135 }
136 if(xmlnode.XMLAttr.indexOf("value=", 0) >= 0)
137 {
138 String s6 = Toolkit.getAttributeValue("value", xmlnode.XMLAttr);
139 try
140 {
141 if(PatternArbiter.matches(s3, s6, true))
142 {
143 s2 = s2 + templateparser.evaluate(i++, xmlnode.XMLChild);
144 return s2;
145 }
146 }
147 catch(NotAnAIMLPatternException notanaimlpatternexception1)
148 {
149 Trace.userinfo(notanaimlpatternexception1.getMessage());
150 }
151 } else
152 {
153 s2 = s2 + templateparser.evaluate(i++, xmlnode.XMLChild);
154 return s2;
155 }
156 break;
157 }
158 }
159 return s2;
160 }
161
162 public static final int NAME_VALUE_LI = 1;
163 public static final int DEFAULT_LI = 2;
164 public static final int VALUE_ONLY_LI = 3;
165 public static final String label = "condition";
166 private static final String LI = "li";
167 }