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.jsp.JspService;
028import org.apache.turbine.util.RunData;
029
030/**
031 * Base JSP navigation that should be subclassed by Navigation that want to
032 * use JSP.  Subclasses should override the doBuildTemplate() method.
033 *
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: BaseJspNavigation.java 1709648 2015-10-20 17:08:10Z tv $
038 */
039public class BaseJspNavigation
040        extends TemplateNavigation
041{
042    /** The prefix for lookup up navigation pages */
043    private final String prefix = Navigation.PREFIX + "/";
044
045    /** Injected service instance */
046    @TurbineService
047    private JspService jspService;
048
049    /**
050     * Method to be overridden by subclasses to include data in beans, etc.
051     *
052     * @param pipelineData the PipelineData object
053     * @throws Exception a generic exception.
054     */
055    @Override
056    protected void doBuildTemplate(PipelineData pipelineData)
057        throws Exception
058    {
059        // empty
060    }
061
062    /**
063     * Method that sets up beans and forward the request to the JSP.
064     *
065     * @param pipelineData the PipelineData object
066     * @return null - the JSP sends the information
067     * @throws Exception a generic exception.
068     */
069    @Override
070    public String buildTemplate(PipelineData pipelineData)
071        throws Exception
072    {
073        RunData data = getRunData(pipelineData);
074        // get the name of the JSP we want to use
075        String templateName = data.getTemplateInfo().getNavigationTemplate();
076
077        // navigations are used by a layout
078        jspService.handleRequest(pipelineData, prefix + templateName);
079        return null;
080    }
081}