001 package 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
022 import org.apache.ecs.ConcreteElement;
023 import org.apache.turbine.Turbine;
024 import org.apache.turbine.pipeline.PipelineData;
025 import org.apache.turbine.util.RunData;
026
027 /**
028 * The purpose of this class is to allow one to load and execute
029 * Navigation modules.
030 *
031 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
032 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
033 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
034 * @version $Id: NavigationLoader.java 1078552 2011-03-06 19:58:46Z tv $
035 */
036 public class NavigationLoader
037 extends GenericLoader<Navigation>
038 implements Loader<Navigation>
039 {
040 /** The single instance of this class. */
041 private static NavigationLoader instance = new NavigationLoader();
042
043 /**
044 * These ctor's are private to force clients to use getInstance()
045 * to access this class.
046 */
047 private NavigationLoader()
048 {
049 super();
050 }
051
052 /**
053 * Attempts to load and execute the external Navigation. This is
054 * used when you want to execute a Navigation which returns its
055 * output via a MultiPartElement instead of out the data.getPage()
056 * value. This allows you to easily chain the execution of
057 * Navigation modules together.
058 *
059 * @deprecated Use PipelineData version instead.
060 * @param data Turbine information.
061 * @param name Name of object that will execute the navigation.
062 * @exception Exception a generic exception.
063 */
064 @Deprecated
065 public ConcreteElement eval(RunData data, String name)
066 throws Exception
067 {
068 // Execute Navigation
069 return getAssembler(name).build(data);
070 }
071
072 /**
073 * Attempts to load and execute the external Navigation. This is
074 * used when you want to execute a Navigation which returns its
075 * output via a MultiPartElement instead of out the data.getPage()
076 * value. This allows you to easily chain the execution of
077 * Navigation modules together.
078 *
079 * @param data Turbine information.
080 * @param name Name of object that will execute the navigation.
081 * @exception Exception a generic exception.
082 */
083 public ConcreteElement eval(PipelineData pipelineData, String name)
084 throws Exception
085 {
086 // Execute Navigation
087 return getAssembler(name).build(pipelineData);
088 }
089
090
091 /**
092 * Attempts to load and execute the external Navigation.
093 * @deprecated Use PipelineData version instead.
094 * @param data Turbine information.
095 * @param name Name of object instance.
096 * @exception Exception a generic exception.
097 */
098 @Deprecated
099 @Override
100 public void exec(RunData data, String name)
101 throws Exception
102 {
103 this.eval(data, name);
104 }
105
106 /**
107 * Attempts to load and execute the external Navigation.
108 *
109 * @param pipelineData Turbine information.
110 * @param name Name of object instance.
111 * @exception Exception a generic exception.
112 */
113 @Override
114 public void exec(PipelineData pipelineData, String name)
115 throws Exception
116 {
117 this.eval(pipelineData, name);
118 }
119
120
121 /**
122 * Pulls out an instance of the object by name. Name is just the
123 * single name of the object. This is equal to getInstance but
124 * returns an Assembler object and is needed to fulfil the Loader
125 * interface.
126 *
127 * @param name Name of object instance.
128 * @return A Layout with the specified name, or null.
129 * @exception Exception a generic exception.
130 */
131 public Navigation getAssembler(String name)
132 throws Exception
133 {
134 return getAssembler(Navigation.NAME, name);
135 }
136
137 /**
138 * @see org.apache.turbine.modules.Loader#getCacheSize()
139 */
140 public int getCacheSize()
141 {
142 return NavigationLoader.getConfiguredCacheSize();
143 }
144
145 /**
146 * The method through which this class is accessed.
147 *
148 * @return The single instance of this class.
149 */
150 public static NavigationLoader getInstance()
151 {
152 return instance;
153 }
154
155 /**
156 * Helper method to get the configured cache size for this module
157 *
158 * @return the configure cache size
159 */
160 private static int getConfiguredCacheSize()
161 {
162 return Turbine.getConfiguration().getInt(Navigation.CACHE_SIZE_KEY,
163 Navigation.CACHE_SIZE_DEFAULT);
164 }
165 }