KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > portal > dispatcher > PortalServletDispatcher


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.dispatcher;
24
25 import java.util.Enumeration JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 import javax.servlet.ServletConfig JavaDoc;
29 import javax.servlet.ServletException JavaDoc;
30 import javax.servlet.http.HttpServletRequest JavaDoc;
31 import javax.servlet.http.HttpServletResponse JavaDoc;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35 import org.apache.pluto.PortletContainerServices;
36 import org.apache.pluto.portalImpl.core.PortletContainerEnvironment;
37 import org.apache.pluto.portalImpl.core.PortletContainerFactory;
38 import org.apache.pluto.portalImpl.factory.FactoryAccess;
39 import org.apache.pluto.portalImpl.services.ServiceManager;
40 import org.apache.pluto.portalImpl.services.factorymanager.FactoryManager;
41 import org.infoglue.deliver.portal.ServletConfigContainer;
42
43 /**
44  * Overides the webwork(1) servlet dispatcher in order to initiate the pluto
45  * services.
46  *
47  * @author robert lerner
48  * @author jan danils
49  * @author jöran stark
50  */

51 public class PortalServletDispatcher extends DeliveryServletDispatcher {
52
53     private static final Log log = LogFactory.getLog(PortalServletDispatcher.class);
54
55     public static final String JavaDoc PORTLET_CONTAINER_NAME = "portal_container_name";
56
57     private static String JavaDoc uniqueContainerName;
58
59     public void init(ServletConfig JavaDoc config) throws ServletException JavaDoc
60     {
61         log.debug("init of servlet");
62         // -- delegate to webwork servlet dispatcher init
63
super.init(config);
64
65         // -- init of infoglue portal singleton container for the servlet config
66
//TODO: un-singleton
67
ServletConfigContainer.getContainer().setServletConfig(config);
68
69         // -- start: init the pluto services -
70
try
71         {
72             ServiceManager.init(config);
73         }
74         catch (Throwable JavaDoc exc)
75         {
76             log.error("Initialization failed!", exc);
77             throw (new javax.servlet.UnavailableException JavaDoc("Initialization of one or more services failed."));
78         }
79
80         try
81         {
82             ServiceManager.postInit(config);
83         }
84         catch (Throwable JavaDoc expos)
85         {
86             log.error("Post initialization failed!", expos);
87             throw (new javax.servlet.UnavailableException JavaDoc("Post initialization of one or more services failed."));
88         }
89
90         if (!PortletContainerFactory.getPortletContainer().isInitialized())
91         {
92             uniqueContainerName = "pluto-" + System.currentTimeMillis();
93
94             if (log.isInfoEnabled())
95                 log.info("Initializing PortletContainer [" + uniqueContainerName + "]...");
96
97             PortletContainerEnvironment environment = new PortletContainerEnvironment();
98
99             environment.addContainerService(org.apache.pluto.portalImpl.services.log.Log.getService());
100             environment.addContainerService(FactoryManager.getService());
101             environment.addContainerService(FactoryAccess.getInformationProviderContainerService());
102             environment.addContainerService(FactoryAccess.getDynamicTitleContainerService());
103
104             Properties JavaDoc properties = new Properties JavaDoc();
105
106             try
107             {
108                 PortletContainerFactory.getPortletContainer().init(uniqueContainerName, config, environment, properties);
109             }
110             catch (Throwable JavaDoc exc)
111             {
112                 log.warn("Initialization of the portlet container failed!", exc);
113                 // throw (
114
// new javax.servlet.UnavailableException(
115
// "Initialization of the portlet container failed."));
116
}
117         }
118         else if (log.isInfoEnabled())
119         {
120             log.info("PortletContainer already initialized");
121         }
122
123         // RSS Portlet test-hack-fix
124
//System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.transformer.TransformerImpl");
125

126         log.info("Ready to serve you.");
127     }
128
129     public void destroy()
130     {
131         super.destroy();
132
133         if (log.isInfoEnabled())
134             log.info("Shutting down portlet container. . .");
135         try
136         {
137             PortletContainerFactory.getPortletContainer().shutdown();
138
139             // destroy all services
140
ServiceManager.destroy(getServletConfig());
141         }
142         catch (Throwable JavaDoc t)
143         {
144             log("Destruction failed!", t);
145         }
146     }
147
148     public void service(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp) throws ServletException JavaDoc
149     {
150         if (log.isDebugEnabled())
151         {
152             log.debug("\n******************************************** infogluePortal service()");
153             Enumeration JavaDoc enumeration = req.getParameterNames();
154             while (enumeration.hasMoreElements())
155             {
156                 String JavaDoc name = (String JavaDoc) enumeration.nextElement();
157                 Object JavaDoc o = req.getParameter(name);
158                 log.debug(name + "=" + o);
159             }
160
161             enumeration = req.getAttributeNames();
162             while (enumeration.hasMoreElements())
163             {
164                 String JavaDoc name = (String JavaDoc) enumeration.nextElement();
165                 Object JavaDoc o = req.getAttribute(name);
166                 log.debug(name + "=" + o);
167             }
168         }
169         // TODO not very nice, or?. Necessary to call before portlet execution.
170
PortletContainerServices.prepare(uniqueContainerName);
171         // Necessary to allow deliver parts to update portlet container when a new
172
// portlet is uploaded.
173
req.setAttribute(PORTLET_CONTAINER_NAME, uniqueContainerName);
174
175         // Delegate to super-servlet (infoglue)
176
super.service(req, resp);
177     }
178     
179
180 }
Popular Tags