%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.turbine.util.template.TemplateScreen |
|
|
1 | package org.apache.turbine.util.template; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 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 278958 2005-09-06 09:35:39Z henning $ |
|
45 | */ |
|
46 | public class TemplateScreen |
|
47 | { |
|
48 | /** Logging */ |
|
49 | 0 | 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 screen; |
|
56 | ||
57 | /** |
|
58 | * Constructor |
|
59 | * |
|
60 | * @param data A Turbine RunData object. |
|
61 | */ |
|
62 | public TemplateScreen(RunData data) |
|
63 | 0 | { |
64 | 0 | this.data = data; |
65 | 0 | this.screen = data.getScreen(); |
66 | 0 | } |
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 | 0 | this.screen = screen; |
77 | 0 | 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 | 0 | String returnValue = ""; |
88 | ||
89 | try |
|
90 | { |
|
91 | 0 | ConcreteElement results = ScreenLoader.getInstance() |
92 | .eval(data, this.screen); |
|
93 | ||
94 | 0 | if (results != null) |
95 | { |
|
96 | 0 | returnValue = results.toString(); |
97 | } |
|
98 | } |
|
99 | 0 | catch (Exception e) |
100 | { |
|
101 | 0 | log.error(e); |
102 | 0 | } |
103 | ||
104 | 0 | return class="keyword">returnValue; |
105 | } |
|
106 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |