KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlet > exomvc > VelocityPage


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlet.exomvc;
6
7 import java.io.Writer JavaDoc;
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 /**
16  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
17  * @since Nov 7, 2004
18  * @version $Id$
19  */

20 public class VelocityPage extends Page {
21   private String JavaDoc template_ ;
22   
23   public String JavaDoc getTemplate() { return template_ ; }
24   public void setTemplate(String JavaDoc s) { template_ = s ; }
25   
26   public void render(RenderRequest req, RenderResponse res) throws Exception JavaDoc {
27     Configuration config = getConfiguration() ;
28     String JavaDoc pageURL = getPageURL(res) ;
29     Writer JavaDoc 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