1 package org.apache.turbine.modules.screens;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.turbine.annotation.TurbineService;
24 import org.apache.turbine.pipeline.PipelineData;
25 import org.apache.turbine.services.jsp.JspService;
26 import org.apache.turbine.services.template.TemplateService;
27 import org.apache.turbine.util.RunData;
28
29 /**
30 * Base JSP Screen that should be subclassed by screens that want to
31 * use JSP. Subclasses should override the doBuildTemplate() method.
32 *
33 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
34 * @author Frank Y. Kim
35 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
36 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
37 * @version $Id: BaseJspScreen.java 1709648 2015-10-20 17:08:10Z tv $
38 */
39 public class BaseJspScreen
40 extends TemplateScreen
41 {
42 /** The prefix for lookup up screen pages */
43 private String prefix = getPrefix() + "/";
44
45 /** Injected service instance */
46 @TurbineService
47 private JspService jspService;
48
49 /** Injected service instance */
50 @TurbineService
51 private TemplateService templateService;
52
53 /**
54 * Method that sets up beans and forward the request to the JSP.
55 *
56 * @param pipelineData Turbine information.
57 * @return null - the JSP sends the information.
58 * @exception Exception, a generic exception.
59 */
60 @Override
61 public String buildTemplate(PipelineData pipelineData)
62 throws Exception
63 {
64 RunData data = getRunData(pipelineData);
65 String screenTemplate = data.getTemplateInfo().getScreenTemplate();
66 // get the name of the template we want to use
67 String templateName
68 = templateService.getScreenTemplateName(screenTemplate);
69
70 // The Template Service could not find the Screen
71 if (StringUtils.isEmpty(templateName))
72 {
73 log.error("Screen " + screenTemplate + " not found!");
74 throw new Exception("Could not find screen for " + screenTemplate);
75 }
76
77 // let service know whether we are using a layout
78 jspService.handleRequest(pipelineData, prefix + templateName,
79 getLayout(pipelineData) == null);
80
81 return null;
82 }
83
84 /**
85 * Method to be overridden by subclasses to include data in beans, etc.
86 *
87 * @param pipelineData the PipelineData object
88 * @exception Exception, a generic exception.
89 */
90 @Override
91 protected void doBuildTemplate(PipelineData pipelineData)
92 throws Exception
93 {
94 // abstract method
95 }
96 }