View Javadoc

1   package org.apache.turbine.util.template;
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.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      /* The RunData object. */
55      private RunData data;
56  
57      /* The name of the screen template. */
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 }