KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > tags > menu > MenuTag


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.ui.core.tags.menu;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26 import org.apache.velocity.VelocityContext;
27 import org.apache.roller.ui.core.tags.VelocityTag;
28 import org.apache.roller.ui.rendering.model.MessageModel;
29
30 /**
31  * @jsp.tag name="Menu"
32  */

33 public class MenuTag extends VelocityTag {
34     
35     private String JavaDoc mMenuId;
36     private String JavaDoc mView;
37     private String JavaDoc mModel;
38     
39     
40     public void prepareContext(VelocityContext ctx) {
41         
42         HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)pageContext.getRequest();
43         HttpServletResponse JavaDoc res = (HttpServletResponse JavaDoc)pageContext.getResponse();
44         
45         RollerMenuModel model = new RollerMenuModel(
46                 mMenuId, "/WEB-INF/"+mModel, pageContext.getServletContext() );
47         ctx.put("menuModel", model );
48         ctx.put("ctx", pageContext );
49         ctx.put("req", req );
50         ctx.put("res", res );
51         
52         MessageModel messageModel = new MessageModel();
53         ctx.put("text", messageModel);
54                 
55         Map JavaDoc mapCtx = new HashMap JavaDoc();
56         //ContextLoader.loadToolboxContext(req, res, mapCtx);
57

58         // hack. put mapCtx info velocity ctx
59
String JavaDoc key = null;
60         Iterator JavaDoc ctxIT = mapCtx.keySet().iterator();
61         while(ctxIT.hasNext()) {
62             key = (String JavaDoc) ctxIT.next();
63             
64             ctx.put(key, mapCtx.get(key));
65         }
66     }
67     
68     
69     public String JavaDoc getTemplateClasspath() {
70         return mView;
71     }
72     
73     
74     /**
75      * Unique ID for this menu within the user's session.
76      *
77      * @jsp.attribute
78      */

79     public String JavaDoc getId() { return mMenuId; }
80     
81     public void setId( String JavaDoc v ) { mMenuId= v; }
82     
83     
84     /**
85      * Name of the view to be used to render the menu.
86      * The view is a Velocity template and it must be in the classpath.
87      * Values: tabbed, vertical, horizontal.
88      *
89      * @jsp.attribute required="true"
90      */

91     public String JavaDoc getView() { return mView; }
92     
93     public void setView( String JavaDoc v ) { mView = v; }
94     
95     
96     /**
97      * Name of the model to be used.
98      * Must correspond to name of XML file in WEB-INF directory.
99      *
100      * @jsp.attribute required="true"
101      */

102     public String JavaDoc getModel() { return mModel; }
103     
104     public void setModel( String JavaDoc v ) { mModel = v; }
105     
106 }
107
108
Popular Tags