php.setWorkDir(getPath(request));
Env env = null;
WriteStream ws = null;
try {
Path path = getPath(request);
QuercusPage page;
try {
page = php.parse(path);
}
catch (FileNotFoundException ex) {
Logger.warn(this, ex.getMessage());
Logger.debug(this, ex.getMessage(), ex);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}catch (NullPointerException ex) {
Logger.warn(this, ex.getMessage());
Logger.debug(this, ex.getMessage(), ex);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
StreamImpl out;
try {
out = new VfsStream(null, response.getOutputStream());
}
catch (IllegalStateException e) {
WriterStreamImpl writer = new WriterStreamImpl();
writer.setWriter(response.getWriter());
out = writer;
}
ws = new WriteStream(out);
ws.setNewlineString("\n");
php.setServletContext(_servletContext);
env = php.createEnv(page, ws, request, response);
try {
env.start();
env.setPwd(path);
env.setGlobalValue("request", env.wrapJava(request));
env.setGlobalValue("response", env.wrapJava(response));
env.setGlobalValue("session", env.wrapJava(request.getSession()));
env.setGlobalValue("servletContext", env.wrapJava(_servletContext));
String prepend = env.getIniString("auto_prepend_file");
if (prepend != null) {
Path prependPath = env.lookup(env.createString(prepend));
if (prependPath == null)
env.error("auto_prepend_file '{0}' not found.", prepend);
else {
QuercusPage prependPage = php.parse(prependPath);
prependPage.executeTop(env);
}
}
page.executeTop(env);
String append = env.getIniString("auto_append_file");
if (append != null) {
Path appendPath = env.lookup(env.createString(append));
if (appendPath == null)
env.error("auto_append_file '{0}' not found.", append);
else {
QuercusPage appendPage = php.parse(appendPath);