KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > util > template > JspTemplate


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.jetspeed.util.template;
17
18 import org.apache.log4j.Logger;
19 import org.apache.turbine.services.TurbineServices;
20 import org.apache.turbine.services.jsp.JspService;
21 import org.apache.turbine.util.RunData;
22 import org.apache.turbine.util.TurbineException;
23
24 /**
25  * JspTemplate
26  *
27  * @author <a HREF="mailto:junyang@cisco.com">Jun Yang</a>
28  * @version $Id: JspTemplate.java,v 1.2 2004/02/23 03:20:46 jford Exp $
29  */

30 public class JspTemplate
31 {
32     protected RunData runData;
33     protected String JavaDoc templateName;
34     private static Logger logger = Logger.getLogger(JspTemplate.class);
35     public JspTemplate(RunData runData, String JavaDoc templateName)
36     {
37         this.runData = runData;
38         this.templateName = templateName;
39     }
40
41     public String JavaDoc getContent()
42     {
43         JspService jsp = (JspService) TurbineServices.getInstance().getService(JspService.SERVICE_NAME);
44         try
45         {
46             jsp.handleRequest(this.runData, this.templateName);
47         }
48         catch (TurbineException te1)
49         {
50             if (!this.templateName.endsWith(".jsp"))
51             {
52                 try
53                 {
54                     jsp.handleRequest(this.runData, this.templateName + ".jsp");
55                 }
56                 catch (TurbineException te2)
57                 {
58                     logger.error("failed to invoke JSP Template '" +
59                                     this.templateName + "' and '" + this.templateName + ".jsp'", te2);
60                 }
61             }
62             else
63             {
64                 logger.error("failed to invoke JSP Template '" + this.templateName + "'", te1);
65             }
66         }
67         
68         return "";
69     }
70 }
71
Popular Tags