1 5 package org.exoplatform.portlet.exomvc; 6 7 import java.io.Writer ; 8 import javax.portlet.* ; 9 import org.apache.velocity.Template; 10 import org.apache.velocity.VelocityContext; 11 import org.apache.velocity.app.VelocityEngine; 12 import org.apache.velocity.context.Context; 13 import org.exoplatform.portlet.exomvc.config.Configuration; 14 15 20 public class VelocityPage extends Page { 21 private String template_ ; 22 23 public String getTemplate() { return template_ ; } 24 public void setTemplate(String s) { template_ = s ; } 25 26 public void render(RenderRequest req, RenderResponse res) throws Exception { 27 Configuration config = getConfiguration() ; 28 String pageURL = getPageURL(res) ; 29 Writer writer = res.getWriter() ; 30 Context ctx = (Context)req.getAttribute(VELOCITY_CONTEXT); 31 if(ctx == null) ctx = new VelocityContext() ; 32 ctx.put(PAGE_URL , pageURL) ; 33 Template tmpl = config.getVelocityResourceManager().getTemplate(template_) ; 34 tmpl.merge(ctx, writer) ; 35 } 36 37 public void setVelocityContext(PortletRequest req, Context ctx) { 38 req.setAttribute(VELOCITY_CONTEXT, ctx) ; 39 } 40 41 public Context getVelocityContext(PortletRequest req) { 42 return (Context)req.getAttribute(VELOCITY_CONTEXT) ; 43 } 44 } | Popular Tags |