1 18 package org.apache.batik.script.jpython; 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 import org.python.util.PythonInterpreter; 27 28 34 public class JPythonInterpreter implements org.apache.batik.script.Interpreter { 35 private PythonInterpreter interpreter = null; 36 37 public JPythonInterpreter() { 38 interpreter = new PythonInterpreter(); 39 } 40 41 43 public Object evaluate(Reader scriptreader) 44 throws InterpreterException, IOException { 45 return evaluate(scriptreader, ""); 46 } 47 48 public Object evaluate(Reader scriptreader, String description) 49 throws InterpreterException, IOException { 50 51 StringBuffer sbuffer = new StringBuffer (); 53 char[] buffer = new char[1024]; 54 int val = 0; 55 while ((val = scriptreader.read(buffer)) != -1) { 56 sbuffer.append(buffer,0, val); 57 } 58 String str = sbuffer.toString(); 59 return evaluate(str); 60 } 61 62 public Object evaluate(String script) 63 throws InterpreterException { 64 try { 65 interpreter.exec(script); 66 } catch (org.python.core.PyException e) { 67 throw new InterpreterException(e, e.getMessage(), -1, -1); 68 } catch (RuntimeException re) { 69 throw new InterpreterException(re, re.getMessage(), -1, -1); 70 } 71 return null; 72 } 73 74 public void dispose() { 75 } 76 77 public void bindObject(String name, Object object) { 78 interpreter.set(name, object); 79 } 80 81 public void setOut(Writer out) { 82 interpreter.setOut(out); 83 } 84 85 87 public Locale getLocale() { 88 return null; 89 } 90 91 public void setLocale(Locale locale) { 92 } 93 94 public String formatMessage(String key, Object [] args) { 95 return null; 96 } 97 } 98 | Popular Tags |