KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > tags > menu > MenuTag


1
2 package org.roller.presentation.tags.menu;
3
4 import javax.servlet.http.Cookie JavaDoc;
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpServletResponse JavaDoc;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.apache.velocity.VelocityContext;
11 import org.roller.RollerException;
12 import org.roller.presentation.util.RequestUtil;
13 import org.roller.presentation.RollerRequest;
14 import org.roller.presentation.tags.VelocityTag;
15 import org.roller.presentation.velocity.ContextLoader;
16 //import javax.servlet.jsp.tagext.*;
17

18
19 /**
20  * @jsp.tag name="Menu"
21  */

22 public class MenuTag extends VelocityTag
23 {
24     private static Log mLogger =
25         LogFactory.getFactory().getInstance(RollerRequest.class);
26
27     /** Unique ID for this menu within the user's session.
28       * @jsp.attribute
29       */

30     public String JavaDoc getId() { return mMenuId; }
31     public void setId( String JavaDoc v ) { mMenuId= v; }
32     private String JavaDoc mMenuId;
33
34     /** Name of the view to be used to render the menu.
35       * The view is a Velocity template and it must be in the classpath.
36       * Values: tabbed, vertical, horizontal.
37       * @jsp.attribute required="true"
38       */

39     public String JavaDoc getView() { return mView; }
40     public void setView( String JavaDoc v ) { mView = v; }
41     private String JavaDoc mView;
42
43     /** Name of the model to be used.
44       * Must correspond to name of XML file in WEB-INF directory.
45       * @jsp.attribute required="true"
46       */

47     public String JavaDoc getModel() { return mModel; }
48     public void setModel( String JavaDoc v ) { mModel = v; }
49     private String JavaDoc mModel;
50
51     public String JavaDoc getTemplateClasspath()
52     {
53         return mView;
54     }
55
56     //-------------------------------------------------------------
57

58     public void prepareContext( VelocityContext ctx )
59     {
60         HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)pageContext.getRequest();
61         HttpServletResponse JavaDoc res = (HttpServletResponse JavaDoc)pageContext.getResponse();
62
63         RollerMenuModel model = new RollerMenuModel(
64             mMenuId, "/WEB-INF/"+mModel, pageContext.getServletContext() );
65         ctx.put("menuModel", model );
66         ctx.put("ctx", pageContext );
67         ctx.put("req", req );
68         ctx.put("res", res );
69         
70         RollerRequest rreq = RollerRequest.getRollerRequest(req);
71         rreq.setPageContext(pageContext);
72         try
73         {
74             ContextLoader.setupContext( ctx, rreq, res );
75         }
76         catch (RollerException e)
77         {
78             // superclass says I can't throw an exception
79
mLogger.error(e);
80         }
81     }
82
83 }
84
85
Popular Tags