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