Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
VelocityOnlyLayout |
|
| 1.0;1 |
1 | package org.apache.turbine.modules.layouts; | |
2 | ||
3 | ||
4 | /* | |
5 | * Licensed to the Apache Software Foundation (ASF) under one | |
6 | * or more contributor license agreements. See the NOTICE file | |
7 | * distributed with this work for additional information | |
8 | * regarding copyright ownership. The ASF licenses this file | |
9 | * to you under the Apache License, Version 2.0 (the | |
10 | * "License"); you may not use this file except in compliance | |
11 | * with the License. You may obtain a copy of the License at | |
12 | * | |
13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
14 | * | |
15 | * Unless required by applicable law or agreed to in writing, | |
16 | * software distributed under the License is distributed on an | |
17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
18 | * KIND, either express or implied. See the License for the | |
19 | * specific language governing permissions and limitations | |
20 | * under the License. | |
21 | */ | |
22 | ||
23 | ||
24 | import org.apache.commons.lang3.StringUtils; | |
25 | import org.apache.turbine.TurbineConstants; | |
26 | import org.apache.turbine.annotation.TurbineLoader; | |
27 | import org.apache.turbine.modules.Screen; | |
28 | import org.apache.turbine.modules.ScreenLoader; | |
29 | import org.apache.turbine.pipeline.PipelineData; | |
30 | import org.apache.turbine.util.template.TemplateNavigation; | |
31 | import org.apache.velocity.context.Context; | |
32 | ||
33 | /** | |
34 | * This Layout module allows Velocity templates to be used as layouts. | |
35 | * Since dynamic content is supposed to be primarily located in | |
36 | * screens and navigations there should be relatively few reasons to | |
37 | * subclass this Layout. | |
38 | * | |
39 | * To get the same functionality as with VelocityECSLayout, you can use two | |
40 | * supplied VelocityMacros, TurbineHtmlHead and TurbineHtmlBodyAttributes | |
41 | * in your templates. These are used to put HtmlPageAttributes into a page | |
42 | * before rendering. | |
43 | * | |
44 | * Use these macros should be used in the Layout template like this: | |
45 | * | |
46 | * ... set things like style sheets, scripts here. | |
47 | * <html> | |
48 | * #TurbineHtmlHead() | |
49 | * <body #TurbineHtmlBodyAttributes() > | |
50 | * .... your body information | |
51 | * </body> | |
52 | * </html> | |
53 | * | |
54 | * As the layout template is rendered _after_ the screen template, you | |
55 | * can of course, add information to the $page tool in your screen template. | |
56 | * This will be added correctly to the <head>...</head> and | |
57 | * <body> tags. | |
58 | * | |
59 | * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> | |
60 | * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> | |
61 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> | |
62 | * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> | |
63 | * @version $Id: VelocityOnlyLayout.java 1854797 2019-03-04 20:41:39Z tv $ | |
64 | */ | |
65 | 27 | public class VelocityOnlyLayout extends VelocityLayout |
66 | { | |
67 | /** Injected loader instance */ | |
68 | @TurbineLoader( Screen.class ) | |
69 | private ScreenLoader screenLoader; | |
70 | ||
71 | /** | |
72 | * @see org.apache.turbine.modules.layouts.VelocityLayout#populateContext(org.apache.turbine.pipeline.PipelineData, org.apache.velocity.context.Context) | |
73 | */ | |
74 | @Override | |
75 | protected void populateContext(PipelineData pipelineData, Context context) throws Exception | |
76 | { | |
77 | 12 | String screenName = pipelineData.getRunData().getScreen(); |
78 | ||
79 | 12 | log.debug("Loading Screen {}", screenName); |
80 | ||
81 | // First, generate the screen and put it in the context so | |
82 | // we can grab it the layout template. | |
83 | 12 | String results = screenLoader.eval(pipelineData, screenName); |
84 | 6 | String returnValue = StringUtils.defaultIfEmpty(results, StringUtils.EMPTY); |
85 | ||
86 | // variable for the screen in the layout template | |
87 | 6 | context.put(TurbineConstants.SCREEN_PLACEHOLDER, returnValue); |
88 | ||
89 | // variable to reference the navigation screen in the layout template | |
90 | 6 | context.put(TurbineConstants.NAVIGATION_PLACEHOLDER, |
91 | new TemplateNavigation(pipelineData)); | |
92 | 6 | } |
93 | } |