Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TemplatePage |
|
| 2.5;2,5 |
1 | package org.apache.turbine.modules.pages; | |
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.turbine.pipeline.PipelineData; | |
25 | import org.apache.turbine.services.template.TurbineTemplate; | |
26 | import org.apache.turbine.util.RunData; | |
27 | import org.apache.turbine.util.TurbineException; | |
28 | ||
29 | /** | |
30 | * When building sites using templates, Screens need only be defined | |
31 | * for templates which require dynamic (database or object) data. | |
32 | * | |
33 | * <p> | |
34 | * | |
35 | * This page can be used on sites where the number of Screens can be | |
36 | * much less than the number of templates. The templates can be | |
37 | * grouped in directories with common layouts. Screen modules are | |
38 | * then expected to be placed in packages corresponding with the | |
39 | * templates' directories and follow a specific naming scheme. | |
40 | * | |
41 | * <p> | |
42 | * | |
43 | * The template parameter is parsed and and a Screen whose package | |
44 | * matches the templates path and shares the same name minus any | |
45 | * extension and beginning with a capital letter is searched for. If | |
46 | * not found, a Screen in a package matching the template's path with | |
47 | * name Default is searched for. If still not found, a Screen with | |
48 | * name Default is looked for in packages corresponding to parent | |
49 | * directories in the template's path until a match is found. | |
50 | * | |
51 | * <p> | |
52 | * | |
53 | * For example if data.getParameters().getString("template") returns | |
54 | * /about_us/directions/driving.wm, the search follows | |
55 | * about_us.directions.Driving, about_us.directions.Default, | |
56 | * about_us.Default, Default, WebMacroSiteScreen (i.e. the default | |
57 | * screen set in TurbineResources). | |
58 | * | |
59 | * <p> | |
60 | * | |
61 | * Only one Layout module is used, since it is expected that any | |
62 | * dynamic content will be placed in navigations and screens. The | |
63 | * layout template to be used is found in a similar way to the Screen. | |
64 | * For example the following paths will be searched in the layouts | |
65 | * subdirectory: /about_us/directions/driving.wm, | |
66 | * /about_us/directions/default.wm, /about_us/default.wm, /default.wm, | |
67 | * where wm is the value of the template.default.extension property. | |
68 | * | |
69 | * <p> | |
70 | * | |
71 | * This approach allows a site with largely static content to be | |
72 | * updated and added to regularly by those with little Java | |
73 | * experience. | |
74 | * | |
75 | * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a> | |
76 | * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> | |
77 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> | |
78 | * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> | |
79 | * @version $Id: TemplatePage.java 1078552 2011-03-06 19:58:46Z tv $ | |
80 | */ | |
81 | 4 | public class TemplatePage |
82 | extends DefaultPage | |
83 | { | |
84 | /** | |
85 | * Works with TemplateService to set up default templates and | |
86 | * corresponding class modules. | |
87 | * | |
88 | * @param data Turbine information. | |
89 | * @exception Exception, a generic exception. | |
90 | */ | |
91 | @Override | |
92 | protected void doBuildAfterAction(RunData data) | |
93 | throws Exception | |
94 | { | |
95 | // The Template Service at this point must fetch the Screen class | |
96 | // to match a given template. If the Screen class has already been | |
97 | // set by an action, skip this, because the user has the already | |
98 | // specified the Screen class he wants to use. | |
99 | 4 | if (!data.hasScreen()) |
100 | { | |
101 | // This is effectively getting the "template" parameter | |
102 | // from the parameter parser in rundata. This is coming | |
103 | // from the request for a template. | |
104 | 4 | String template = data.getTemplateInfo().getScreenTemplate(); |
105 | ||
106 | // Get the layout template and the correct Screen. | |
107 | 4 | String layoutTemplate = |
108 | TurbineTemplate.getLayoutTemplateName(template); | |
109 | 4 | data.getTemplateInfo().setLayoutTemplate(layoutTemplate); |
110 | ||
111 | 4 | String screen = TurbineTemplate.getScreenName(template); |
112 | ||
113 | 4 | if (screen == null) |
114 | { | |
115 | 0 | String errMsg = "Couldn't map Template " |
116 | + template + " to any Screen class!"; | |
117 | 0 | log.error(errMsg); |
118 | 0 | throw new TurbineException(errMsg); |
119 | } | |
120 | 4 | data.setScreen(screen); |
121 | } | |
122 | 4 | } |
123 | ||
124 | /** | |
125 | * Works with TemplateService to set up default templates and | |
126 | * corresponding class modules. | |
127 | * | |
128 | * @param pipelineData Turbine information. | |
129 | * @exception Exception, a generic exception. | |
130 | */ | |
131 | @Override | |
132 | protected void doBuildAfterAction(PipelineData pipelineData) | |
133 | throws Exception | |
134 | { | |
135 | 4 | RunData data = getRunData(pipelineData); |
136 | 4 | doBuildAfterAction(data); |
137 | 4 | } |
138 | ||
139 | ||
140 | ||
141 | } |