Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TurbineJsp |
|
| 1.2222222222222223;1,222 |
1 | package org.apache.turbine.services.jsp; | |
2 | ||
3 | ||
4 | /* | |
5 | * Licensed to the Apache Software Foundation (ASF) under one | |
6 | * or more contributor license agreements. See the NOTICE file | |
7 | * distributed with this work for additional information | |
8 | * regarding copyright ownership. The ASF licenses this file | |
9 | * to you under the Apache License, Version 2.0 (the | |
10 | * "License"); you may not use this file except in compliance | |
11 | * with the License. You may obtain a copy of the License at | |
12 | * | |
13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
14 | * | |
15 | * Unless required by applicable law or agreed to in writing, | |
16 | * software distributed under the License is distributed on an | |
17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
18 | * KIND, either express or implied. See the License for the | |
19 | * specific language governing permissions and limitations | |
20 | * under the License. | |
21 | */ | |
22 | ||
23 | ||
24 | import org.apache.turbine.pipeline.PipelineData; | |
25 | import org.apache.turbine.services.TurbineServices; | |
26 | ||
27 | import org.apache.turbine.util.RunData; | |
28 | import org.apache.turbine.util.TurbineException; | |
29 | ||
30 | /** | |
31 | * Facade class for the Jsp Service. | |
32 | * | |
33 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> | |
34 | * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> | |
35 | */ | |
36 | 0 | public abstract class TurbineJsp |
37 | { | |
38 | /** | |
39 | * Utility method for accessing the service | |
40 | * implementation | |
41 | * | |
42 | * @return a JspService implementation instance | |
43 | */ | |
44 | protected static JspService getService() | |
45 | { | |
46 | 0 | return (JspService) TurbineServices |
47 | .getInstance().getService(JspService.SERVICE_NAME); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Adds some convenience objects to the request. For example an instance | |
52 | * of JspLink which can be used to generate links to other templates. | |
53 | * | |
54 | * @deprecated Use the PipelineData version. | |
55 | * @param data the turbine rundata object | |
56 | */ | |
57 | public static void addDefaultObjects(RunData data) | |
58 | { | |
59 | 0 | getService().addDefaultObjects(data); |
60 | 0 | } |
61 | ||
62 | ||
63 | /** | |
64 | * Adds some convenience objects to the request. For example an instance | |
65 | * of JspLink which can be used to generate links to other templates. | |
66 | * | |
67 | * @param data the turbine pipelinedData object | |
68 | */ | |
69 | public static void addDefaultObjects(PipelineData pipelineData) | |
70 | { | |
71 | //Map runDataMap = (Map) pipelineData.get(RunData.class); | |
72 | //RunData data = (RunData)runDataMap.get(RunData.class); | |
73 | 0 | RunData runData = (RunData)pipelineData; |
74 | 0 | addDefaultObjects(runData); |
75 | 0 | } |
76 | ||
77 | /** | |
78 | * executes the JSP given by templateName. | |
79 | * | |
80 | * @deprecated Use the PipelineData version. | |
81 | * @param data A RunData Object | |
82 | * @param templateName The template to execute | |
83 | * @param isForward whether to perform a forward or include. | |
84 | * | |
85 | * @throws TurbineException If a problem occured while executing the JSP | |
86 | */ | |
87 | public static void handleRequest(RunData data, String templateName, boolean isForward) | |
88 | throws TurbineException | |
89 | { | |
90 | 0 | getService().handleRequest(data, templateName, isForward); |
91 | 0 | } |
92 | ||
93 | /** | |
94 | * executes the JSP given by templateName. | |
95 | * | |
96 | * @deprecated Use the PipelineData version. | |
97 | * @param data A RunData Object | |
98 | * @param templateName The template to execute | |
99 | * | |
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 | 0 | getService().handleRequest(data, templateName); |
106 | 0 | } |
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 | 0 | RunData runData = (RunData)pipelineData; |
123 | 0 | handleRequest(runData, templateName, isForward); |
124 | 0 | } |
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 | 0 | if(!(pipelineData instanceof RunData)){ |
138 | 0 | throw new RuntimeException("Can't cast to rundata from pipeline data."); |
139 | } | |
140 | 0 | handleRequest((RunData)pipelineData, templateName); |
141 | 0 | } |
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 | 0 | 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 | 0 | return getService().getRelativeTemplateName(template); |
166 | } | |
167 | } |