1 package org.apache.turbine.modules.pages;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.turbine.services.template.TurbineTemplate;
23 import org.apache.turbine.util.RunData;
24 import org.apache.turbine.util.TurbineException;
25
26 /***
27 * When building sites using templates, Screens need only be defined
28 * for templates which require dynamic (database or object) data.
29 *
30 * <p>
31 *
32 * This page can be used on sites where the number of Screens can be
33 * much less than the number of templates. The templates can be
34 * grouped in directories with common layouts. Screen modules are
35 * then expected to be placed in packages corresponding with the
36 * templates' directories and follow a specific naming scheme.
37 *
38 * <p>
39 *
40 * The template parameter is parsed and and a Screen whose package
41 * matches the templates path and shares the same name minus any
42 * extension and beginning with a capital letter is searched for. If
43 * not found, a Screen in a package matching the template's path with
44 * name Default is searched for. If still not found, a Screen with
45 * name Default is looked for in packages corresponding to parent
46 * directories in the template's path until a match is found.
47 *
48 * <p>
49 *
50 * For example if data.getParameters().getString("template") returns
51 * /about_us/directions/driving.wm, the search follows
52 * about_us.directions.Driving, about_us.directions.Default,
53 * about_us.Default, Default, WebMacroSiteScreen (i.e. the default
54 * screen set in TurbineResources).
55 *
56 * <p>
57 *
58 * Only one Layout module is used, since it is expected that any
59 * dynamic content will be placed in navigations and screens. The
60 * layout template to be used is found in a similar way to the Screen.
61 * For example the following paths will be searched in the layouts
62 * subdirectory: /about_us/directions/driving.wm,
63 * /about_us/directions/default.wm, /about_us/default.wm, /default.wm,
64 * where wm is the value of the template.default.extension property.
65 *
66 * <p>
67 *
68 * This approach allows a site with largely static content to be
69 * updated and added to regularly by those with little Java
70 * experience.
71 *
72 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
73 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
74 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
75 * @version $Id: TemplatePage.java 534527 2007-05-02 16:10:59Z tv $
76 */
77 public class TemplatePage
78 extends DefaultPage
79 {
80 /***
81 * Works with TemplateService to set up default templates and
82 * corresponding class modules.
83 *
84 * @param data Turbine information.
85 * @exception Exception, a generic exception.
86 */
87 protected void doBuildAfterAction(RunData data)
88 throws Exception
89 {
90
91
92
93
94 if (!data.hasScreen())
95 {
96
97
98
99 String template = data.getTemplateInfo().getScreenTemplate();
100
101
102 String layoutTemplate =
103 TurbineTemplate.getLayoutTemplateName(template);
104 data.getTemplateInfo().setLayoutTemplate(layoutTemplate);
105
106 String screen = TurbineTemplate.getScreenName(template);
107
108 if (screen == null)
109 {
110 String errMsg = "Couldn't map Template "
111 + template + " to any Screen class!";
112 log.error(errMsg);
113 throw new TurbineException(errMsg);
114 }
115 data.setScreen(screen);
116 }
117 }
118 }