* @return A ConcreteElement.
* @exception Exception, a generic exception.
*/
public ConcreteElement buildTemplate( RunData data ) throws Exception
{
StringElement output = null;
String screenData = null;
Context context = TurbineVelocity.getContext(data);
// This will already be properly set and will not be null
// because of TemplateSessionValidator.
String templateName = TurbineTemplate.getScreenTemplateName(
data.getTemplateInfo().getScreenTemplate() );
// Template service adds the leading slash, but make it sure.
if ((templateName.length() > 0) &&
(templateName.charAt(0) != '/'))
{
templateName = '/' + templateName;
}
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,
"screens" + templateName,
data.getResponse().getOutputStream());
}
else
{
screenData = TurbineVelocity
.handleRequest(context,"screens" + 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 ( "processingException", e.toString() );
context.put ( "stackTrace", StringUtils.stackTrace(e) );
templateName = TurbineResources.getString(
"template.error", "/error.vm");
if ((templateName.length() > 0) &&
(templateName.charAt(0) != '/'))
{
templateName = '/' + templateName;
}
screenData = TurbineVelocity.handleRequest(
context, "screens" + templateName);
}
// package the response in an ECS element
if (screenData != null)
{
output = new StringElement();
output.setFilterState(false);
output.addElement(screenData);
}
return output;
}