* evaluates based on a reader.
*/
public Object eval(Reader script, ScriptContext cxt)
throws ScriptException
{
Env env = null;
try {
ReadStream reader = ReaderStream.open(script);
QuercusProgram program = QuercusParser.parse(_quercus, null, reader);
Writer writer = cxt.getWriter();
WriteStream out;
if (writer != null) {
WriterStreamImpl s = new WriterStreamImpl();
s.setWriter(writer);
WriteStream os = new WriteStream(s);
os.setNewlineString("\n");
try {
os.setEncoding("iso-8859-1");
} catch (Exception e) {
}
out = os;
}
else
out = new NullWriteStream();
QuercusPage page = new InterpretedPage(program);
env = new Env(_quercus, page, out, null, null);
env.setScriptContext(cxt);
// php/214c
env.start();
Object result = null;
try {
Value value = program.execute(env);
if (value != null)
result = value.toJavaObject();
}
catch (QuercusExitException e) {
//php/2148
}
out.flushBuffer();
out.free();
// flush buffer just in case
//
// jrunscript in interactive mode does not automatically flush its
// buffers after every input, so output to stdout will not be seen
// until the output buffer is full
//
// http://bugs.caucho.com/view.php?id=1914
writer.flush();
return result;
/*
} catch (ScriptException e) {
throw e;
*/
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new ScriptException(e);
} catch (Throwable e) {
throw new RuntimeException(e);
} finally {
if (env != null)
env.close();
}
}