KickJava   Java API By Example, From Geeks To Geeks.

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


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.portlet.PortletException;
26 import javax.servlet.ServletConfig JavaDoc;
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.core.PortletContainerFactory;
35 import org.apache.pluto.portalImpl.services.ServiceManager;
36 import org.apache.pluto.services.information.InformationProviderAccess;
37 import org.infoglue.deliver.portal.information.DynamicInformationProviderIG;
38 import org.infoglue.deliver.portal.services.PortletWindowRegistryService;
39
40 /**
41  * This class handles portlet action requests. Determines if a request is a portlet action
42  * and executes the action if so.
43  *
44  * @author robert lerner
45  * @author jan danils
46  * @author jöran stark
47  */

48 public class PortalService
49 {
50     private static final Log log = LogFactory.getLog(PortalService.class);
51
52     /**
53      * Determines wether a portlet action request is beeing sent and delegates that to the
54      * portlet container.
55      * In case of an action request a redirect is issued in order to encode state parameters in
56      * the path-part of the url.
57      * @param request
58      * @param response
59      * @return true if an action request is sent false otherwise.
60      * @throws PortalException
61      */

62     
63     public boolean service(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws PortalException
64     {
65         log.debug("*** service start");
66         ServletConfig JavaDoc cfg = ServletConfigContainer.getContainer().getServletConfig();
67         if (cfg == null)
68         {
69             throw new RuntimeException JavaDoc("ServletConfig is null (the PortalServletDispatcher should initiate it)");
70         }
71
72         // -- Check if the request is a portlet action...
73
String JavaDoc portletWindowId = null;
74         
75         try
76         {
77             DynamicInformationProviderIG provider = (DynamicInformationProviderIG) InformationProviderAccess.getDynamicProvider(request);
78             portletWindowId = provider.getPortalURL().getActionWindowID();
79         }
80         catch (Throwable JavaDoc e)
81         {
82             log.error("Failed to locate DynamicInformationProviderIG", e);
83             throw new PortalException(e);
84         }
85
86         // Do we have a portlet-action?
87
if (portletWindowId == null)
88         {
89             log.debug("null actionwindow - no actionrequest returning false");
90             return false;
91         }
92         else
93         {
94             log.debug("actionwindow found [" + portletWindowId + "]");
95         }
96
97         // Locate portlet-window instance
98
PortletWindowRegistryService windowService = (PortletWindowRegistryService) ServiceManager.getService(PortletWindowRegistryService.class);
99         PortletWindow actionWindow = windowService.getPortletWindow(portletWindowId);
100
101         if (actionWindow == null)
102         {
103             log.error("PortletWindow action requested but not found: " + portletWindowId);
104             return false;
105         }
106
107         // -- now that we got everything we need - send the action to the portletcontainer
108
try
109         {
110             log.debug("ask container to process portlet action");
111             PortletContainerFactory.getPortletContainer().processPortletAction(actionWindow, request, response);
112             log.debug("action sent and executed without exception");
113         }
114         catch (PortletException e)
115         {
116             log.error("PortletException: ", e);
117             throw new PortalException(e);
118         }
119         catch (PortletContainerException e)
120         {
121             log.error("PortletContainerException: ", e);
122             throw new PortalException(e);
123         }
124         // This catch block is for compliance
125
// of TCK's Portlet.ProcessActionIOExceptionTest
126
catch (Exception JavaDoc e)
127         {
128             log.error("Unknown exception [" + e.getClass().getName() + "]", e);
129             throw new PortalException(e);
130         }
131
132         return true;
133     }
134
135 }
Popular Tags