001package org.apache.turbine.modules.navigations; 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.template.TemplateService; 027import org.apache.turbine.services.velocity.VelocityService; 028import org.apache.turbine.util.RunData; 029import org.apache.velocity.context.Context; 030 031/** 032 * VelocityNavigation. This screen relies on the VelocityPage 033 * being set as the default page. The doBuildTemplate() assumes the 034 * user has put the template filename in the RunData parameter and set 035 * it to the value of the template file to execute. Specialized 036 * Navigations screens should extend this class and override the 037 * doBuildTemplate( data , context) method. 038 * 039 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 040 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 041 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> 042 * @version $Id$ 043 */ 044public class VelocityNavigation 045 extends TemplateNavigation 046{ 047 /** The prefix for lookup up navigation pages */ 048 private static final String prefix = PREFIX + "/"; 049 050 /** Injected service instance */ 051 @TurbineService 052 private VelocityService velocity; 053 054 /** Injected service instance */ 055 @TurbineService 056 private TemplateService templateService; 057 058 /** 059 * Velocity Navigations extending this class should override this 060 * method to perform any particular business logic and add 061 * information to the context. 062 * 063 * @param pipelineData Turbine information. 064 * @param context Context for web pages. 065 * @throws Exception a generic exception. 066 */ 067 protected void doBuildTemplate(PipelineData pipelineData, 068 Context context) 069 throws Exception 070 { 071 // empty 072 } 073 074 /** 075 * Needs to be implemented to make TemplateNavigation like us. 076 * The actual method that you should override is the one with the 077 * context in the parameter list. 078 * 079 * @param pipelineData Turbine information. 080 * @throws Exception a generic exception. 081 */ 082 @Override 083 protected void doBuildTemplate(PipelineData pipelineData) 084 throws Exception 085 { 086 doBuildTemplate(pipelineData, velocity.getContext(pipelineData)); 087 } 088 089 /** 090 * This builds the Velocity template. 091 * 092 * @param pipelineData Turbine information. 093 * @return the content of the navigation module 094 * @throws Exception a generic exception. 095 */ 096 @Override 097 public String buildTemplate(PipelineData pipelineData) 098 throws Exception 099 { 100 RunData data = pipelineData.getRunData(); 101 Context context = velocity.getContext(pipelineData); 102 103 String navigationTemplate = data.getTemplateInfo().getNavigationTemplate(); 104 String templateName 105 = templateService.getNavigationTemplateName(navigationTemplate); 106 107 return velocity.handleRequest(context, prefix + templateName); 108 } 109}