1 18 package org.apache.batik.script.jacl; 19 20 import java.io.IOException ; 21 import java.io.Reader ; 22 import java.io.Writer ; 23 import java.util.Locale ; 24 25 import org.apache.batik.script.InterpreterException; 26 27 import tcl.lang.Interp; 28 import tcl.lang.ReflectObject; 29 import tcl.lang.TclException; 30 31 37 public class JaclInterpreter implements org.apache.batik.script.Interpreter { 38 private Interp interpreter = null; 39 40 public JaclInterpreter() { 41 interpreter = new Interp(); 42 try { 43 interpreter.eval("package require java", 0); 44 } catch (TclException e) { 45 } 46 } 47 48 50 public Object evaluate(Reader scriptreader) 51 throws InterpreterException, IOException { 52 return evaluate(scriptreader, ""); 53 } 54 55 public Object evaluate(Reader scriptreader, String description) throws IOException , InterpreterException { 56 StringBuffer sbuffer = new StringBuffer (); 58 char[] buffer = new char[1024]; 59 int val = 0; 60 while ((val = scriptreader.read(buffer)) != -1) { 61 sbuffer.append(buffer, 0, val); 62 } 63 String str = sbuffer.toString(); 64 return evaluate(str); 65 } 66 67 public Object evaluate(String script) 68 throws InterpreterException { 69 try { 70 interpreter.eval(script, 0); 71 } catch (TclException e) { 72 throw new InterpreterException(e, e.getMessage(), -1, -1); 73 } catch (RuntimeException re) { 74 throw new InterpreterException(re, re.getMessage(), -1, -1); 75 } 76 return interpreter.getResult(); 77 } 78 79 public void dispose() { 80 interpreter.dispose(); 81 } 82 83 public void bindObject(String name, Object object) { 84 try { 85 interpreter. 86 setVar(name, 87 ReflectObject. 88 newInstance(interpreter, object.getClass(), object), 89 0); 90 } catch (TclException e) { 91 } 93 } 94 95 public void setOut(Writer out) { 96 } 98 99 101 public Locale getLocale() { 102 return Locale.getDefault(); 103 } 104 105 public void setLocale(Locale locale) { 106 } 107 108 public String formatMessage(String key, Object [] args) { 109 return null; 110 } 111 } 112 | Popular Tags |