1 package org.apache.turbine.util.template;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import org.apache.ecs.ConcreteElement;
23
24 import org.apache.turbine.modules.ScreenLoader;
25 import org.apache.turbine.util.RunData;
26
27 /***
28 * Returns output of a Screen module. An instance of this is
29 * placed in the Velocity context by the VelocityDirectLayout. This
30 * allows the screen to be executed only at rendering.
31 * Here's how it's used in a template:
32 *
33 * <p>
34 * <code>
35 * $screen_placeholder
36 * </code>
37 * <p>
38 * <code>
39 * $screen_placeholder.setScreen("Test")
40 * </code>
41 * </p>
42 *
43 * @author <a href="raphael@apache.org">Raphaël Luta</a>
44 * @version $Id: TemplateScreen.java 278958 2005-09-06 09:35:39Z henning $
45 */
46 public class TemplateScreen
47 {
48 /*** Logging */
49 private static Log log = LogFactory.getLog(TemplateScreen.class);
50
51
52 private RunData data;
53
54
55 private String screen;
56
57 /***
58 * Constructor
59 *
60 * @param data A Turbine RunData object.
61 */
62 public TemplateScreen(RunData data)
63 {
64 this.data = data;
65 this.screen = data.getScreen();
66 }
67
68 /***
69 * Set the screen.
70 *
71 * @param screen A String with the name of the screen module
72 * @return A TemplateScreen (self).
73 */
74 public TemplateScreen setScreen(String screen)
75 {
76 this.screen = screen;
77 return this;
78 }
79
80 /***
81 * Builds the output of the navigation template.
82 *
83 * @return A String.
84 */
85 public String toString()
86 {
87 String returnValue = "";
88
89 try
90 {
91 ConcreteElement results = ScreenLoader.getInstance()
92 .eval(data, this.screen);
93
94 if (results != null)
95 {
96 returnValue = results.toString();
97 }
98 }
99 catch (Exception e)
100 {
101 log.error(e);
102 }
103
104 return returnValue;
105 }
106 }