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: NavigationLoader.java 1709648 2015-10-20 17:08:10Z tv $
033 */
034public class NavigationLoader
035    extends GenericLoader<Navigation>
036    implements Loader<Navigation>
037{
038    /** The single instance of this class. */
039    private static NavigationLoader instance = new NavigationLoader();
040
041    /**
042     * These ctor's are private to force clients to use getInstance()
043     * to access this class.
044     */
045    private NavigationLoader()
046    {
047        super();
048    }
049
050    /**
051     * Attempts to load and execute the external Navigation. This is
052     * used when you want to execute a Navigation which returns its
053     * output via a MultiPartElement instead of out the data.getPage()
054     * value.  This allows you to easily chain the execution of
055     * Navigation modules together.
056     *
057     * @param pipelineData Turbine information.
058     * @param name Name of object that will execute the navigation.
059     * @return the navigation module output
060     * @exception Exception a generic exception.
061     */
062    public String eval(PipelineData pipelineData, String name)
063            throws Exception
064    {
065        // Execute Navigation
066        return getAssembler(name).build(pipelineData);
067    }
068
069    /**
070     * Attempts to load and execute the external Navigation.
071     *
072     * @param pipelineData Turbine information.
073     * @param name Name of object instance.
074     * @exception Exception a generic exception.
075     */
076    @Override
077    public void exec(PipelineData pipelineData, String name)
078                throws Exception
079    {
080        this.eval(pipelineData, name);
081    }
082
083    /**
084     * Pulls out an instance of the object by name.  Name is just the
085     * single name of the object.
086     *
087     * @param name Name of object instance.
088     * @return A Layout with the specified name, or null.
089     * @exception Exception a generic exception.
090     */
091    @Override
092    public Navigation getAssembler(String name)
093        throws Exception
094    {
095        return getAssembler(Navigation.class, name);
096    }
097
098    /**
099     * @see org.apache.turbine.modules.Loader#getCacheSize()
100     */
101    @Override
102    public int getCacheSize()
103    {
104        return NavigationLoader.getConfiguredCacheSize();
105    }
106
107    /**
108     * The method through which this class is accessed.
109     *
110     * @return The single instance of this class.
111     */
112    public static NavigationLoader getInstance()
113    {
114        return instance;
115    }
116
117    /**
118     * Helper method to get the configured cache size for this module
119     *
120     * @return the configure cache size
121     */
122    private static int getConfiguredCacheSize()
123    {
124        return Turbine.getConfiguration().getInt(Navigation.CACHE_SIZE_KEY,
125                Navigation.CACHE_SIZE_DEFAULT);
126    }
127}