/** template name with relative path */
String relativeTemplateName = getRelativeTemplateName(templateName);
if (StringUtils.isEmpty(relativeTemplateName))
{
throw new TurbineException(
"Template " + templateName + " not found in template paths");
}
// get the RequestDispatcher for the JSP
RequestDispatcher dispatcher = data.getServletContext()
.getRequestDispatcher(relativeTemplateName);
try
{
if (isForward)
{
// forward the request to the JSP
dispatcher.forward(data.getRequest(), data.getResponse());
}
else
{
data.getOut().flush();
// include the JSP
dispatcher.include(data.getRequest(), data.getResponse());
}
}
catch (Exception e)
{
// as JSP service is in Alpha stage, let's try hard to send the
// error message to the browser, to speed up debugging
try
{
data.getOut().print("Error encountered processing a template: "
+ templateName);
e.printStackTrace(data.getOut());
}
catch (IOException ignored)
{
}
// pass the exception to the caller according to the general
// contract for tamplating services in Turbine
throw new TurbineException(
"Error encountered processing a template: " + templateName, e);
}
}