Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/alicebot/server/core/processor/loadtime/SubstitutionsProcessor.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.loadtime;
6   
7   import java.io.File;
8   import org.alicebot.server.core.*;
9   import org.alicebot.server.core.logging.Log;
10  import org.alicebot.server.core.parser.StartupFileParser;
11  import org.alicebot.server.core.parser.XMLNode;
12  import org.alicebot.server.core.processor.ProcessorException;
13  import org.alicebot.server.core.util.Toolkit;
14  import org.alicebot.server.core.util.UserError;
15  
16  // Referenced classes of package org.alicebot.server.core.processor.loadtime:
17  //            StartupElementProcessor, InvalidStartupElementException
18  
19  public class SubstitutionsProcessor extends StartupElementProcessor
20  {
21  
22      public SubstitutionsProcessor()
23      {
24      }
25  
26      public String process(int i, XMLNode xmlnode, StartupFileParser startupfileparser)
27          throws InvalidStartupElementException
28      {
29          String s = getHref(xmlnode);
30          if(s.length() > 0)
31              try
32              {
33                  return startupfileparser.processResponse(Toolkit.getFileContents(Graphmaster.getWorkingDirectory() + File.separator + s));
34              }
35              catch(ProcessorException processorexception)
36              {
37                  throw new UserError(processorexception);
38              }
39          else
40              return startupfileparser.evaluate(i++, xmlnode.XMLChild);
41      }
42  
43      static void addSubstitutions(int i, XMLNode xmlnode, StartupFileParser startupfileparser)
44          throws InvalidStartupElementException
45      {
46          int j = startupfileparser.nodeCount("substitute", xmlnode.XMLChild, true);
47          Bot bot = startupfileparser.getCurrentBot();
48          for(int k = j; k > 0; k--)
49          {
50              XMLNode xmlnode1 = startupfileparser.getNode("substitute", xmlnode.XMLChild, k);
51              if(xmlnode1.XMLType == 1)
52              {
53                  String s = Toolkit.getAttributeValue("find", xmlnode1.XMLAttr);
54                  String s1 = Toolkit.getAttributeValue("replace", xmlnode1.XMLAttr);
55                  if(s != null && s1 != null)
56                      switch(i)
57                      {
58                      case 0: // '\0'
59                          bot.addInputSubstitution(s, s1);
60                          break;
61  
62                      case 1: // '\001'
63                          bot.addGenderSubstitution(s, s1);
64                          break;
65  
66                      case 2: // '\002'
67                          bot.addPersonSubstitution(s, s1);
68                          break;
69  
70                      case 3: // '\003'
71                          bot.addPerson2Substitution(s, s1);
72                          break;
73                      }
74              } else
75              {
76                  throw new InvalidStartupElementException("<" + xmlnode.XMLData + "/> cannot have content!");
77              }
78          }
79  
80          if(Globals.showConsole())
81              Log.userinfo("Loaded " + j + " " + xmlnode.XMLData + " substitutions.", Log.STARTUP);
82      }
83  
84      public static final String label = "substitutions";
85      private static final String SUBSTITUTE = "substitute";
86      private static final String FIND = "find";
87      private static final String REPLACE = "replace";
88      static final int INPUT = 0;
89      static final int GENDER = 1;
90      static final int PERSON = 2;
91      static final int PERSON2 = 3;
92  }