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