001package org.apache.turbine.modules;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.turbine.Turbine;
023import org.apache.turbine.pipeline.PipelineData;
024
025/**
026 * The purpose of this class is to allow one to load and execute
027 * Navigation modules.
028 *
029 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
030 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
031 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
032 * @version $Id$
033 */
034public class NavigationLoader
035    extends GenericLoader<Navigation>
036{
037    /** The single instance of this class. */
038    private static NavigationLoader instance = new NavigationLoader();
039
040    /**
041     * These ctor's are private to force clients to use getInstance()
042     * to access this class.
043     */
044    private NavigationLoader()
045    {
046        super(Navigation.class,
047                () -> Turbine.getConfiguration().getInt(Navigation.CACHE_SIZE_KEY,
048                        Navigation.CACHE_SIZE_DEFAULT));
049    }
050
051    /**
052     * Attempts to load and execute the external Navigation. This is
053     * used when you want to execute a Navigation which returns its
054     * output via a MultiPartElement instead of out the data.getPage()
055     * value.  This allows you to easily chain the execution of
056     * Navigation modules together.
057     *
058     * @param pipelineData Turbine information.
059     * @param name Name of object that will execute the navigation.
060     * @return the navigation module output
061     * @throws Exception a generic exception.
062     */
063    public String eval(PipelineData pipelineData, String name)
064            throws Exception
065    {
066        // Execute Navigation
067        return getAssembler(name).build(pipelineData);
068    }
069
070    /**
071     * Attempts to load and execute the external Navigation.
072     *
073     * @param pipelineData Turbine information.
074     * @param name Name of object instance.
075     * @throws Exception a generic exception.
076     */
077    @Override
078    public void exec(PipelineData pipelineData, String name)
079                throws Exception
080    {
081        this.eval(pipelineData, name);
082    }
083
084    /**
085     * The method through which this class is accessed.
086     *
087     * @return The single instance of this class.
088     */
089    public static NavigationLoader getInstance()
090    {
091        return instance;
092    }
093}