KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > portal > PortalController


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.deliver.portal;
24
25 import javax.naming.NameNotFoundException JavaDoc;
26 import javax.portlet.PortletException;
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.pluto.PortletContainerException;
33 import org.apache.pluto.om.window.PortletWindow;
34 import org.apache.pluto.portalImpl.services.ServiceManager;
35 import org.infoglue.deliver.portal.services.PortletWindowRegistryService;
36
37 /**
38  * @author robert lerner
39  * @author jan danils
40  * @author jöran stark
41  */

42 public class PortalController {
43     public static final String JavaDoc NAME = "portalLogic";
44
45     private static final Log log = LogFactory.getLog(PortalController.class);
46
47     private HttpServletRequest JavaDoc request;
48
49     private HttpServletResponse JavaDoc response;
50
51     public PortalController(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
52         this.request = request;
53         this.response = response;
54     }
55
56     /**
57      * Render portlet
58      *
59      * @param portletID
60      * Unique identifier (myPortlet.MyPortletName of the portlet to
61      * be rendered
62      * @param windowId
63      * Unique identifier of the window that is to be rendered, if a
64      * PortletWindow with windowId don't exist in the registry it's
65      * created and added to the registry.
66      * @return the content the portlet produces
67      * @throws PortalException
68      */

69     public String JavaDoc renderFragment(String JavaDoc portletID, String JavaDoc windowID) throws NameNotFoundException JavaDoc, PortalException
70     {
71         PortletWindowIG window = getPortletWindow(portletID, windowID);
72         
73         return window.render();
74     }
75
76     /**
77      * Gets a PortletWindowIG for a portlet instance.
78      *
79      * @param portletID
80      * identifies the portlet instance.
81      * @param windowId
82      * Unique identifier of the window that is to be rendered, if a
83      * PortletWindow with windowId don't exist in the registry it's
84      * created and added to the registry.
85      * @return a PortletWindowIG for a portlet instance
86      * @throws NameNotFoundException
87      * thrown if the identifier is not bound to a portlet instance
88      * @throws PortalException
89      * thrown in case of an exception while initializing the
90      * portlet.
91      */

92     public PortletWindowIG getPortletWindow(String JavaDoc portletID, String JavaDoc windowID) throws NameNotFoundException JavaDoc, PortalException
93     {
94         try
95         {
96             PortletWindowRegistryService windowService = (PortletWindowRegistryService) ServiceManager.getService(PortletWindowRegistryService.class);
97             PortletWindow renderWindow = windowService.createPortletWindow(windowID, portletID);
98             log.info("Portlet window of " + portletID + "," + windowID + ": " + renderWindow);
99             return new PortletWindowIGImpl(renderWindow, request, response);
100         }
101         catch (PortletException e)
102         {
103             log.error("", e);
104             throw new PortalException(e);
105         }
106         catch (PortletContainerException e)
107         {
108             log.error("", e);
109             throw new PortalException(e);
110         }
111         catch (Throwable JavaDoc e)
112         {
113             log.error("", e);
114             throw new PortalException(e);
115         }
116     }
117 }
Popular Tags