Ejemplo n.º 1
0
  public static void main(String[] args) throws Exception {
    ClipsShell shell = new ClipsShell();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    shell.addRouter("t", new PrintStream(out));

    StringBuffer buf = new StringBuffer();
    System.out.print("Drools>");

    StringBuffer sessionLog = new StringBuffer();
    while (true) {
      byte name[] = new byte[256];

      System.in.read(name);
      String cmd = (new String(name)).trim();

      if (cmd.equals("(exit)") || cmd.equals("(quit)")) {
        sessionLog.append(cmd);
        break;
      }
      buf.append(cmd);

      if (isBalancedBrackets(buf)) {
        String exp = buf.toString();
        if (exp.startsWith("(save ")) {
          String file = getFileName(exp);
          System.out.println("Saving transcript to [" + file + "]");
          writeFile(file, sessionLog);
          sessionLog = new StringBuffer();
          System.out.print("Drools>");
        } else {
          sessionLog.append(cmd + "\n");

          if (exp.startsWith("(load ")) {
            String file = getFileName(exp);
            System.out.println("Loading transcript from [" + file + "]");
            exp = loadFile(file);
          }

          shell.eval(exp);
          String output = new String(out.toByteArray());
          if (output != null && output.trim().length() > 0) {
            System.out.println(output);
          }
          out.reset();
          System.out.print("Drools>");
          buf = new StringBuffer();
        }
      }
    }

    System.out.println("Goodbye, and good luck !");
  }
Ejemplo n.º 2
0
 public void eval(String string) {
   eval(new StringReader(string));
 }