// get the various items required from the stack
Map actionContext = templateContext.getStack().getContext();
ServletContext servletContext = (ServletContext) actionContext.get(ServletActionContext.SERVLET_CONTEXT);
HttpServletRequest req = (HttpServletRequest) actionContext.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse res = (HttpServletResponse) actionContext.get(ServletActionContext.HTTP_RESPONSE);
// prepare velocity
velocityManager.init(servletContext);
VelocityEngine velocityEngine = velocityManager.getVelocityEngine();
// get the list of templates we can use
List templates = templateContext.getTemplate().getPossibleTemplates(this);
// find the right template
org.apache.velocity.Template template = null;
String templateName = null;
Exception exception = null;
for (Iterator iterator = templates.iterator(); iterator.hasNext();) {
Template t = (Template) iterator.next();
templateName = getFinalTemplateName(t);
try {
// try to load, and if it works, stop at the first one
template = velocityEngine.getTemplate(templateName);
break;
} catch (IOException e) {
if (exception == null) {
exception = e;
}
}
}
if (template == null) {
LOG.error("Could not load template " + templateContext.getTemplate());
if (exception != null) {
throw exception;
} else {
return;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Rendering template " + templateName);
}
Context context = velocityManager.createContext(templateContext.getStack(), req, res);
Writer outputWriter = templateContext.getWriter();
context.put("tag", templateContext.getTag());
context.put("parameters", templateContext.getParameters());
template.merge(context, outputWriter);