1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.modules.parameters;
1819// Turbine support20import org.apache.turbine.util.RunData;
21import org.apache.turbine.services.TurbineServices;
22import org.apache.turbine.services.jsp.JspService;
2324// Java stuff25import java.util.Map;
2627// jetspeed stuff28import org.apache.jetspeed.services.TemplateLocator;
29import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
30import org.apache.jetspeed.services.logging.JetspeedLogger;
3132/***33 * Generic jsp-based presentation style. The following default objects are put in the context:34 * <UL>35 * <LI>data - rundata object</LI>36 * <LI>name - name of the parameter</LI>37 * <LI>value - current value of the parameter</LI>38 * <LI>parms - map of additional style parameters</LI>39 * </UL>40 * 41 * <P>Supporting jsp templates should be placed in ${velocity-templates-root}/parameters folder.</p>42 * 43 * <P>It may be used directly with "template" as the only required parameter. This is useful when the44 * no additional objects are needed by the template.</P>45 * 46 * <P>If additional objects need to be put in the context, a new class extending JspParameterPresentationStyle47 * should be created. Override buildContext to place custom objects in the jsp context.</P>48 * 49 * <P>If "template" parameter is not specified, it is assumed that the template name is "classname.vm".</P>50 * 51 * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>52 * @version $Id: JspParameterPresentationStyle.java,v 1.4 2004/02/23 03:01:20 jford Exp $53 */5455publicclassJspParameterPresentationStyleextendsParameterPresentationStyle56 {
5758/***59 * Static initialization of the logger for this class60 */61privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(JspParameterPresentationStyle.class.getName());
6263/***64 * Returns presentation control65 * 66 * @param data - rundata object67 * @param name - parameter name68 * @param value - current parameter value69 * @param parms - additional style parameters70 * @return string71 */72public String getContent(RunData data, String name, String value, Map parms)
73 {
74 String result = null;
7576// Get reference to jsp service77 JspService jspService = (JspService) TurbineServices.getInstance().getService(JspService.SERVICE_NAME);
7879// Put basics in the context80 data.getRequest().setAttribute("data", data);
81 data.getRequest().setAttribute("name", name);
82 data.getRequest().setAttribute("value", value);
83 data.getRequest().setAttribute("parms", parms);
84 data.getRequest().setAttribute("events", this.getJavascriptEvents());
8586try87 {
88// Add custom objects to the context89this.buildContext(data, name, value, parms);
9091// Build default template name (classname + .vm)92 String className = this.getClass().getName();
93int pos = className.lastIndexOf(".");
94 pos = pos < 0 ? 0 : pos + 1;
95 className = className.substring(pos);
9697// Render the template98 String template = (String) this.getParm("template", className + ".jsp");
99 String templatePath = TemplateLocator.locateParameterTemplate(data, template);
100 jspService.handleRequest(data, templatePath);
101 result = "";
102 }
103catch (Exception e)
104 {
105 logger.error("Exception", e);
106// Fallback to input text box presentation style107 result = "<input type=\"text\" name=\"" + name + "\" value=\"" + value + "\"";
108 }
109110return result;
111112 }
113114/***115 * Override this method to put your own objects in the Velocity context116 * 117 * @param data118 * @param name119 * @param value120 * @param parms121 * @param context122 */123publicvoid buildContext(RunData data, String name, String value, Map parms)
124 {
125126 }
127 }