001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.ui.core.tags.menu;
020:
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.Map;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026: import org.apache.velocity.VelocityContext;
027: import org.apache.roller.ui.core.tags.VelocityTag;
028: import org.apache.roller.ui.rendering.model.MessageModel;
029:
030: /**
031: * @jsp.tag name="Menu"
032: */
033: public class MenuTag extends VelocityTag {
034:
035: private String mMenuId;
036: private String mView;
037: private String mModel;
038:
039: public void prepareContext(VelocityContext ctx) {
040:
041: HttpServletRequest req = (HttpServletRequest) pageContext
042: .getRequest();
043: HttpServletResponse res = (HttpServletResponse) pageContext
044: .getResponse();
045:
046: RollerMenuModel model = new RollerMenuModel(mMenuId,
047: "/WEB-INF/" + mModel, pageContext.getServletContext());
048: ctx.put("menuModel", model);
049: ctx.put("ctx", pageContext);
050: ctx.put("req", req);
051: ctx.put("res", res);
052:
053: MessageModel messageModel = new MessageModel();
054: ctx.put("text", messageModel);
055:
056: Map mapCtx = new HashMap();
057: //ContextLoader.loadToolboxContext(req, res, mapCtx);
058:
059: // hack. put mapCtx info velocity ctx
060: String key = null;
061: Iterator ctxIT = mapCtx.keySet().iterator();
062: while (ctxIT.hasNext()) {
063: key = (String) ctxIT.next();
064:
065: ctx.put(key, mapCtx.get(key));
066: }
067: }
068:
069: public String getTemplateClasspath() {
070: return mView;
071: }
072:
073: /**
074: * Unique ID for this menu within the user's session.
075: *
076: * @jsp.attribute
077: */
078: public String getId() {
079: return mMenuId;
080: }
081:
082: public void setId(String v) {
083: mMenuId = v;
084: }
085:
086: /**
087: * Name of the view to be used to render the menu.
088: * The view is a Velocity template and it must be in the classpath.
089: * Values: tabbed, vertical, horizontal.
090: *
091: * @jsp.attribute required="true"
092: */
093: public String getView() {
094: return mView;
095: }
096:
097: public void setView(String v) {
098: mView = v;
099: }
100:
101: /**
102: * Name of the model to be used.
103: * Must correspond to name of XML file in WEB-INF directory.
104: *
105: * @jsp.attribute required="true"
106: */
107: public String getModel() {
108: return mModel;
109: }
110:
111: public void setModel(String v) {
112: mModel = v;
113: }
114:
115: }
|