1 package org.apache.turbine.util.template;
2
3
4 import org.apache.logging.log4j.LogManager;
5
6 /*
7 * Licensed to the Apache Software Foundation (ASF) under one
8 * or more contributor license agreements. See the NOTICE file
9 * distributed with this work for additional information
10 * regarding copyright ownership. The ASF licenses this file
11 * to you under the Apache License, Version 2.0 (the
12 * "License"); you may not use this file except in compliance
13 * with the License. You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing,
18 * software distributed under the License is distributed on an
19 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20 * KIND, either express or implied. See the License for the
21 * specific language governing permissions and limitations
22 * under the License.
23 */
24
25
26 import org.apache.logging.log4j.Logger;
27 import org.apache.turbine.modules.ScreenLoader;
28 import org.apache.turbine.pipeline.PipelineData;
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$
48 */
49 public class TemplateScreen
50 {
51 /** Logging */
52 private static final Logger log = LogManager.getLogger(TemplateScreen.class);
53
54 /* The PipelineData object. */
55 private final PipelineData pipelineData;
56
57 /* The name of the screen template. */
58 private String screen;
59
60 /**
61 * Constructor
62 *
63 * @param pipelineData A Turbine PipelineData object.
64 */
65 public TemplateScreen(PipelineData pipelineData)
66 {
67 this.pipelineData = pipelineData;
68 this.screen = pipelineData.getRunData().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 @Override
89 public String toString()
90 {
91 String returnValue = "";
92
93 try
94 {
95 String results = ScreenLoader.getInstance().eval(pipelineData, this.screen);
96
97 if (results != null)
98 {
99 returnValue = results;
100 }
101 }
102 catch (Exception e)
103 {
104 log.error(e);
105 }
106
107 return returnValue;
108 }
109 }