001 package org.apache.turbine.services.jsp;
002
003
004 /*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements. See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership. The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License. You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied. See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024 import org.apache.turbine.pipeline.PipelineData;
025 import org.apache.turbine.services.TurbineServices;
026
027 import org.apache.turbine.util.RunData;
028 import org.apache.turbine.util.TurbineException;
029
030 /**
031 * Facade class for the Jsp Service.
032 *
033 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
034 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
035 */
036 public abstract class TurbineJsp
037 {
038 /**
039 * Utility method for accessing the service
040 * implementation
041 *
042 * @return a JspService implementation instance
043 */
044 protected static JspService getService()
045 {
046 return (JspService) TurbineServices
047 .getInstance().getService(JspService.SERVICE_NAME);
048 }
049
050 /**
051 * Adds some convenience objects to the request. For example an instance
052 * of JspLink which can be used to generate links to other templates.
053 *
054 * @deprecated Use the PipelineData version.
055 * @param data the turbine rundata object
056 */
057 public static void addDefaultObjects(RunData data)
058 {
059 getService().addDefaultObjects(data);
060 }
061
062
063 /**
064 * Adds some convenience objects to the request. For example an instance
065 * of JspLink which can be used to generate links to other templates.
066 *
067 * @param data the turbine pipelinedData object
068 */
069 public static void addDefaultObjects(PipelineData pipelineData)
070 {
071 //Map runDataMap = (Map) pipelineData.get(RunData.class);
072 //RunData data = (RunData)runDataMap.get(RunData.class);
073 RunData runData = (RunData)pipelineData;
074 addDefaultObjects(runData);
075 }
076
077 /**
078 * executes the JSP given by templateName.
079 *
080 * @deprecated Use the PipelineData version.
081 * @param data A RunData Object
082 * @param templateName The template to execute
083 * @param isForward whether to perform a forward or include.
084 *
085 * @throws TurbineException If a problem occured while executing the JSP
086 */
087 public static void handleRequest(RunData data, String templateName, boolean isForward)
088 throws TurbineException
089 {
090 getService().handleRequest(data, templateName, isForward);
091 }
092
093 /**
094 * executes the JSP given by templateName.
095 *
096 * @deprecated Use the PipelineData version.
097 * @param data A RunData Object
098 * @param templateName The template to execute
099 *
100 * @throws TurbineException If a problem occured while executing the JSP
101 */
102 public static void handleRequest(RunData data, String templateName)
103 throws TurbineException
104 {
105 getService().handleRequest(data, templateName);
106 }
107
108 /**
109 * executes the JSP given by templateName.
110 *
111 * @param data A RunData Object
112 * @param templateName The template to execute
113 * @param isForward whether to perform a forward or include.
114 *
115 * @throws TurbineException If a problem occured while executing the JSP
116 */
117 public static void handleRequest(PipelineData pipelineData, String templateName, boolean isForward)
118 throws TurbineException
119 {
120 //Map runDataMap = (Map) pipelineData.get(RunData.class);
121 //RunData data = (RunData)runDataMap.get(RunData.class);
122 RunData runData = (RunData)pipelineData;
123 handleRequest(runData, templateName, isForward);
124 }
125
126 /**
127 * executes the JSP given by templateName.
128 *
129 * @param data A RunData Object
130 * @param templateName The template to execute
131 *
132 * @throws TurbineException If a problem occured while executing the JSP
133 */
134 public static void handleRequest(PipelineData pipelineData, String templateName)
135 throws TurbineException
136 {
137 if(!(pipelineData instanceof RunData)){
138 throw new RuntimeException("Can't cast to rundata from pipeline data.");
139 }
140 handleRequest((RunData)pipelineData, templateName);
141 }
142
143
144 /**
145 * Returns the default buffer size of the JspService
146 *
147 * @return The default buffer size.
148 */
149 public static int getDefaultBufferSize()
150 {
151 return getService().getDefaultBufferSize();
152 }
153
154 /**
155 * Searchs for a template in the default.template path[s] and
156 * returns the template name with a relative path which is required
157 * by <a href="http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html#getRequestDispatcher(java.lang.String)">javax.servlet.RequestDispatcher</a>
158 *
159 * @param template The name of the template to search for.
160 *
161 * @return the template with a relative path
162 */
163 public static String getRelativeTemplateName(String template)
164 {
165 return getService().getRelativeTemplateName(template);
166 }
167 }