001    package org.apache.turbine.modules.screens;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.commons.lang.StringUtils;
023    import org.apache.ecs.ConcreteElement;
024    import org.apache.turbine.pipeline.PipelineData;
025    import org.apache.turbine.services.jsp.TurbineJsp;
026    import org.apache.turbine.services.template.TurbineTemplate;
027    import org.apache.turbine.util.RunData;
028    
029    /**
030     * Base JSP Screen that should be subclassed by screens that want to
031     * use JSP.  Subclasses should override the doBuildTemplate() method.
032     *
033     * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
034     * @author Frank Y. Kim
035     * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
036     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
037     * @version $Id: BaseJspScreen.java 938645 2010-04-27 20:57:51Z tv $
038     */
039    public class BaseJspScreen
040            extends TemplateScreen
041    {
042        /** The prefix for lookup up screen pages */
043        private String prefix = getPrefix() + "/";
044    
045        /**
046         * Method that sets up beans and forward the request to the JSP.
047         *
048         * @deprecated Use PipelineData version instead.
049         * @param data Turbine information.
050         * @return null - the JSP sends the information.
051         * @exception Exception, a generic exception.
052         */
053        public ConcreteElement buildTemplate(RunData data)
054                throws Exception
055        {
056            String screenTemplate = data.getTemplateInfo().getScreenTemplate();
057            // get the name of the JSP we want to use
058            String templateName
059                = TurbineTemplate.getScreenTemplateName(screenTemplate);
060    
061            // The Template Service could not find the Screen
062            if (StringUtils.isEmpty(templateName))
063            {
064                log.error("Screen " + screenTemplate + " not found!");
065                throw new Exception("Could not find screen for " + screenTemplate);
066            }
067    
068            // let service know whether we are using a layout
069            TurbineJsp.handleRequest(data, prefix + templateName,
070                                     getLayout(data) == null);
071    
072            return null;
073        }
074    
075        /**
076         * Method that sets up beans and forward the request to the JSP.
077         *
078         * @param data Turbine information.
079         * @return null - the JSP sends the information.
080         * @exception Exception, a generic exception.
081         */
082        public ConcreteElement buildTemplate(PipelineData pipelineData)
083                throws Exception
084        {
085            RunData data = getRunData(pipelineData);
086            String screenTemplate = data.getTemplateInfo().getScreenTemplate();
087            // get the name of the JSP we want to use
088            String templateName
089                = TurbineTemplate.getScreenTemplateName(screenTemplate);
090    
091            // The Template Service could not find the Screen
092            if (StringUtils.isEmpty(templateName))
093            {
094                log.error("Screen " + screenTemplate + " not found!");
095                throw new Exception("Could not find screen for " + screenTemplate);
096            }
097    
098            // let service know whether we are using a layout
099            TurbineJsp.handleRequest(pipelineData, prefix + templateName,
100                                     getLayout(pipelineData) == null);
101    
102            return null;
103        }
104    
105        /**
106         * Method to be overidden by subclasses to include data in beans, etc.
107         *
108         * @deprecated Use PipelineData version instead.
109         * @param data, the Rundata object
110         * @exception Exception, a generic exception.
111         */
112        protected void doBuildTemplate(RunData data)
113            throws Exception
114        {
115            // abstract method
116        }
117    
118        /**
119         * Method to be overidden by subclasses to include data in beans, etc.
120         *
121         * @param data, the Rundata object
122         * @exception Exception, a generic exception.
123         */
124        protected void doBuildTemplate(PipelineData pipelineData)
125            throws Exception
126        {
127            // abstract method
128        }
129    
130    }