1 package org.apache.turbine.modules;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.turbine.Turbine;
23 import org.apache.turbine.pipeline.PipelineData;
24
25 /**
26 * The purpose of this class is to allow one to load and execute
27 * Navigation modules.
28 *
29 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
30 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
31 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
32 * @version $Id: NavigationLoader.java 1709648 2015-10-20 17:08:10Z tv $
33 */
34 public class NavigationLoader
35 extends GenericLoader<Navigation>
36 implements Loader<Navigation>
37 {
38 /** The single instance of this class. */
39 private static NavigationLoader instance = new NavigationLoader();
40
41 /**
42 * These ctor's are private to force clients to use getInstance()
43 * to access this class.
44 */
45 private NavigationLoader()
46 {
47 super();
48 }
49
50 /**
51 * Attempts to load and execute the external Navigation. This is
52 * used when you want to execute a Navigation which returns its
53 * output via a MultiPartElement instead of out the data.getPage()
54 * value. This allows you to easily chain the execution of
55 * Navigation modules together.
56 *
57 * @param pipelineData Turbine information.
58 * @param name Name of object that will execute the navigation.
59 * @return the navigation module output
60 * @exception Exception a generic exception.
61 */
62 public String eval(PipelineData pipelineData, String name)
63 throws Exception
64 {
65 // Execute Navigation
66 return getAssembler(name).build(pipelineData);
67 }
68
69 /**
70 * Attempts to load and execute the external Navigation.
71 *
72 * @param pipelineData Turbine information.
73 * @param name Name of object instance.
74 * @exception Exception a generic exception.
75 */
76 @Override
77 public void exec(PipelineData pipelineData, String name)
78 throws Exception
79 {
80 this.eval(pipelineData, name);
81 }
82
83 /**
84 * Pulls out an instance of the object by name. Name is just the
85 * single name of the object.
86 *
87 * @param name Name of object instance.
88 * @return A Layout with the specified name, or null.
89 * @exception Exception a generic exception.
90 */
91 @Override
92 public Navigation getAssembler(String name)
93 throws Exception
94 {
95 return getAssembler(Navigation.class, name);
96 }
97
98 /**
99 * @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 }