KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > util > template > TemplateScreen


1 package org.apache.turbine.util.template;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
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,v 1.6.2.2 2004/05/20 03:27:23 seade Exp $
45  */

46 public class TemplateScreen
47 {
48     /** Logging */
49     private static Log log = LogFactory.getLog(TemplateScreen.class);
50
51     /* The RunData object. */
52     private RunData data;
53
54     /* The name of the screen template. */
55     private String JavaDoc 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 JavaDoc 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 JavaDoc toString()
86     {
87         String JavaDoc 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 JavaDoc e)
100         {
101             log.error(e);
102         }
103
104         return returnValue;
105     }
106 }
107
Popular Tags