001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/utils/mvc/impl/TemplateJstlView.java $
003: * $Id: TemplateJstlView.java 14230 2006-09-05 18:02:51Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.utils.mvc.impl;
021:
022: import java.util.Map;
023:
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026:
027: import org.sakaiproject.metaobj.utils.mvc.intf.CommonModelController;
028: import org.sakaiproject.util.ResourceLoader;
029: import org.springframework.web.servlet.view.JstlView;
030:
031: /**
032: * Created by IntelliJ IDEA.
033: * User: John Ellis
034: * Date: Apr 30, 2004
035: * Time: 8:29:53 AM
036: * To change this template use File | Settings | File Templates.
037: */
038: public class TemplateJstlView extends JstlView {
039:
040: private String rightMenu = null;
041: private String leftMenu = null;
042: private String header = null;
043: private String footer = null;
044: private String body = null;
045: private String template = null;
046: private String title = null;
047:
048: private String defaultTemplateDefName = "defaultTemplateDef";
049: private String commonModelControllerName = "commonModelController";
050:
051: /**
052: * Prepares the view given the specified model, merging it with static
053: * attributes and a RequestContext attribute, if necessary.
054: * Delegates to renderMergedOutputModel for the actual rendering.
055: *
056: * @see #renderMergedOutputModel
057: */
058: public void render(Map model, HttpServletRequest request,
059: HttpServletResponse response) throws Exception {
060:
061: // Added to be able to conform to the locale in JSTL jsp's
062: ResourceLoader rb = new ResourceLoader();
063: model.put("locale", rb.getLocale().toString());
064:
065: SimpleBeanWrapper mapWrapper = (SimpleBeanWrapper) getWebApplicationContext()
066: .getBean(defaultTemplateDefName);
067:
068: Map defaultTemplateDef = (Map) mapWrapper.getWrappedBean();
069:
070: addComponent("_rightMenu", rightMenu, request,
071: defaultTemplateDef);
072: addComponent("_leftMenu", leftMenu, request, defaultTemplateDef);
073: addComponent("_header", header, request, defaultTemplateDef);
074: addComponent("_footer", footer, request, defaultTemplateDef);
075: addComponent("_body", body, request, defaultTemplateDef);
076: addComponent("_title", title, request, defaultTemplateDef);
077: template = addComponent("_template", template, request,
078: defaultTemplateDef);
079:
080: CommonModelController controller = (CommonModelController) getWebApplicationContext()
081: .getBean(commonModelControllerName);
082:
083: controller.fillModel(model, request, response);
084:
085: this .setUrl(template);
086:
087: super .render(model, request, response);
088:
089: }
090:
091: protected String addComponent(String menuTag, String menuName,
092: HttpServletRequest request, Map defaultTemplateDef) {
093:
094: if (menuName == null) {
095: menuName = (String) defaultTemplateDef.get(menuTag);
096: }
097:
098: if (menuName != null) {
099: request.setAttribute(menuTag, menuName);
100: }
101:
102: return menuName;
103: }
104:
105: public String getRightMenu() {
106: return rightMenu;
107: }
108:
109: public void setRightMenu(String rightMenu) {
110: this .rightMenu = rightMenu;
111: }
112:
113: public String getLeftMenu() {
114: return leftMenu;
115: }
116:
117: public void setLeftMenu(String leftMenu) {
118: this .leftMenu = leftMenu;
119: }
120:
121: public String getHeader() {
122: return header;
123: }
124:
125: public void setHeader(String header) {
126: this .header = header;
127: }
128:
129: public String getFooter() {
130: return footer;
131: }
132:
133: public void setFooter(String footer) {
134: this .footer = footer;
135: }
136:
137: public String getBody() {
138: return body;
139: }
140:
141: public void setBody(String body) {
142: this .body = body;
143: }
144:
145: public String getDefaultTemplateDefName() {
146: return defaultTemplateDefName;
147: }
148:
149: public void setDefaultTemplateDefName(String defaultTemplateDefName) {
150: this .defaultTemplateDefName = defaultTemplateDefName;
151: }
152:
153: public String getTemplate() {
154: return template;
155: }
156:
157: public void setTemplate(String template) {
158: this .template = template;
159: }
160:
161: public String getCommonModelControllerName() {
162: return commonModelControllerName;
163: }
164:
165: public void setCommonModelControllerName(
166: String commonModelControllerName) {
167: this .commonModelControllerName = commonModelControllerName;
168: }
169:
170: public String getTitle() {
171: return title;
172: }
173:
174: public void setTitle(String title) {
175: this.title = title;
176: }
177:
178: }
|