001 package org.apache.turbine.modules.pages;
002
003
004 /*
005 * Licensed to the Apache Software Foundation (ASF) under one
006 * or more contributor license agreements. See the NOTICE file
007 * distributed with this work for additional information
008 * regarding copyright ownership. The ASF licenses this file
009 * to you under the Apache License, Version 2.0 (the
010 * "License"); you may not use this file except in compliance
011 * with the License. You may obtain a copy of the License at
012 *
013 * http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing,
016 * software distributed under the License is distributed on an
017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018 * KIND, either express or implied. See the License for the
019 * specific language governing permissions and limitations
020 * under the License.
021 */
022
023
024 import org.apache.turbine.pipeline.PipelineData;
025 import org.apache.turbine.services.template.TurbineTemplate;
026 import org.apache.turbine.util.RunData;
027 import org.apache.turbine.util.TurbineException;
028
029 /**
030 * When building sites using templates, Screens need only be defined
031 * for templates which require dynamic (database or object) data.
032 *
033 * <p>
034 *
035 * This page can be used on sites where the number of Screens can be
036 * much less than the number of templates. The templates can be
037 * grouped in directories with common layouts. Screen modules are
038 * then expected to be placed in packages corresponding with the
039 * templates' directories and follow a specific naming scheme.
040 *
041 * <p>
042 *
043 * The template parameter is parsed and and a Screen whose package
044 * matches the templates path and shares the same name minus any
045 * extension and beginning with a capital letter is searched for. If
046 * not found, a Screen in a package matching the template's path with
047 * name Default is searched for. If still not found, a Screen with
048 * name Default is looked for in packages corresponding to parent
049 * directories in the template's path until a match is found.
050 *
051 * <p>
052 *
053 * For example if data.getParameters().getString("template") returns
054 * /about_us/directions/driving.wm, the search follows
055 * about_us.directions.Driving, about_us.directions.Default,
056 * about_us.Default, Default, WebMacroSiteScreen (i.e. the default
057 * screen set in TurbineResources).
058 *
059 * <p>
060 *
061 * Only one Layout module is used, since it is expected that any
062 * dynamic content will be placed in navigations and screens. The
063 * layout template to be used is found in a similar way to the Screen.
064 * For example the following paths will be searched in the layouts
065 * subdirectory: /about_us/directions/driving.wm,
066 * /about_us/directions/default.wm, /about_us/default.wm, /default.wm,
067 * where wm is the value of the template.default.extension property.
068 *
069 * <p>
070 *
071 * This approach allows a site with largely static content to be
072 * updated and added to regularly by those with little Java
073 * experience.
074 *
075 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
076 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
077 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
078 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
079 * @version $Id: TemplatePage.java 1078552 2011-03-06 19:58:46Z tv $
080 */
081 public class TemplatePage
082 extends DefaultPage
083 {
084 /**
085 * Works with TemplateService to set up default templates and
086 * corresponding class modules.
087 *
088 * @param data Turbine information.
089 * @exception Exception, a generic exception.
090 */
091 @Override
092 protected void doBuildAfterAction(RunData data)
093 throws Exception
094 {
095 // The Template Service at this point must fetch the Screen class
096 // to match a given template. If the Screen class has already been
097 // set by an action, skip this, because the user has the already
098 // specified the Screen class he wants to use.
099 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 String template = data.getTemplateInfo().getScreenTemplate();
105
106 // Get the layout template and the correct Screen.
107 String layoutTemplate =
108 TurbineTemplate.getLayoutTemplateName(template);
109 data.getTemplateInfo().setLayoutTemplate(layoutTemplate);
110
111 String screen = TurbineTemplate.getScreenName(template);
112
113 if (screen == null)
114 {
115 String errMsg = "Couldn't map Template "
116 + template + " to any Screen class!";
117 log.error(errMsg);
118 throw new TurbineException(errMsg);
119 }
120 data.setScreen(screen);
121 }
122 }
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 RunData data = getRunData(pipelineData);
136 doBuildAfterAction(data);
137 }
138
139
140
141 }