public ConcreteElement buildTemplate(RunData data)
throws Exception
{
String screenData = null;
Context context = TurbineVelocity.getContext(data);
String screenTemplate = data.getTemplateInfo().getScreenTemplate();
String templateName
= TurbineTemplate.getScreenTemplateName(screenTemplate);
// The Template Service could not find the Screen
if (StringUtils.isEmpty(templateName))
{
log.error("Screen " + screenTemplate + " not found!");
throw new Exception("Could not find screen for " + screenTemplate);
}
try
{
// if a layout has been defined return the results, otherwise
// send the results directly to the output stream.
if (getLayout(data) == null)
{
TurbineVelocity.handleRequest(context,
prefix + templateName,
data.getResponse().getOutputStream());
}
else
{
screenData = TurbineVelocity
.handleRequest(context, prefix + templateName);
}
}
catch (Exception e)
{
// If there is an error, build a $processingException and
// attempt to call the error.vm template in the screens
// directory.
context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));
templateName = Turbine.getConfiguration()
.getString(TurbineConstants.TEMPLATE_ERROR_KEY,
TurbineConstants.TEMPLATE_ERROR_VM);