| Index: TurbineJspService.java |
| =================================================================== |
| RCS file: /home/cvspublic/jakarta-turbine-2/src/java/org/apache/turbine/services/jsp/TurbineJspService.java,v |
| retrieving revision 1.8 |
| diff -u -r1.8 TurbineJspService.java |
| --- TurbineJspService.java 13 Jan 2003 21:14:29 -0000 1.8 |
| +++ TurbineJspService.java 11 Feb 2003 14:43:37 -0000 |
| @@ -67,6 +67,8 @@ |
| import org.apache.turbine.services.template.TurbineTemplate; |
| import org.apache.turbine.util.RunData; |
| import org.apache.turbine.util.TurbineException; |
| +import org.apache.velocity.context.Context; |
| +import org.apache.velocity.VelocityContext; |
| |
| |
| /** |
| @@ -76,6 +78,7 @@ |
| * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> |
| * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a> |
| * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> |
| + * @author <a href="mailto:gabrielm@itcsoluciones.com">Gabriel A. Moreno</a> |
| */ |
| public class TurbineJspService extends BaseTemplateEngineService |
| implements JspService |
| @@ -137,6 +140,7 @@ |
| HttpServletRequest req = data.getRequest(); |
| req.setAttribute(LINK, new JspLink(data)); |
| req.setAttribute(RUNDATA, data); |
| + req.setAttribute(CONTEXT_INSTANCE, getContext(data)); |
| } |
| |
| /** |
| @@ -307,4 +311,40 @@ |
| } |
| return null; |
| } |
| + |
| + /** |
| + * Create a Context object that also contains the globalContext. |
| + * |
| + * @return A Context object. |
| + */ |
| + public Context getContext() |
| + { |
| + return new VelocityContext(/*globalContext*/); |
| + } |
| + |
| + /** |
| + * Create a Context from the RunData object. |
| + * |
| + * @param data The Turbine RunData object. |
| + * @return A clone of the WebContext needed by Velocity. |
| + */ |
| + public Context getContext(RunData data) |
| + { |
| + /* |
| + * Attempt to get it from the data first. If it doesn't |
| + * exist, create it and then stuff it into the data. |
| + */ |
| + Context context = (Context) |
| + data.getTemplateInfo().getTemplateContext(JspService.CONTEXT); |
| + |
| + if (context == null) |
| + { |
| + context = getContext(); |
| + |
| + data.getTemplateInfo().setTemplateContext( |
| + JspService.CONTEXT, context); |
| + } |
| + return context; |
| + } |
| + |
| } |