You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2005/07/14 15:00:55 UTC
svn commit: r219037 - in /cocoon/branches/BRANCH_2_1_X: ./
src/blocks/portal/conf/
src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/
src/blocks/portal/java/org/apache/cocoon/portal/impl/
src/blocks/portal/java/org/apache/cocoon/porta...
Author: cziegeler
Date: Thu Jul 14 06:00:51 2005
New Revision: 219037
URL: http://svn.apache.org/viewcvs?rev=219037&view=rev
Log:
Convert PortletPortalManager into portal manager aspect.
Added:
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManagerAspect.java (with props)
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.xconf
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalManagerAspectChain.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManager.java
cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/PortletWindowAspect.java
cocoon/branches/BRANCH_2_1_X/status.xml
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.xconf
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.xconf?rev=219037&r1=219036&r2=219037&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.xconf (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.xconf Thu Jul 14 06:00:51 2005
@@ -17,8 +17,8 @@
<!-- SVN $Id$ -->
<xconf xpath="/cocoon" unless="component[@role='org.apache.cocoon.portal.event.aspect.EventAspectSelector']">
- <!-- Event Aspect configuration -->
- <component class="org.apache.cocoon.components.ExtendedComponentSelector" role="org.apache.cocoon.portal.event.aspect.EventAspectSelector">
+ <!-- Event Aspect configuration -->
+ <component class="org.apache.cocoon.components.ExtendedComponentSelector" role="org.apache.cocoon.portal.event.aspect.EventAspectSelector">
<aspect logger="portal" name="action-counter" class="org.apache.cocoon.portal.event.aspect.impl.ActionCounterEventAspect"/>
<aspect logger="portal" name="request-parameter" class="org.apache.cocoon.portal.event.aspect.impl.RequestParameterEventAspect"/>
<aspect logger="portal" name="frame" class="org.apache.cocoon.portal.event.aspect.impl.FrameEventAspect"/>
@@ -29,9 +29,16 @@
<!-- This aspect sets headers on the response that tell the client to not cache the response: -->
<aspect logger="portal" name="no-client-caching" class="org.apache.cocoon.portal.event.aspect.impl.NoClientCachingEventAspect"/>
- </component>
+ </component>
+
+ <!-- Portal Manager Aspect Configuration -->
+ <component class="org.apache.cocoon.components.ExtendedComponentSelector"
+ role="org.apache.cocoon.portal.PortalManagerAspectSelector">
+ <!-- This aspect activates the JSR-168 support. -->
+ <aspect logger="portal" name="portlet" class="org.apache.cocoon.portal.impl.PortletPortalManagerAspect"/>
+ </component>
- <component class="org.apache.cocoon.portal.event.impl.DefaultEventManager" logger="portal" role="org.apache.cocoon.portal.event.EventManager">
+ <component class="org.apache.cocoon.portal.event.impl.DefaultEventManager" logger="portal" role="org.apache.cocoon.portal.event.EventManager">
<event-aspects>
<!-- Uncomment this aspect when marshalling JSR168 portlet events
<aspect type="convertable"/>
@@ -60,7 +67,7 @@
<subscriber-roles>
<!-- <role name="AVALON-ROLE"/> -->
</subscriber-roles>
- </component>
+ </component>
<!-- Event Factory configuration -->
<component class="org.apache.cocoon.components.ExtendedComponentSelector" role="org.apache.cocoon.portal.event.ConvertableEventFactorySelector">
@@ -70,14 +77,17 @@
</component>
<!-- This is the portal manager.
- If you don't need the JSR-168 support uncomment the following line and comment out
- the definition below:
- <component class="org.apache.cocoon.portal.impl.PortalManagerImpl"
- logger="portal" role="org.apache.cocoon.portal.PortalManager"/>
-
+ The portal manager can be extended with different aspects.
+ Currently the JSR-168 aspect is configured/activated.
+ If you don't need the JSR-168 support uncomment the aspect.
-->
- <component class="org.apache.cocoon.portal.impl.PortletPortalManager"
- logger="portal" role="org.apache.cocoon.portal.PortalManager"/>
+ <component class="org.apache.cocoon.portal.impl.PortalManagerImpl"
+ logger="portal" role="org.apache.cocoon.portal.PortalManager">
+ <aspects>
+ <!-- JSR-168 support: -->
+ <aspect type="portlet"/>
+ </aspects>
+ </component>
<!-- This is the portal service -->
<component class="org.apache.cocoon.portal.impl.PortalServiceImpl" logger="portal" role="org.apache.cocoon.portal.PortalService">
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java?rev=219037&r1=219036&r2=219037&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/coplet/adapter/impl/PortletAdapter.java Thu Jul 14 06:00:51 2005
@@ -26,9 +26,8 @@
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.cocoon.components.ContextHelper;
import org.apache.cocoon.environment.http.HttpEnvironment;
-import org.apache.cocoon.portal.PortalManager;
import org.apache.cocoon.portal.coplet.CopletInstanceData;
-import org.apache.cocoon.portal.impl.PortletPortalManager;
+import org.apache.cocoon.portal.impl.PortletPortalManagerAspect;
import org.apache.cocoon.portal.pluto.om.PortletDefinitionRegistry;
import org.apache.cocoon.portal.pluto.om.PortletEntityListImpl;
import org.apache.cocoon.portal.pluto.om.PortletWindowImpl;
@@ -78,7 +77,7 @@
try {
// now get the portal manager
ServletConfig servletConfig = (ServletConfig) context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG);
- PortletPortalManager portalManager = (PortletPortalManager) servletConfig.getServletContext().getAttribute(PortalManager.ROLE);
+ PortletPortalManagerAspect portalManager = (PortletPortalManagerAspect) servletConfig.getServletContext().getAttribute(PortletPortalManagerAspect.class.getName());
this.portletContainer = portalManager.getPortletContainer();
this.environment = portalManager.getPortletContainerEnvironment();
@@ -125,7 +124,7 @@
objectModel.put("portlet-request", req);
}
final HttpServletResponse res = (HttpServletResponse) objectModel.get("portlet-response");
- PortletPortalManager.copletInstanceData.set(coplet);
+ PortletPortalManagerAspect.copletInstanceData.set(coplet);
try {
this.portletContainer.portletLoad(portletWindow, req.getRequest(portletWindow),
res);
@@ -135,7 +134,7 @@
coplet.removeTemporaryAttribute("window");
((PortletEntityListImpl)pae.getPortletEntityList()).remove(portletEntity);
} finally {
- PortletPortalManager.copletInstanceData.set(null);
+ PortletPortalManagerAspect.copletInstanceData.set(null);
}
}
}
@@ -162,7 +161,7 @@
final Map objectModel = ContextHelper.getObjectModel(this.context);
final ServletRequestImpl req = (ServletRequestImpl) objectModel.get("portlet-request");
final HttpServletResponse res = (HttpServletResponse) objectModel.get("portlet-response");
- PortletPortalManager.copletInstanceData.set(coplet);
+ PortletPortalManagerAspect.copletInstanceData.set(coplet);
// TODO - for parallel processing we have to clone the response!
this.portletContainer.renderPortlet(window, req.getRequest(window), res);
@@ -183,7 +182,7 @@
} catch (Exception e) {
throw new SAXException(e);
} finally {
- PortletPortalManager.copletInstanceData.set(null);
+ PortletPortalManagerAspect.copletInstanceData.set(null);
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalManagerAspectChain.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalManagerAspectChain.java?rev=219037&r1=219036&r2=219037&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalManagerAspectChain.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortalManagerAspectChain.java Thu Jul 14 06:00:51 2005
@@ -81,4 +81,15 @@
this.aspects.clear();
this.configs.clear();
}
+
+ /**
+ * Adds an aspect at the front. This method is only used by the deprecated PortletPortalManager.
+ * @deprecated This method will be removed in 2.2.
+ * @param firstAspect
+ * @param firstAspectParameters
+ */
+ public void addAsFirst(PortalManagerAspect firstAspect, Parameters firstAspectParameters) {
+ this.aspects.add(0, firstAspect);
+ this.configs.add(0, firstAspectParameters);
+ }
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManager.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManager.java?rev=219037&r1=219036&r2=219037&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManager.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManager.java Thu Jul 14 06:00:51 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 2004,2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,287 +15,30 @@
*/
package org.apache.cocoon.portal.impl;
-import java.util.Map;
-import java.util.Properties;
-
-import javax.portlet.PortletMode;
-import javax.portlet.WindowState;
-import javax.servlet.ServletConfig;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.ContextHelper;
-import org.apache.cocoon.environment.http.HttpEnvironment;
-import org.apache.cocoon.portal.PortalManager;
-import org.apache.cocoon.portal.event.Event;
-import org.apache.cocoon.portal.event.EventManager;
-import org.apache.cocoon.portal.event.Filter;
-import org.apache.cocoon.portal.event.Subscriber;
-import org.apache.cocoon.portal.pluto.PortletContainerEnvironmentImpl;
-import org.apache.cocoon.portal.pluto.PortletURLProviderImpl;
-import org.apache.cocoon.portal.pluto.servlet.ServletRequestImpl;
-import org.apache.cocoon.portal.pluto.servlet.ServletResponseImpl;
-import org.apache.cocoon.servlet.CocoonServlet;
-import org.apache.pluto.PortletContainer;
-import org.apache.pluto.PortletContainerException;
-import org.apache.pluto.PortletContainerImpl;
-import org.apache.pluto.om.window.PortletWindow;
-import org.apache.pluto.services.PortletContainerEnvironment;
-import org.apache.pluto.services.information.DynamicInformationProvider;
-import org.apache.pluto.services.information.InformationProviderService;
-import org.apache.pluto.services.information.PortletActionProvider;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
+import org.apache.cocoon.util.Deprecation;
/**
* Extends the PortalManager by initializing Pluto
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- *
+ * @deprecated Use the {@link org.apache.cocoon.portal.impl.PortletPortalManagerAspect}.
* @version CVS $Id$
*/
public class PortletPortalManager
extends PortalManagerImpl
- implements Initializable, Subscriber {
+ implements Initializable {
- public static final ThreadLocal copletInstanceData = new InheritableThreadLocal();
-
- /** The servlet configuration for pluto */
- protected ServletConfig servletConfig;
-
- /** The Portlet Container */
- protected PortletContainer portletContainer;
-
- /** The Portlet Container environment */
- protected PortletContainerEnvironmentImpl portletContainerEnvironment;
-
- /**
- * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
- */
- public void contextualize(Context context) throws ContextException {
- super.contextualize(context);
- try {
- this.servletConfig = (ServletConfig) context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG);
- // we have to somehow pass this component down to other components!
- // This is ugly, but it's the only chance for sofisticated component containers
- // that wrap component implementations!
- this.servletConfig.getServletContext().setAttribute(PortalManager.ROLE, this);
- } catch (ContextException ignore) {
- // we ignore the context exception
- // this avoids startup errors if the portal is configured for the CLI
- // environment
- this.getLogger().warn("The JSR-168 support is disabled as the servlet context is not available.", ignore);
- }
- }
+ public static final ThreadLocal copletInstanceData = PortletPortalManagerAspect.copletInstanceData;
/**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager manager) throws ServiceException {
- super.service(manager);
- EventManager eventManager = null;
- try {
- eventManager = (EventManager)this.manager.lookup(EventManager.ROLE);
- eventManager.getRegister().subscribe(this);
- } finally {
- this.manager.release(eventManager);
- }
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- if ( this.manager != null ) {
- EventManager eventManager = null;
- try {
- eventManager = (EventManager)this.manager.lookup(EventManager.ROLE);
- eventManager.getRegister().unsubscribe(this);
- } catch (Exception ignore) {
- // let's ignore it
- } finally {
- this.manager.release(eventManager);
- }
- }
- try {
- if (this.portletContainer != null ) {
- this.portletContainer.shutdown();
- this.portletContainer = null;
- }
- ContainerUtil.dispose(this.portletContainerEnvironment);
- this.portletContainerEnvironment = null;
- } catch (Throwable t) {
- this.getLogger().error("Destruction failed!", t);
- }
- if ( this.servletConfig != null ) {
- this.servletConfig.getServletContext().removeAttribute(PortalManager.ROLE);
- this.servletConfig = null;
- }
- super.dispose();
- }
-
- /* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Initializable#initialize()
*/
public void initialize() throws Exception {
- if ( this.servletConfig != null ) {
- this.initContainer();
- }
- }
-
- /**
- * Return the portlet container
- */
- public PortletContainer getPortletContainer() {
- return this.portletContainer;
- }
-
- /**
- * Return the portlet container environment
- */
- public PortletContainerEnvironment getPortletContainerEnvironment() {
- return this.portletContainerEnvironment;
- }
-
- /**
- * Initialize the container
- */
- public void initContainer() throws Exception {
- this.portletContainer = new PortletContainerImpl();
-
- if (!portletContainer.isInitialized()) {
- this.getLogger().debug ("Initializing PortletContainer...");
-
- final String uniqueContainerName = "cocoon-portal";
-
- this.portletContainerEnvironment = new PortletContainerEnvironmentImpl();
- ContainerUtil.enableLogging(this.portletContainerEnvironment, this.getLogger());
- ContainerUtil.contextualize(this.portletContainerEnvironment, this.context);
- ContainerUtil.service(this.portletContainerEnvironment, this.manager);
- ContainerUtil.initialize(this.portletContainerEnvironment);
-
- Properties properties = new Properties();
-
- try {
- portletContainer.init(uniqueContainerName, servletConfig, this.portletContainerEnvironment, properties);
- } catch (PortletContainerException exc) {
- throw new ProcessingException("Initialization of the portlet container failed.", exc);
- }
- } else {
- this.getLogger().debug("PortletContainer already initialized.");
- }
-
- this.getLogger().debug("PortletContainer initialized.");
-
- }
-
- /* (non-Javadoc)
- * @see org.apache.cocoon.portal.PortalManager#process()
- */
- public void process() throws ProcessingException {
- // process the events
- super.process();
-
- // if we aren't running in a servlet environment, just skip the JSR-168 part
- if ( this.servletConfig == null ) {
- return;
- }
-
- // do we already have an environment?
- // if not, create one
- final Map objectModel = ContextHelper.getObjectModel(this.context);
-
- PortletURLProviderImpl event = (PortletURLProviderImpl) objectModel.get("portlet-event");
- if ( event != null ) {
- PortletWindow actionWindow = event.getPortletWindow();
- try {
- final ServletRequestImpl req = (ServletRequestImpl) objectModel.get("portlet-request");
- final ServletResponseImpl res= (ServletResponseImpl)objectModel.get("portlet-response");
- this.portletContainer.processPortletAction(actionWindow, req.getRequest(actionWindow), res);
-
- // this redirect is only for 2.1.x, don't add it to 2.2
- // (see #32157 for more information)
- final String redirectURL = res.getRedirectURL();
- HttpServletResponse response = (HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
- response.sendRedirect(redirectURL);
- } catch (Exception ignore) {
- this.getLogger().error("Error during processing of portlet action.", ignore);
- }
- } else if ( objectModel.get("portlet-response") == null ) {
- final HttpServletResponse res = (HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
- objectModel.put("portlet-response", new ServletResponseImpl(res));
- final ServletRequestImpl req = new ServletRequestImpl((HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT), null);
- objectModel.put("portlet-request", req);
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.cocoon.portal.PortalManager#showPortal(org.xml.sax.ContentHandler, org.apache.avalon.framework.parameters.Parameters)
- */
- public void showPortal(ContentHandler contentHandler, Parameters parameters)
- throws SAXException {
- final Map objectModel = ContextHelper.getObjectModel(this.context);
-
- // don't generate a response, if we issued a redirect
- if (objectModel.get("portlet-event") == null) {
- super.showPortal(contentHandler, parameters);
- }
+ Deprecation.logger.info("The PortletPortalManager is deprecated. Please use the PortletPortalManagerAspect instead.");
+ PortletPortalManagerAspect aspect = (PortletPortalManagerAspect)this.aspectSelector.select("portlet");
+ this.chain.addAsFirst(aspect, new Parameters());
}
-
- /* (non-Javadoc)
- * @see org.apache.cocoon.portal.event.Subscriber#getEventType()
- */
- public Class getEventType() {
- return PortletURLProviderImpl.class;
- }
-
- /* (non-Javadoc)
- * @see org.apache.cocoon.portal.event.Subscriber#getFilter()
- */
- public Filter getFilter() {
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.apache.cocoon.portal.event.Subscriber#inform(org.apache.cocoon.portal.event.Event)
- */
- public void inform(Event e) {
- PortletURLProviderImpl event = (PortletURLProviderImpl)e;
- final Map objectModel = ContextHelper.getObjectModel(this.context);
- final ServletRequestImpl req = new ServletRequestImpl((HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT), event);
- final HttpServletResponse res = new ServletResponseImpl((HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT));
- objectModel.put("portlet-response", res);
- objectModel.put("portlet-request", req);
-
- if ( event.isAction() ) {
- // This means we can only have ONE portlet event per request!
- objectModel.put("portlet-event", event);
- } else {
- DynamicInformationProvider dynProv;
- InformationProviderService ips;
- PortletActionProvider pap;
-
- ips = (InformationProviderService)this.portletContainerEnvironment.getContainerService(InformationProviderService.class);
- dynProv = ips.getDynamicProvider(req);
- pap = dynProv.getPortletActionProvider(event.getPortletWindow());
- final PortletMode mode = event.getPortletMode();
- if ( mode != null ) {
- pap.changePortletMode(mode);
- }
- final WindowState state = event.getWindowState();
- if ( state != null ) {
- pap.changePortletWindowState(state);
- }
- }
- }
-
}
Added: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManagerAspect.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManagerAspect.java?rev=219037&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManagerAspect.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManagerAspect.java Thu Jul 14 06:00:51 2005
@@ -0,0 +1,324 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.portal.impl;
+
+import java.util.Map;
+import java.util.Properties;
+
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.http.HttpEnvironment;
+import org.apache.cocoon.portal.PortalManager;
+import org.apache.cocoon.portal.PortalManagerAspect;
+import org.apache.cocoon.portal.PortalManagerAspectPrepareContext;
+import org.apache.cocoon.portal.PortalManagerAspectRenderContext;
+import org.apache.cocoon.portal.PortalService;
+import org.apache.cocoon.portal.event.Event;
+import org.apache.cocoon.portal.event.EventManager;
+import org.apache.cocoon.portal.event.Filter;
+import org.apache.cocoon.portal.event.Subscriber;
+import org.apache.cocoon.portal.pluto.PortletContainerEnvironmentImpl;
+import org.apache.cocoon.portal.pluto.PortletURLProviderImpl;
+import org.apache.cocoon.portal.pluto.servlet.ServletRequestImpl;
+import org.apache.cocoon.portal.pluto.servlet.ServletResponseImpl;
+import org.apache.cocoon.servlet.CocoonServlet;
+import org.apache.pluto.PortletContainer;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.PortletContainerImpl;
+import org.apache.pluto.om.window.PortletWindow;
+import org.apache.pluto.services.PortletContainerEnvironment;
+import org.apache.pluto.services.information.DynamicInformationProvider;
+import org.apache.pluto.services.information.InformationProviderService;
+import org.apache.pluto.services.information.PortletActionProvider;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * This aspect provides the JSR-168 support by initializing Pluto.
+ * The aspect can be configured at the portal manager.
+ *
+ * @version SVN $Id:$
+ */
+public class PortletPortalManagerAspect
+ extends AbstractLogEnabled
+ implements PortalManagerAspect,
+ Contextualizable,
+ Serviceable,
+ Initializable,
+ Disposable,
+ Subscriber {
+
+ public static final ThreadLocal copletInstanceData = new InheritableThreadLocal();
+
+ /** The servlet configuration for pluto */
+ protected ServletConfig servletConfig;
+
+ /** The Portlet Container */
+ protected PortletContainer portletContainer;
+
+ /** The Portlet Container environment */
+ protected PortletContainerEnvironmentImpl portletContainerEnvironment;
+
+ /** The service locator */
+ protected ServiceManager manager;
+
+ /** The component context */
+ protected Context context;
+
+ /**
+ * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+ */
+ public void contextualize(Context context) throws ContextException {
+ this.context = context;
+ try {
+ this.servletConfig = (ServletConfig) context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG);
+ // we have to somehow pass this component down to other components!
+ // This is ugly, but it's the only chance for sofisticated component containers
+ // that wrap component implementations!
+ this.servletConfig.getServletContext().setAttribute(PortletPortalManagerAspect.class.getName(), this);
+ } catch (ContextException ignore) {
+ // we ignore the context exception
+ // this avoids startup errors if the portal is configured for the CLI
+ // environment
+ this.getLogger().warn("The JSR-168 support is disabled as the servlet context is not available.", ignore);
+ }
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ EventManager eventManager = null;
+ try {
+ eventManager = (EventManager)this.manager.lookup(EventManager.ROLE);
+ eventManager.getRegister().subscribe(this);
+ } finally {
+ this.manager.release(eventManager);
+ }
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ if ( this.manager != null ) {
+ EventManager eventManager = null;
+ try {
+ eventManager = (EventManager)this.manager.lookup(EventManager.ROLE);
+ eventManager.getRegister().unsubscribe(this);
+ } catch (Exception ignore) {
+ // let's ignore it
+ } finally {
+ this.manager.release(eventManager);
+ }
+ this.manager = null;
+ }
+ try {
+ if (this.portletContainer != null ) {
+ this.portletContainer.shutdown();
+ this.portletContainer = null;
+ }
+ ContainerUtil.dispose(this.portletContainerEnvironment);
+ this.portletContainerEnvironment = null;
+ } catch (Throwable t) {
+ this.getLogger().error("Destruction failed!", t);
+ }
+ if ( this.servletConfig != null ) {
+ this.servletConfig.getServletContext().removeAttribute(PortalManager.ROLE);
+ this.servletConfig = null;
+ }
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception {
+ if ( this.servletConfig != null ) {
+ this.initContainer();
+ }
+ }
+
+ /**
+ * Return the portlet container
+ */
+ public PortletContainer getPortletContainer() {
+ return this.portletContainer;
+ }
+
+ /**
+ * Return the portlet container environment
+ */
+ public PortletContainerEnvironment getPortletContainerEnvironment() {
+ return this.portletContainerEnvironment;
+ }
+
+ /**
+ * Initialize the container
+ */
+ public void initContainer() throws Exception {
+ this.portletContainer = new PortletContainerImpl();
+
+ if (!portletContainer.isInitialized()) {
+ this.getLogger().debug ("Initializing PortletContainer...");
+
+ final String uniqueContainerName = "cocoon-portal";
+
+ this.portletContainerEnvironment = new PortletContainerEnvironmentImpl();
+ ContainerUtil.enableLogging(this.portletContainerEnvironment, this.getLogger());
+ ContainerUtil.contextualize(this.portletContainerEnvironment, this.context);
+ ContainerUtil.service(this.portletContainerEnvironment, this.manager);
+ ContainerUtil.initialize(this.portletContainerEnvironment);
+
+ Properties properties = new Properties();
+
+ try {
+ portletContainer.init(uniqueContainerName, servletConfig, this.portletContainerEnvironment, properties);
+ } catch (PortletContainerException exc) {
+ throw new ProcessingException("Initialization of the portlet container failed.", exc);
+ }
+ } else {
+ this.getLogger().debug("PortletContainer already initialized.");
+ }
+
+ this.getLogger().debug("PortletContainer initialized.");
+
+ }
+
+ /**
+ * @see org.apache.cocoon.portal.event.Subscriber#getEventType()
+ */
+ public Class getEventType() {
+ return PortletURLProviderImpl.class;
+ }
+
+ /**
+ * @see org.apache.cocoon.portal.event.Subscriber#getFilter()
+ */
+ public Filter getFilter() {
+ return null;
+ }
+
+ /**
+ * @see org.apache.cocoon.portal.event.Subscriber#inform(org.apache.cocoon.portal.event.Event)
+ */
+ public void inform(Event e) {
+ PortletURLProviderImpl event = (PortletURLProviderImpl)e;
+ final Map objectModel = ContextHelper.getObjectModel(this.context);
+ final ServletRequestImpl req = new ServletRequestImpl((HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT), event);
+ final HttpServletResponse res = new ServletResponseImpl((HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT));
+ objectModel.put("portlet-response", res);
+ objectModel.put("portlet-request", req);
+
+ if ( event.isAction() ) {
+ // This means we can only have ONE portlet event per request!
+ objectModel.put("portlet-event", event);
+ } else {
+ DynamicInformationProvider dynProv;
+ InformationProviderService ips;
+ PortletActionProvider pap;
+
+ ips = (InformationProviderService)this.portletContainerEnvironment.getContainerService(InformationProviderService.class);
+ dynProv = ips.getDynamicProvider(req);
+ pap = dynProv.getPortletActionProvider(event.getPortletWindow());
+ final PortletMode mode = event.getPortletMode();
+ if ( mode != null ) {
+ pap.changePortletMode(mode);
+ }
+ final WindowState state = event.getWindowState();
+ if ( state != null ) {
+ pap.changePortletWindowState(state);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.cocoon.portal.PortalManagerAspect#prepare(org.apache.cocoon.portal.PortalManagerAspectPrepareContext, org.apache.cocoon.portal.PortalService)
+ */
+ public void prepare(PortalManagerAspectPrepareContext aspectContext,
+ PortalService service)
+ throws ProcessingException {
+ // process the events
+ aspectContext.invokeNext();
+
+ // if we aren't running in a servlet environment, just skip the JSR-168 part
+ if ( this.servletConfig == null ) {
+ return;
+ }
+
+ // do we already have an environment?
+ // if not, create one
+ final Map objectModel = aspectContext.getObjectModel();
+
+ PortletURLProviderImpl event = (PortletURLProviderImpl) objectModel.get("portlet-event");
+ if ( event != null ) {
+ PortletWindow actionWindow = event.getPortletWindow();
+ try {
+ final ServletRequestImpl req = (ServletRequestImpl) objectModel.get("portlet-request");
+ final ServletResponseImpl res= (ServletResponseImpl)objectModel.get("portlet-response");
+ this.portletContainer.processPortletAction(actionWindow, req.getRequest(actionWindow), res);
+
+ // this redirect is only for 2.1.x, don't add it to 2.2
+ // (see #32157 for more information)
+ final String redirectURL = res.getRedirectURL();
+ HttpServletResponse response = (HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
+ response.sendRedirect(redirectURL);
+ } catch (Exception ignore) {
+ this.getLogger().error("Error during processing of portlet action.", ignore);
+ }
+ } else if ( objectModel.get("portlet-response") == null ) {
+ final HttpServletResponse res = (HttpServletResponse) objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
+ objectModel.put("portlet-response", new ServletResponseImpl(res));
+ final ServletRequestImpl req = new ServletRequestImpl((HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT), null);
+ objectModel.put("portlet-request", req);
+ }
+ }
+
+ /**
+ * @see org.apache.cocoon.portal.PortalManagerAspect#render(org.apache.cocoon.portal.PortalManagerAspectRenderContext, org.apache.cocoon.portal.PortalService, org.xml.sax.ContentHandler, org.apache.avalon.framework.parameters.Parameters)
+ */
+ public void render(PortalManagerAspectRenderContext aspectContext,
+ PortalService service,
+ ContentHandler ch,
+ Parameters parameters)
+ throws SAXException {
+ final Map objectModel = aspectContext.getObjectModel();
+
+ // don't generate a response, if we issued a redirect
+ if (objectModel.get("portlet-event") == null) {
+ aspectContext.invokeNext(ch, parameters);
+ }
+ }
+
+}
+
Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManagerAspect.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PortletPortalManagerAspect.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/PortletWindowAspect.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/PortletWindowAspect.java?rev=219037&r1=219036&r2=219037&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/PortletWindowAspect.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/layout/renderer/aspect/impl/PortletWindowAspect.java Thu Jul 14 06:00:51 2005
@@ -25,10 +25,9 @@
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.cocoon.portal.PortalManager;
import org.apache.cocoon.portal.PortalService;
import org.apache.cocoon.portal.coplet.CopletInstanceData;
-import org.apache.cocoon.portal.impl.PortletPortalManager;
+import org.apache.cocoon.portal.impl.PortletPortalManagerAspect;
import org.apache.cocoon.portal.layout.Layout;
import org.apache.cocoon.portal.layout.impl.CopletLayout;
import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
@@ -92,7 +91,7 @@
try {
// now get the portal manager
ServletConfig servletConfig = (ServletConfig) context.get(CocoonServlet.CONTEXT_SERVLET_CONFIG);
- PortletPortalManager portalManager = (PortletPortalManager) servletConfig.getServletContext().getAttribute(PortalManager.ROLE);
+ PortletPortalManagerAspect portalManager = (PortletPortalManagerAspect) servletConfig.getServletContext().getAttribute(PortletPortalManagerAspect.class.getName());
if ( portalManager != null ) {
this.environment = portalManager.getPortletContainerEnvironment();
}
Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=219037&r1=219036&r2=219037&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Thu Jul 14 06:00:51 2005
@@ -197,6 +197,9 @@
<changes>
<release version="@version@" date="@date@">
<action dev="CZ" type="add">
+ Portal block: Convert PortletPortalManager into portal manager aspect.
+ </action>
+ <action dev="CZ" type="add">
CForms block: Make all WidgetValidatorBuilders ThreadSafe. Reset validation errors
before validating a field.
</action>