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