001package org.apache.turbine.modules.pages; 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 024import org.apache.turbine.annotation.TurbineService; 025import org.apache.turbine.pipeline.PipelineData; 026import org.apache.turbine.services.velocity.VelocityService; 027import org.apache.turbine.util.RunData; 028import org.apache.velocity.context.Context; 029 030/** 031 * Extends TemplatePage to set the template Context. 032 * 033 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 034 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> 035 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 036 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 037 * @version $Id$ 038 */ 039public class VelocityPage 040 extends TemplatePage 041{ 042 /** Injected service instance */ 043 @TurbineService 044 private VelocityService velocity; 045 046 /** 047 * Stuffs the Context into the PipelineData so that it is available to 048 * the Action module and the Screen module via getContext(). 049 * 050 * @param pipelineData Turbine information. 051 * @throws Exception a generic exception. 052 */ 053 @Override 054 protected void doBuildBeforeAction(PipelineData pipelineData) 055 throws Exception 056 { 057 RunData data = pipelineData.getRunData(); 058 Context context = velocity.getContext(pipelineData); 059 data.getTemplateInfo() 060 .setTemplateContext(VelocityService.CONTEXT, context); 061 } 062 063 /** 064 * Allows the VelocityService to perform post-request actions. 065 * (releases the (non-global) tools in the context for reuse later) 066 */ 067 @Override 068 protected void doPostBuild(PipelineData pipelineData) 069 throws Exception 070 { 071 Context context = velocity.getContext(pipelineData); 072 velocity.requestFinished(context); 073 } 074}