View Javadoc

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  
17  
18  package org.apache.jetspeed.portal.portlets;
19  
20  import org.apache.ecs.ConcreteElement;
21  import org.apache.ecs.StringElement;
22  
23  import org.apache.jetspeed.portal.PortletConfig;
24  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
25  import org.apache.jetspeed.services.logging.JetspeedLogger;
26  import org.apache.jetspeed.portal.portlets.AbstractPortlet;
27  import org.apache.jetspeed.util.servlet.EcsServletElement;
28  
29  import org.apache.turbine.util.RunData;
30  
31  /***
32   * The ServletInvokerPortlet invokes a servlet or JSP and displays the result.
33   * 
34   * @author Thomas Schaeck (schaeck@de.ibm.com)
35   */
36  public class ServletInvokerPortlet extends AbstractPortlet 
37  {
38  
39      /***
40       * Static initialization of the logger for this class
41       */    
42      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ServletInvokerPortlet.class.getName());    
43  
44    /***
45     * Returns an ECS concrete element that includes the servlet/JSP.
46     *
47     * The servlet/JSP will be invoked when the ECS tree is written 
48     * to the servlet output stream and add its output to the stream.
49     */
50    public ConcreteElement getContent(RunData rundata) {
51  	// !!! Need to check this - is this the right rundata object ? !!!
52  	PortletConfig pc = this.getPortletConfig();
53  
54  	String servletURL = null;
55  	try {
56  	  servletURL = (String) this.getPortletConfig().getInitParameter("url");
57  	  return new EcsServletElement(rundata, servletURL);
58  	} catch (Exception e) {
59  	  String message = "ServletInvokerPortlet: Error invoking " 
60  					   + servletURL + ": " + e.getMessage();
61  	  logger.error(message, e);
62  	  return new StringElement(message);
63  	}
64    }    }