You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by cd...@apache.org on 2007/08/04 16:41:49 UTC

svn commit: r562725 [4/33] - in /portals/pluto/branches/1.1-286-trunk-merge: ./ assembly/ assembly/src/ assembly/src/main/ assembly/src/main/assembly/ assembly/src/main/resources/ maven-pluto-plugin/ maven-pluto-plugin/src/ maven-pluto-plugin/src/main/...

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/OptionalContainerServices.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/OptionalContainerServices.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/OptionalContainerServices.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/OptionalContainerServices.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004 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.pluto;
+
+import org.apache.pluto.spi.optional.PortletPreferencesService;
+import org.apache.pluto.spi.optional.PortletEnvironmentService;
+import org.apache.pluto.spi.optional.PortletInvokerService;
+import org.apache.pluto.internal.InternalPortletWindow;
+
+/**
+ * Defines the services necessary for integration between the Pluto Container
+ * and a Portal.
+ * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
+ */
+public interface OptionalContainerServices {
+
+    /**
+     * Returns the portlet preferences service implementation.
+     * @return the portlet preferences service implementation.
+     */
+    public PortletPreferencesService getPortletPreferencesService();
+
+    public PortletEnvironmentService getPortletEnvironmentService();
+    
+    /**
+     * Returns an invoker for the specified PortletWindow.
+     * @param portletWindow  the InternalPortletWindow used for invocation.
+     * @return an invoker which can be used to service the indicated portlet.
+     */
+    public PortletInvokerService getPortletInvokerService(
+    		InternalPortletWindow portletWindow);
+
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PlutoConfigurationException.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PlutoConfigurationException.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PlutoConfigurationException.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PlutoConfigurationException.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2003,2004 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.pluto;
+
+/**
+ * Exception thrown when Pluto configuration fails.
+ *
+ * @author ddewolf@apache.org
+ * @since Jul 2, 2005
+ */
+public class PlutoConfigurationException extends RuntimeException {
+
+    public PlutoConfigurationException(String message) {
+        super(message);
+    }
+
+    public PlutoConfigurationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainer.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainer.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainer.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainer.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2003,2004 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.pluto;
+
+import java.io.IOException;
+
+import javax.portlet.PortletException;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+
+/**
+ * The publicized entry point into Pluto. The base functionality of the portlet
+ * container can be enhanced or even modified by PortletContainerServices.
+ * <p/>
+ * <P> The methods of this class have to be called in the following order:
+ * <TABLE> <TR><TH>Method</TH><TH>Description</TH><TH>Constraints</TH></TR>
+ * <TR><TD>{@link #init(javax.servlet.ServletContext)}</TD> <TD>Initialized the
+ * portlet container.</TD> <TD>Performed only once per container
+ * lifecycle.</TD></TR>
+ * <p/>
+ * <TR><TD>{@link #doAction(org.apache.pluto.PortletWindow,
+    * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}</TD>
+ * <TD>Perform the action for the targeted portlet</TD> <TD>Optionally performed
+ * for a single portlet per request</TD></TR>
+ * <p/>
+ * <TR><TD>{@link #doRender(org.apache.pluto.PortletWindow,
+    * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}</TD>
+ * <TD>Render the portlet</TD> <TD>Performed once for each portlet per
+ * request.</TD></TR>
+ * <p/>
+ * <TR><TD>{@link #destroy()}</TD> <TD>Destroy and remove container from
+ * service.</TD> <TD>Performed only once per container lifecylce</TD></TR>
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:esm@apache.org">Elliot Metsger</a>
+ * @version $Id: PortletContainer.java 36010 2004-07-30 14:16:06Z ddewolf $
+ */
+public interface PortletContainer {
+
+    /**
+     * Initializes the container for use within the given servlet context.
+     * @param servletContext  the servlet context.
+     * @throws PortletContainerException if an error occurs.
+     */
+    public void init(ServletContext servletContext)
+    throws PortletContainerException;
+
+    /**
+     * Shuts down the container. After calling this method it is no longer valid
+     * to call any method on the portlet container.
+     * @throws PortletContainerException if an error occurs while shutting down
+     *                                   the container
+     */
+    public void destroy() throws PortletContainerException;
+
+    /**
+     * Calls the render method of the given portlet window.
+     * @param internalPortletWindow the portlet Window
+     * @param request               the servlet request
+     * @param response              the servlet response
+     * @throws PortletException          if one portlet has trouble fulfilling
+     *                                   the request
+     * @throws IOException               if the streaming causes an I/O problem
+     * @throws PortletContainerException if the portlet container implementation
+     *                                   has trouble fulfilling the request
+     */
+    public void doRender(PortletWindow internalPortletWindow,
+                         HttpServletRequest request,
+                         HttpServletResponse response)
+        throws PortletException, IOException, PortletContainerException;
+
+    /**
+     * Indicates that a portlet resource Serving occured in the current request and calls
+     * the processServeResource method of this portlet.
+     * @param internalPortletWindow the portlet Window
+     * @param request               the servlet request
+     * @param response              the servlet response
+     * @throws PortletException          if one portlet has trouble fulfilling
+     *                                   the request
+     * @throws PortletContainerException if the portlet container implementation
+     *                                   has trouble fulfilling the request
+     */
+    public void doServeResource(PortletWindow internalPortletWindow,
+                         HttpServletRequest request,
+                         HttpServletResponse response)
+        throws PortletException, IOException, PortletContainerException;
+
+    /**
+     * Indicates that a portlet action occured in the current request and calls
+     * the processAction method of this portlet.
+     * @param internalPortletWindow the portlet Window
+     * @param request               the servlet request
+     * @param response              the servlet response
+     * @throws PortletException          if one portlet has trouble fulfilling
+     *                                   the request
+     * @throws PortletContainerException if the portlet container implementation
+     *                                   has trouble fulfilling the request
+     */
+    public void doAction(PortletWindow internalPortletWindow,
+                         HttpServletRequest request,
+                         HttpServletResponse response)
+        throws PortletException, IOException, PortletContainerException;
+
+    /**
+     * Indicates that the portlet must be initialized
+     * @param internalPortletWindow the portlet Window
+     * @param servletRequest        the servlet request
+     * @param servletResponse       the servlet response
+     * @throws PortletException          if one portlet has trouble fulfilling
+     *                                   the request
+     * @throws PortletContainerException if the portlet container implementation
+     *                                   has trouble fulfilling the request
+     */
+    public void doLoad(PortletWindow internalPortletWindow,
+                       HttpServletRequest servletRequest,
+                       HttpServletResponse servletResponse)
+        throws PortletException, IOException, PortletContainerException;
+
+    /**
+     * Returns whether the container is already initialized or not.
+     * @return <code>true</code> if the container is initialized
+     */
+    public boolean isInitialized();
+
+    /**
+     * Retrieve the unique container name
+     * @return the container name.
+     */
+    public String getName();
+
+    /**
+     * Retreive the required container services associated with this container.
+     * @return the required container services associated with this container.
+     */
+    public RequiredContainerServices getRequiredContainerServices();
+
+    /**
+     * Retrieve the optional container services associated with this contianer.
+     * @return the container services provided by either the portal or the defaults.
+     */
+    public OptionalContainerServices getOptionalContainerServices();
+    
+    /**
+     * Retrieve the {@link PortletAppDD} for the portlet
+     * located at the supplied context.
+     * 
+     * Must not return null.
+     * 
+     * @param context the context of the portlet
+     * @return the portlet application descriptor
+     * @throws PortletContainerException if the container has trouble obtaining
+     *                                   the context of the portlet, or retrieving
+     *                                   the <code>PortletAppDD</code>
+     */    
+    public PortletAppDD getPortletApplicationDescriptor(String context)
+        throws PortletContainerException;
+    
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerException.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerException.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerException.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerException.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2003,2004 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.pluto;
+
+/**
+ * Thrown when an internal portlet container exception occurs within Pluto.
+ * This type of exception indicates an error from which the container is not
+ * able to recover.
+ *
+ * @version 1.0
+ */
+public class PortletContainerException extends Exception {
+    private Throwable cause;
+
+    /**
+     * Constructs a new PortletContainerException.
+     * This exception will have no message and no root cause.
+     */
+    public PortletContainerException() {
+
+    }
+
+    /**
+     * Constructs a new PortletContainerException with the given message.
+     * @param text the message explaining the exception occurance
+     */
+    public PortletContainerException(String text) {
+        super(text);
+    }
+
+    /**
+     * Constructs a new PortletContainerException with the given message and
+     * root cause.
+     * @param text  the message explaining the exception occurance
+     * @param cause the root cause of the is exception
+     */
+    public PortletContainerException(String text, Throwable cause) {
+        super(text);
+        this.cause = cause;
+    }
+
+    /**
+     * Constructs a new portlet invoker exception when the portlet needs to
+     * throw an exception. The exception's message is based on the localized
+     * message of the underlying exception.
+     * @param cause the root cause
+     */
+    public PortletContainerException(Throwable cause) {
+        super(cause.getLocalizedMessage());
+        this.cause = cause;
+    }
+
+    /**
+     * Returns the exception that cause this portlet exception.
+     * @return the <CODE>Throwable</CODE> that caused this portlet exception.
+     */
+    public Throwable getRootCause() {
+        return (cause);
+    }
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerFactory.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerFactory.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerFactory.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerFactory.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2004 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.pluto;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.core.DefaultOptionalContainerServices;
+import org.apache.pluto.core.PortletContainerImpl;
+import org.apache.pluto.util.ArgumentUtility;
+
+/**
+ * Factory used to create new PortletContainer instances.  The factor constructs
+ * the underlying pluto container implementation by using the the given
+ * container services.
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @version 1.0
+ * @since Sep 18, 2004
+ */
+public class PortletContainerFactory {
+
+    /** Logger. */
+    private static final Log LOG = LogFactory.getLog(PortletContainerFactory.class);
+
+
+    /** Singleton instance of the <code>PortletContainerFactory</code>. */
+    private static final PortletContainerFactory FACTORY =
+    		new PortletContainerFactory();
+
+    /**
+     * Accessor method for the singleton instance of the
+     * <code>PortletContainerFactory</code>.
+     * @return singleton instance of the PortletContainerFactory
+     */
+    public static PortletContainerFactory getInstance() {
+    	return FACTORY;
+    }
+
+    /**
+     * Private constructor that prevents external instantiation.
+     */
+    private PortletContainerFactory() {
+    	// Do nothing.
+    }
+
+    /**
+     * Create a container with the given containerName, initialized from the given
+     * servlet config, and using the given container services.
+     * @param containerName  the name of the portlet container.
+     * @param requiredServices  the required portlet container services.
+     * @return newly created PortletContainer instance.
+     * @throws PortletContainerException
+     */
+    public PortletContainer createContainer(
+    		String containerName,
+    		RequiredContainerServices requiredServices)
+        throws PortletContainerException {
+        return createContainer(containerName,
+                               requiredServices,
+                               new DefaultOptionalContainerServices());
+   }
+
+    public PortletContainer createContainer(
+    		String containerName,
+    		RequiredContainerServices requiredServices,
+    		OptionalContainerServices optionalServices) {
+    	
+        ArgumentUtility.validateNotNull("requiredServices", requiredServices);
+        ArgumentUtility.validateNotEmpty("containerName", containerName);
+        
+        DefaultOptionalContainerServices optionalServicesWrapper =
+        		new DefaultOptionalContainerServices(optionalServices);
+        PortletContainer container = new PortletContainerImpl(
+        		containerName, requiredServices, optionalServicesWrapper);
+        
+        if (LOG.isInfoEnabled()) {
+            LOG.info("Portlet Container [" + containerName + "] created.");
+        }
+        return container;
+    }
+}
+

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerRuntimeException.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerRuntimeException.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerRuntimeException.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletContainerRuntimeException.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2003,2004 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.pluto;
+
+/**
+ * Runtime exception thrown when an unexpected condition is encountered.
+ *
+ * @version 1.0
+ */
+public class PortletContainerRuntimeException extends RuntimeException {
+
+    public PortletContainerRuntimeException() {
+
+    }
+
+    public PortletContainerRuntimeException(String message) {
+        super(message);
+    }
+
+    public PortletContainerRuntimeException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public PortletContainerRuntimeException(Throwable cause) {
+        super(cause);
+    }
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletWindow.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletWindow.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletWindow.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletWindow.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004 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.pluto;
+
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+
+/**
+ * Thin representation of the portlet window for which the container
+ * request should be processed.  The PortletWindow is used internally
+ * to map the request to the configured Portlet Application and Portlet.
+ *
+ * @see org.apache.pluto.core.PortletWindowImpl
+ * @see org.apache.pluto.descriptors.portlet.PortletDD
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @version 1.0
+ * @since Sep 22, 2004
+ */
+public interface PortletWindow {
+
+    /**
+     * Retrieve this windows unique id which will be
+     *  used to communicate back to the referencing portal.
+     * @return unique id.
+     */
+    public PortletWindowID getId();
+
+    /**
+     * Retrieve the context path in which the Portlet resides.
+     * @return context path
+     */
+    public String getContextPath();
+
+    /**
+     * Retrieve the name of the portlet as configured in the
+     * <code>portlet.xml</code>.
+     * @return the name of the portlet.
+     */
+    public String getPortletName();
+
+    /**
+     * Retrieve the current window state for this window.
+     * @return the current window state.
+     */
+    public WindowState getWindowState();
+
+    /**
+     * Retrieve the current portlet mode for this window.
+     * @return the current portlet mode.
+     */
+    public PortletMode getPortletMode();
+    
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletWindowID.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletWindowID.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletWindowID.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/PortletWindowID.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2004 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.pluto;
+
+/**
+ * The portlet window ID.
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @version 1.0
+ */
+public interface PortletWindowID {
+	
+	/**
+	 * Returns the unique string ID of the portlet window.
+	 * <p>
+	 * Depending on the implementation of <code>toString()</code> is dangerous,
+	 * because the original implementation in <code>Object</code> is not
+	 * qualified.
+	 * </p>
+	 * @return the unique string ID of the portlet window.
+	 */
+	public String getStringId();
+	
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/RequiredContainerServices.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/RequiredContainerServices.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/RequiredContainerServices.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/RequiredContainerServices.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004 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.pluto;
+
+import org.apache.pluto.spi.PortalCallbackService;
+
+import javax.portlet.PortalContext;
+
+/**
+ * This interface defines the services required for integration between the
+ * Pluto Portlet Container and a Portal.
+ * 
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ */
+public interface RequiredContainerServices {
+
+    /**
+     * Returns the PortalContext instance associated with this group of
+     * portlet container services.
+     * @return a PortalContext implementation.
+     */
+    public PortalContext getPortalContext();
+
+    /**
+     * Returns the portal callback service implementation instance associated
+     * with this group of portlet container services. 
+     * @return a PortalCallbackService implementation.
+     */
+    public PortalCallbackService getPortalCallbackService();
+    
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalContainerServices.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalContainerServices.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalContainerServices.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/DefaultOptionalContainerServices.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2004 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.pluto.core;
+
+import org.apache.pluto.OptionalContainerServices;
+import org.apache.pluto.internal.InternalPortletWindow;
+import org.apache.pluto.spi.optional.PortletPreferencesService;
+import org.apache.pluto.spi.optional.PortletEnvironmentService;
+import org.apache.pluto.spi.optional.PortletInvokerService;
+
+/**
+ * Default Optional Container Services implementation.
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @version 1.0
+ * @since Sep 18, 2004
+ */
+public class DefaultOptionalContainerServices
+implements OptionalContainerServices {
+	
+	// Private Member Variables ------------------------------------------------
+	
+    /** The portlet preferences service implementation. */
+    private PortletPreferencesService preferenceService = null;
+    
+    
+    // Constructors ------------------------------------------------------------
+    
+    /**
+     * Constructs an instance using the default portlet preferences service
+     * implementation.
+     */
+    public DefaultOptionalContainerServices() {
+        preferenceService = new DefaultPortletPreferencesService();
+    }
+    
+    /**
+     * Constructs an instance using specified optional container services
+     * implementation. If the portlet preferences service is provided, it will
+     * be used. Otherwise, the default portlet preferences service will be used.
+     * @param root  the root optional container services implementation.
+     */
+    public DefaultOptionalContainerServices(OptionalContainerServices root) {
+        if (root.getPortletPreferencesService() != null) {
+            preferenceService = root.getPortletPreferencesService();
+        } else {
+        	preferenceService = new DefaultPortletPreferencesService();
+        }
+    }
+    
+    
+    // OptionalContainerServices Impl ------------------------------------------
+    
+    public PortletPreferencesService getPortletPreferencesService() {
+        return preferenceService;
+    }
+    
+    /**
+     * TODO:
+     */
+    public PortletEnvironmentService getPortletEnvironmentService() {
+        return null;
+    }
+    
+    /**
+     * TODO:
+     */
+    public PortletInvokerService getPortletInvokerService(
+    		InternalPortletWindow window) {
+        return null;
+    }
+    
+}
+

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/DefaultPortletPreferencesService.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2004 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.pluto.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.PortletWindow;
+import org.apache.pluto.internal.InternalPortletPreference;
+import org.apache.pluto.spi.optional.PortletPreferencesService;
+
+/**
+ * Default implementation of the portlet preferences service. The portlet
+ * preferences service is a singleton held by the pluto portlet container.
+ * 
+ * @see javax.portlet.PortletPreferences
+ * @see org.apache.pluto.core.impl.PortletPreferencesImpl
+ * @see org.apache.pluto.core.PortletPreference
+ * 
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+public class DefaultPortletPreferencesService
+implements PortletPreferencesService {
+	
+	/** Logger. */
+	private static final Log LOG = LogFactory.getLog(
+			DefaultPortletPreferencesService.class);
+	
+	
+	// Private Member Variables ------------------------------------------------
+	
+	/**
+	 * The in-memory portlet preferences storage: key is the preference name as
+	 * a string, value is an array of PortletPreference objects.
+	 */
+	private Map storage = new HashMap();
+	
+	
+	// Constructor -------------------------------------------------------------
+	
+	/**
+	 * Default no-arg constructor.
+	 */
+	public DefaultPortletPreferencesService() {
+		// Do nothing.
+	}
+	
+	
+	// PortletPreferencesService Impl ------------------------------------------
+	
+	/**
+	 * Returns the stored portlet preferences array. The preferences managed by
+	 * this service should be protected from being directly accessed, so this
+	 * method returns a cloned copy of the stored preferences.
+	 * 
+	 * @see org.apache.pluto.core.PortletPreference#clone()
+	 * 
+	 * @param portletWindow  the portlet window.
+	 * @param request  the portlet request from which the remote user is retrieved.
+	 * @return a copy of the stored portlet preferences array.
+	 * @throws PortletContainerException
+	 */
+	public InternalPortletPreference[] getStoredPreferences(
+			PortletWindow portletWindow,
+			PortletRequest request)
+	throws PortletContainerException {
+        String key = getFormattedKey(portletWindow, request);
+        InternalPortletPreference[] preferences = (InternalPortletPreference[])
+        		storage.get(key);
+        if (preferences == null) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("No portlet preferences found for: " + key);
+            }
+            return new InternalPortletPreference[0];
+        } else {
+        	if (LOG.isDebugEnabled()) {
+        		LOG.debug("Got " + preferences.length + " stored preferences.");
+        	}
+        	return clonePreferences(preferences);
+        }
+    }
+	
+	/**
+	 * Stores the portlet preferences to the in-memory storage. This method
+	 * should be invoked after the portlet preferences are validated by the
+	 * preference validator (if defined).
+	 * <p>
+	 * The preferences managed by this service should be protected from being
+	 * directly accessed, so this method clones the passed-in preferences array
+	 * and saves it.
+	 * </p>
+	 * 
+	 * @see javax.portlet.PortletPreferences#store()
+	 * @see org.apache.pluto.core.PortletPreference#clone()
+	 * 
+	 * @param portletWindow  the portlet window
+	 * @param request  the portlet request from which the remote user is retrieved.
+	 * @param preferences  the portlet preferences to store.
+	 * @throws PortletContainerException
+	 */
+    public void store(PortletWindow portletWindow,
+                      PortletRequest request,
+                      InternalPortletPreference[] preferences)
+    throws PortletContainerException {
+        String key = getFormattedKey(portletWindow, request);
+        storage.put(key, clonePreferences(preferences));
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Portlet preferences stored for: " + key);
+        }
+    }
+    
+    
+    // Private Methods ---------------------------------------------------------
+    
+    /**
+     * Formats the preference key for the portlet preference using specified
+     * portlet window and remote user.
+     * @param portletWindow  the portlet window.
+     * @param user  the remote user.
+     */
+    private String getFormattedKey(PortletWindow portletWindow,
+                                   PortletRequest request) {
+    	StringBuffer buffer = new StringBuffer();
+    	buffer.append("user=").append(request.getRemoteUser()).append(";");
+    	buffer.append("portletName=").append(portletWindow.getPortletName());
+    	return buffer.toString();
+    }
+    
+    /**
+     * Clones a PortletPreference array. This method performs a deep clone on
+     * the passed-in portlet preferences array. Every PortletPreference object
+     * in the array are cloned (via the <code>PortletPreference.clone()</code>
+     * method) and injected into the new array.
+     * 
+     * @see org.apache.pluto.core.PortletPreference#clone()
+     * 
+     * @param preferences  the portlet preferences array to clone.
+     * @return a deep-cloned copy of the portlet preferences array.
+     */
+    private InternalPortletPreference[] clonePreferences(
+    		InternalPortletPreference[] preferences) {
+    	if (preferences == null) {
+    		return null;
+    	}
+    	InternalPortletPreference[] copy =
+    			new InternalPortletPreference[preferences.length];
+    	for (int i = 0; i < preferences.length; i++) {
+    		if (preferences[i] != null) {
+    			copy[i] = (InternalPortletPreference) preferences[i].clone();
+    		} else {
+    			copy[i] = null;
+    		}
+    	}
+    	return copy;
+    }
+    
+}
+
+

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/NullPortlet.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/NullPortlet.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/NullPortlet.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/NullPortlet.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2006 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.pluto.core;
+
+/**
+ * Implements the Null Object Pattern
+ * 
+ * @author <a href="mailto:chrisra@cs.uni-jena.de">Christian Raschka</a>
+ *
+ */
+
+import java.io.IOException;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.EventPortlet;
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.Portlet;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceServingPortlet;
+
+public class NullPortlet implements EventPortlet, ResourceServingPortlet,
+               Portlet {
+
+       public void processEvent(EventRequest arg0, EventResponse arg1)
+                       throws PortletException, IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void serveResource(ResourceRequest arg0, ResourceResponse arg1)
+                       throws PortletException, IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void destroy() {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void init(PortletConfig arg0) throws PortletException {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void processAction(ActionRequest arg0, ActionResponse arg1)
+                       throws PortletException, IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void render(RenderRequest arg0, RenderResponse arg1)
+                       throws PortletException, IOException {
+               // TODO Auto-generated method stub
+
+       }
+
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletContainerImpl.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,519 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pluto.core;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.portlet.Event;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.Constants;
+import org.apache.pluto.EventContainer;
+import org.apache.pluto.OptionalContainerServices;
+import org.apache.pluto.PortletContainer;
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.PortletWindow;
+import org.apache.pluto.RequiredContainerServices;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.internal.InternalPortletWindow;
+import org.apache.pluto.internal.PortletDescriptorRegistry;
+import org.apache.pluto.internal.impl.ActionRequestImpl;
+import org.apache.pluto.internal.impl.ActionResponseImpl;
+import org.apache.pluto.internal.impl.EventRequestImpl;
+import org.apache.pluto.internal.impl.EventResponseImpl;
+import org.apache.pluto.internal.impl.PortletWindowImpl;
+import org.apache.pluto.internal.impl.RenderRequestImpl;
+import org.apache.pluto.internal.impl.RenderResponseImpl;
+import org.apache.pluto.internal.impl.ResourceRequestImpl;
+import org.apache.pluto.internal.impl.ResourceResponseImpl;
+import org.apache.pluto.internal.impl.StateAwareResponseImpl;
+import org.apache.pluto.spi.EventProvider;
+import org.apache.pluto.spi.PortletURLProvider;
+
+/**
+ * Default Pluto Container implementation.
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @author <a href="mailto:esm@apache.org">Elliot Metsger</a>
+ * @author <a href="mailto:chrisra@cs.uni-jena.de">Christian Raschka</a>
+ * @version 1.0
+ * @since Sep 18, 2004
+ */
+public class PortletContainerImpl implements PortletContainer,
+	EventContainer {
+
+    /** Internal logger. */
+    private static final Log LOG = LogFactory.getLog(PortletContainerImpl.class);
+    
+    
+    // Private Member Variables ------------------------------------------------
+    
+    /** The portlet container name. */
+    private String name = null;
+    
+    /** The required container services associated with this container. */
+    private RequiredContainerServices requiredContainerServices = null;
+    
+    /** The optional container services associated with this container. */
+    private OptionalContainerServices optionalContainerServices = null;
+    
+    /** The servlet context associated with this container. */
+    private ServletContext servletContext = null;
+
+    /** Flag indicating whether or not we've been initialized. */
+    private boolean initialized = false;
+    
+    
+    // Constructor -------------------------------------------------------------
+    
+    /** Default Constructor.  Create a container implementation
+     *  whith the given name and given services.
+     *
+     * @param name  the name of the container.
+     * @param requiredServices  the required container services implementation.
+     * @param optionalServices  the optional container services implementation.
+     */
+    public PortletContainerImpl(String name,
+                                RequiredContainerServices requiredServices,
+                                OptionalContainerServices optionalServices) {
+        this.name = name;
+        this.requiredContainerServices = requiredServices;
+        this.optionalContainerServices = optionalServices;
+    }
+    
+    
+    // PortletContainer Impl ---------------------------------------------------
+    
+    /**
+     * Initialize the container for use within the given configuration scope.
+     * @param servletContext  the servlet context of the portal webapp.
+     */
+    public void init(ServletContext servletContext)
+    throws PortletContainerException {
+    	if (servletContext == null) {
+    		throw new PortletContainerException(
+    				"Unable to initialize portlet container [" + name + "]: "
+    				+ "servlet context is null.");
+    	}
+        this.servletContext = servletContext;
+        this.initialized = true;
+        infoWithName("Container initialized successfully.");
+    }
+
+    /**
+     * Determine whether this container has been initialized or not.
+     * @return true if the container has been initialized.
+     */
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+    /**
+     * Destroy this container.
+     */
+    public void destroy() {
+        this.servletContext = null;
+        this.initialized = false;
+        infoWithName("Container destroyed.");
+    }
+
+
+    /**
+     * Renders the portlet associated with the specified portlet window.
+     * @param portletWindow  the portlet window.
+     * @param request  the servlet request.
+     * @param response  the servlet response.
+     * @throws IllegalStateException  if the container is not initialized.
+     * @throws PortletException
+     * @throws IOException
+     * @throws PortletContainerException
+     * 
+     * @see javax.portlet.Portlet#render(RenderRequest, RenderResponse)
+     */
+    public void doRender(PortletWindow portletWindow,
+                         HttpServletRequest request,
+                         HttpServletResponse response)
+    throws PortletException, IOException, PortletContainerException {
+    	
+    	ensureInitialized();
+    	
+        InternalPortletWindow internalPortletWindow =
+        		new PortletWindowImpl(servletContext, portletWindow);
+        debugWithName("Render request received for portlet: "
+        		+ portletWindow.getPortletName());
+        
+        RenderRequestImpl renderRequest = new RenderRequestImpl(
+        		this, internalPortletWindow, request);
+        RenderResponseImpl renderResponse = new RenderResponseImpl(
+        		this, internalPortletWindow, request, response);
+
+        PortletInvoker invoker = new PortletInvoker(internalPortletWindow);
+        invoker.render(renderRequest, renderResponse);
+        debugWithName("Portlet rendered for: "
+        		+ portletWindow.getPortletName());
+    }
+
+    /**
+     * Indicates that a portlet resource Serving occured in the current request and calls
+     * the processServeResource method of this portlet.
+     * @param internalPortletWindow the portlet Window
+     * @param request               the servlet request
+     * @param response              the servlet response
+     * @throws PortletException          if one portlet has trouble fulfilling
+     *                                   the request
+     * @throws PortletContainerException if the portlet container implementation
+     *                                   has trouble fulfilling the request
+     */
+    public void doServeResource(PortletWindow portletWindow,
+    							HttpServletRequest request,
+    							HttpServletResponse response)
+    throws PortletException, IOException, PortletContainerException {
+		
+    	ensureInitialized();
+    	
+        InternalPortletWindow internalPortletWindow =
+        		new PortletWindowImpl(servletContext, portletWindow);
+        debugWithName("Resource request received for portlet: "
+        		+ portletWindow.getPortletName());
+        
+        ResourceRequestImpl renderRequest = new ResourceRequestImpl(
+        		this, internalPortletWindow, request);
+        ResourceResponseImpl renderResponse = new ResourceResponseImpl(
+        		this, internalPortletWindow, request, response);
+
+        PortletInvoker invoker = new PortletInvoker(internalPortletWindow);
+        invoker.resource(renderRequest, renderResponse);
+        debugWithName("Portlet resource for: "
+        		+ portletWindow.getPortletName());
+	}
+    
+    /**
+     * Process action for the portlet associated with the given portlet window.
+     * @param portletWindow  the portlet window.
+     * @param request  the servlet request.
+     * @param response  the servlet response.
+     * @throws PortletException
+     * @throws IOException
+     * @throws PortletContainerException
+     * 
+     * @see javax.portlet.Portlet#processAction(ActionRequest, ActionResponse)
+     */
+    public void doAction(PortletWindow portletWindow,
+                         HttpServletRequest request,
+                         HttpServletResponse response)
+    throws PortletException, IOException, PortletContainerException {
+    	
+    	ensureInitialized();
+    	
+        InternalPortletWindow internalPortletWindow =
+            	new PortletWindowImpl(servletContext, portletWindow);
+    	debugWithName("Action request received for portlet: "
+    			+ portletWindow.getPortletName());
+    	
+        ActionRequestImpl actionRequest = new ActionRequestImpl(
+        		this, internalPortletWindow, request);
+        ActionResponseImpl actionResponse = new ActionResponseImpl(
+        		this, internalPortletWindow, request, response);
+        
+        PortletInvoker invoker = new PortletInvoker(internalPortletWindow);
+        invoker.action(actionRequest, actionResponse);
+        debugWithName("Portlet action processed for: "
+        		+ portletWindow.getPortletName());
+        
+        PortletURLProvider portletURLProvider = requiredContainerServices.getPortalCallbackService().getPortletURLProvider(request, internalPortletWindow);
+        saveChangedParameters(actionRequest, actionResponse, portletURLProvider);
+        portletURLProvider.savePortalURL(request);        
+        
+        EventProvider provider = this.getRequiredContainerServices().getPortalCallbackService().
+			getEventProvider(request,response);
+        provider.fireEvents(this);
+        
+        // After processing action, send a redirect URL for rendering.
+        String location = actionResponse.getRedirectLocation();
+
+        if (location == null) {
+        	
+        	// Create portlet URL provider to encode redirect URL.
+        	debugWithName("No redirect location specified.");
+            PortletURLProvider redirectURL = requiredContainerServices
+            		.getPortalCallbackService()
+            		.getPortletURLProvider(request, internalPortletWindow);
+            
+            saveChangedParameters(actionRequest, actionResponse, redirectURL);
+            
+            // Encode the redirect URL to a string.
+            location = actionResponse.encodeRedirectURL(redirectURL.toString());
+        }
+
+        // Here we intentionally use the original response
+        // instead of the wrapped internal response.
+        response.sendRedirect(location);
+        debugWithName("Redirect URL sent.");
+    }
+
+    /**
+     * Loads the portlet associated with the specified portlet window.
+     * @param portletWindow  the portlet window.
+     * @param request  the servlet request.
+     * @param response  the servlet response.
+     * @throws PortletException
+     * @throws IOException
+     * @throws PortletContainerException
+     */
+    public void doLoad(PortletWindow portletWindow,
+                       HttpServletRequest request,
+                       HttpServletResponse response)
+    	throws PortletException, IOException, PortletContainerException {
+    	
+    	ensureInitialized();
+    	
+        InternalPortletWindow internalPortletWindow =
+        		new PortletWindowImpl(servletContext, portletWindow);
+        debugWithName("Load request received for portlet: "
+        		+ portletWindow.getPortletName());
+        
+        RenderRequestImpl renderRequest = new RenderRequestImpl(
+        		this, internalPortletWindow, request);
+        RenderResponseImpl renderResponse = new RenderResponseImpl(
+        		this, internalPortletWindow, request, response);
+        
+        PortletInvoker invoker = new PortletInvoker(internalPortletWindow);
+        invoker.load(renderRequest, renderResponse);
+        debugWithName("Portlet loaded for: " + portletWindow.getPortletName());
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public RequiredContainerServices getRequiredContainerServices() {
+        return requiredContainerServices;
+    }
+
+    public OptionalContainerServices getOptionalContainerServices() {
+        return optionalContainerServices;
+    }
+    
+    public PortletAppDD getPortletApplicationDescriptor(String context) 
+        throws PortletContainerException {
+        
+        // make sure the container has initialized
+        ensureInitialized();
+        
+        // sanity check
+        if (context == null || context.trim().equals("")) {
+            final String msg = "Context was null or the empty string.";
+            errorWithName(msg);
+            throw new PortletContainerException(msg);
+        }
+        
+        // obtain the context of the portlet
+        ServletContext portletCtx = servletContext.getContext(context);
+        if (portletCtx == null) {
+            final String msg = "Unable to obtain the servlet context for " +
+                "portlet context [" + context + "].  Ensure the portlet has " +
+                "been deployed and that cross context support is enabled.";
+            errorWithName(msg);
+            throw new PortletContainerException(msg);
+        }
+        
+        // obtain the portlet application descriptor for the portlet
+        // context.
+        PortletAppDD portletAppDD = PortletDescriptorRegistry
+                                        .getRegistry()
+                                        .getPortletAppDD(portletCtx);
+        
+        // we can't return null
+        if (portletAppDD == null) {
+            final String msg = "Obtained a null portlet application description for " +
+                "portlet context [" + context + "]";
+            errorWithName(msg);
+            throw new PortletContainerException(msg);
+        }
+        
+        return portletAppDD;        
+    }
+    
+    public ServletContext getServletContext() {
+		return servletContext;
+	}
+    
+    /**
+     * Fire Event for the portlet associated with the given portlet window and eventName
+     * @param portletWindow  the portlet window.
+     * @param request  the servlet request.
+     * @param response  the servlet response.
+     * @param eventName the event name
+     * @throws PortletException
+     * @throws IOException
+     * @throws PortletContainerException
+     * 
+     * @see {@link javax.portlet.EventPortlet#processEvent(javax.portlet.EventRequest, javax.portlet.EventResponse)
+     */
+    public void fireEvent(HttpServletRequest request, HttpServletResponse response,
+    		PortletWindow window, Event event) 
+    		throws PortletException, IOException {
+
+    	ensureInitialized();
+
+    	InternalPortletWindow internalPortletWindow =
+    		new PortletWindowImpl(servletContext, window);
+    	debugWithName("Event request received for portlet: "
+    			+ window.getPortletName());
+
+    	EventRequestImpl eventRequest = new EventRequestImpl(
+    			this, internalPortletWindow, request, event);
+    	EventResponseImpl eventResponse = new EventResponseImpl(
+    			this, internalPortletWindow, request, response);
+
+    	PortletInvoker invoker = new PortletInvoker(internalPortletWindow);
+    	invoker.event(eventRequest, eventResponse);
+
+    	debugWithName("Portlet event processed for: "
+    			+ window.getPortletName());
+
+    	// After processing event, change the redirect URL for rendering.
+    	String location = eventResponse.getRedirectLocation();
+
+    	if (location == null) {
+
+    		// Create portlet URL provider to encode redirect URL.
+    		debugWithName("No redirect location specified.");
+    		PortletURLProvider redirectURL = requiredContainerServices
+    		.getPortalCallbackService()
+    		.getPortletURLProvider(request, internalPortletWindow);
+
+    		saveChangedParameters(eventRequest, eventResponse, redirectURL);
+
+    		// save redirectURL in request
+    		redirectURL.savePortalURL(request);
+    	}
+    }
+    
+    
+    // Private Methods ---------------------------------------------------------
+    
+    /**
+     * Ensures that the portlet container is initialized.
+     * @throws IllegalStateException  if the container is not initialized.
+     */
+    private void ensureInitialized() throws IllegalStateException {
+    	if (!isInitialized()) {
+    		throw new IllegalStateException(
+    				"Portlet container [" + name + "] is not initialized.");
+    	}
+    }
+    
+    /**
+     * Prints a message at DEBUG level with the container name prefix.
+     * @param message  log message.
+     */
+    private void debugWithName(String message) {
+    	if (LOG.isDebugEnabled()) {
+    		LOG.debug("Portlet Container [" + name + "]: " + message);
+    	}
+    }
+    
+    /**
+     * Prints a message at INFO level with the container name prefix.
+     * @param message  log message.
+     */
+    private void infoWithName(String message) {
+    	if (LOG.isInfoEnabled()) {
+    		LOG.info("Portlet Container [" + name + "]: " + message);
+    	}
+    }
+    
+    /**
+     * Prints a message at ERROR level with the container name prefix.
+     * @param message  log message.
+     */
+    private void errorWithName(String message) {
+        if (LOG.isErrorEnabled()) {
+            LOG.info("Portlet Container [" + name + "]: " + message);
+        }
+    }
+
+	/**
+	 * @param request
+	 * @param response
+	 * @param redirectURL
+	 */
+	private void saveChangedParameters(PortletRequest request, StateAwareResponseImpl response, PortletURLProvider redirectURL) {
+		// Encode portlet mode if it is changed.
+		if (response.getChangedPortletMode() != null) {
+			redirectURL.setPortletMode(
+					response.getChangedPortletMode());
+		}
+
+		// Encode window state if it is changed.
+		if (response.getChangedWindowState() != null) {
+			redirectURL.setWindowState(
+					response.getChangedWindowState());
+		}
+
+		// Encode render parameters retrieved from action response.
+		Map renderParameters = response.getRenderParameters();
+		
+		// clear render parameter only once per request
+		// (there could be more than one (eventing))
+		if (!isAlreadyCleared(request))
+			redirectURL.clearParameters();
+		
+		redirectURL.setParameters(renderParameters);
+		redirectURL.setPublicRenderParameters(response.getPublicRenderParameter());
+
+		// Encode redirect URL as a render URL.
+		redirectURL.setAction(false);
+
+		// Set secure of the redirect URL if necessary.
+		if (request.isSecure()) {
+			redirectURL.setSecure();
+		}
+	}
+
+
+	/**
+	 * Checks if render parameter are already cleared,
+	 * bye storing/reading an ID in the request
+	 * 
+	 * @param request the portlet request
+	 * 
+	 * @return true, if already cleared
+	 */
+	private boolean isAlreadyCleared(PortletRequest request) {
+		String cleared = (String) request.getAttribute(Constants.RENDER_ALREADY_CLEARED);
+		if (cleared == null || cleared.equals("false")) {
+			request.setAttribute(Constants.RENDER_ALREADY_CLEARED,"true");
+			return false;
+		}
+		return true;
+	}    
+}
+

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletContextManager.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2004 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.pluto.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletContext;
+import javax.servlet.ServletContext;
+
+import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.descriptors.portlet.PortletAppDD;
+import org.apache.pluto.internal.InternalPortletContext;
+import org.apache.pluto.internal.PortletDescriptorRegistry;
+import org.apache.pluto.internal.impl.PortletContextImpl;
+
+/**
+ * Manager used to cache the portlet configurations which have
+ * been previously parsed.
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ * @version 1.0
+ * @since Sep 20, 2004
+ */
+public class PortletContextManager {
+
+    /** The singleton manager instance. */
+    private static final PortletContextManager MANAGER = new PortletContextManager();
+
+    // Private Member Variables ------------------------------------------------
+    
+    /**
+     * The PortletContext cache map: key is servlet context, and value is the
+     * associated portlet context.
+     */
+    private Map portletContexts = new HashMap();
+    
+    
+    // Constructor -------------------------------------------------------------
+    
+    /**
+     * Private constructor that prevents external instantiation.
+     */
+    private PortletContextManager() {
+    	// Do nothing.
+    }
+
+    /**
+     * Returns the singleton manager instance.
+     * @return the singleton manager instance.
+     */
+    public static PortletContextManager getManager() {
+        return MANAGER;
+    }
+    
+    
+    // Public Methods ----------------------------------------------------------
+
+    /**
+     * Retrieves the PortletContext associated with the given ServletContext.
+     * If one does not exist, it is created.
+     *
+     * @param servletContext  the servlet context.
+     * @return the InternalPortletContext associated with the ServletContext.
+     * @throws PortletContainerException
+     */
+    public InternalPortletContext getPortletContext(ServletContext servletContext)
+    throws PortletContainerException {
+        if (!portletContexts.containsKey(servletContext)) {
+            PortletAppDD portletAppDD = PortletDescriptorRegistry.getRegistry()
+            		.getPortletAppDD(servletContext);
+            PortletContext portletContext = new PortletContextImpl(
+            		servletContext, portletAppDD);
+            portletContexts.put(servletContext, portletContext);
+        }
+        return (InternalPortletContext) portletContexts.get(servletContext);
+    }
+}

Added: portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletInvoker.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletInvoker.java?view=auto&rev=562725
==============================================================================
--- portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletInvoker.java (added)
+++ portals/pluto/branches/1.1-286-trunk-merge/pluto-container/src/main/java/org/apache/pluto/core/PortletInvoker.java Sat Aug  4 07:41:23 2007
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2003,2004 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.pluto.core;
+
+import java.io.IOException;
+
+import javax.portlet.PortletException;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pluto.Constants;
+import org.apache.pluto.internal.InternalPortletWindow;
+import org.apache.pluto.internal.impl.ActionRequestImpl;
+import org.apache.pluto.internal.impl.ActionResponseImpl;
+import org.apache.pluto.internal.impl.PortletRequestImpl;
+import org.apache.pluto.internal.impl.PortletResponseImpl;
+import org.apache.pluto.internal.impl.RenderRequestImpl;
+import org.apache.pluto.internal.impl.RenderResponseImpl;
+import org.apache.pluto.internal.impl.ResourceRequestImpl;
+import org.apache.pluto.internal.impl.ResourceResponseImpl;
+import org.apache.pluto.util.StringManager;
+
+/**
+ * Used internally to invoke/dispatch requests from the container to
+ * the portlet application.
+ *
+ * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
+ * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
+ */
+class PortletInvoker {
+
+    /** Logger.  */
+    private static final Log LOG = LogFactory.getLog(PortletInvoker.class);
+
+    /** Exception Messages. */
+    private static final StringManager EXCEPTIONS = StringManager.getManager(
+    		PortletInvoker.class.getPackage().getName());
+    
+    
+    // Private Member Variables ------------------------------------------------
+    
+    /** Portlet Window for which we are invoking the portlet. */
+    private InternalPortletWindow portletWindow = null;
+    
+    
+    // Constructor -------------------------------------------------------------
+    
+    /**
+     * Default Constructor.  Create a new invoker which
+     * is initialized for the given <code>InternalPortletWindow</code>.
+     *
+     * @param portletWindow  the portlet window.
+     */
+    public PortletInvoker(InternalPortletWindow portletWindow) {
+        this.portletWindow = portletWindow;
+    }
+    
+    
+    // Public Methods ----------------------------------------------------------
+    
+    /**
+     * Invoke the portlet with an action request.
+     *
+     * @param request action request used for the invocation.
+     * @param response action response used for the invocation.
+     * @throws PortletException if a error occurs within the portlet.
+     * @throws IOException if an IO error occurs writing the response.
+     *
+     * @see PortletServlet
+     * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
+     */
+    public void action(ActionRequestImpl request, ActionResponseImpl response)
+    throws PortletException, IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Performing Action Invocation");
+        }
+        invoke(request, response, Constants.METHOD_ACTION);
+    }
+
+        
+    /**
+     * Invoke the portlet with an resource request.
+     *
+     * @param request resource request used for the invocation.
+     * @param response resource response used for the invocation.
+     * @throws PortletException if a error occurs within the portlet.
+     * @throws IOException if an IO error occurs writing the response.
+     *
+     * @see PortletServlet
+     * @see javax.portlet.Portlet#processresource(javax.portlet.ResourceRequest, javax.portlet.ActionResponse)
+     */
+    public void resource(ResourceRequestImpl request, ResourceResponseImpl response)
+    throws PortletException, IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Performing Resource Invocation");
+        }
+        invoke(request, response, Constants.METHOD_RESOURCE);
+    }
+    
+    /**
+     * Invoke the portlet with a render request.
+     *
+     * @param request action request used for the invocation.
+     * @param response action response used for the invocation.
+     * @throws PortletException if a error occurs within the portlet.
+     * @throws IOException if an IO error occurs writing the response.
+     *
+     * @see PortletServlet
+     * @see javax.portlet.Portlet#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
+     */
+    public void render(RenderRequestImpl request, RenderResponseImpl response)
+    throws PortletException, IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Performing Render Invocation");
+        }
+        invoke(request, response, Constants.METHOD_RENDER);
+    }
+
+    /**
+     * Invoke the portlet with a load request.
+     *
+     * @param request action request used for the invocation.
+     * @param response action response used for the invocation.
+     * @throws PortletException if a error occurs within the portlet.
+     *
+     * @see PortletServlet
+     */
+    public void load(PortletRequestImpl request, PortletResponseImpl response)
+    throws PortletException, IOException {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Performing Load Invocation");
+        }
+        invoke(request, response, Constants.METHOD_NOOP);
+    }
+    
+    /**
+     * Invoke the portlet with an event request.
+     * 
+     * @param request
+     * @param response
+     * @throws PortletException
+     * @throws IOException
+     */
+    public void event(PortletRequestImpl request, PortletResponseImpl response)
+    throws PortletException, IOException {
+    	if (LOG.isDebugEnabled()) {
+    		LOG.debug("Performing Event Invocation");
+    	}
+    	invoke(request, response, Constants.METHOD_EVENT);
+    }
+    
+    
+    // Private Invoke Method ---------------------------------------------------
+    
+    /**
+     * Perform the invocation.
+     *
+     * @param request portlet request
+     * @param response portlet response
+     * @param methodID method identifier
+     * @throws PortletException if a portlet exception occurs.
+     * @throws IOException if an error occurs writing to the response.
+     */
+    private void invoke(PortletRequestImpl request,
+                        PortletResponseImpl response,
+                        Integer methodID)
+    throws PortletException, IOException {
+
+        String uri = portletWindow.getPortletEntity().getControllerServletUri();
+        if (LOG.isDebugEnabled()) {
+        	LOG.debug("Dispatching to portlet servlet at: " + uri);
+        }
+        
+        ServletContext servletContext = portletWindow.getServletContext();
+        RequestDispatcher dispatcher = servletContext.getRequestDispatcher(uri);
+
+        if (dispatcher != null) {
+            try {
+                // Tomcat does not like to properly include wrapped requests
+                // and responses. Thus we "unwrap" and then include.
+                HttpServletRequest servletRequest =
+                		request.getHttpServletRequest();
+                HttpServletResponse servletResponse =
+                		response.getHttpServletResponse();
+                
+                servletRequest.setAttribute(Constants.METHOD_ID, methodID);
+                servletRequest.setAttribute(Constants.PORTLET_REQUEST, request);
+                servletRequest.setAttribute(Constants.PORTLET_RESPONSE, response);
+                
+                dispatcher.include(servletRequest, servletResponse);
+
+            } catch (javax.servlet.UnavailableException ex) {
+                int seconds = ex.isPermanent()?-1:ex.getUnavailableSeconds();
+                String message =  EXCEPTIONS.getString(
+                    "error.portlet.invoker.unavailable",
+                    uri, new String[] {String.valueOf(seconds)}
+                );
+                if (LOG.isErrorEnabled()) {
+                    LOG.error(message, ex);
+                }
+                throw new javax.portlet.UnavailableException(
+                        message, seconds);
+                
+            } catch (javax.servlet.ServletException ex) {
+                String message = EXCEPTIONS.getString("error.portlet.invoker");
+                if(LOG.isErrorEnabled()) {
+                    LOG.error(message);
+                }
+
+                if (ex.getRootCause() != null &&
+                    ex.getRootCause() instanceof PortletException) {
+                        throw (PortletException) ex.getRootCause();
+                }
+                else if(ex.getRootCause() != null) {
+                    throw new PortletException(ex.getRootCause());
+                }
+                else {
+                    throw new PortletException(ex);
+                }
+                
+            } finally {
+                request.removeAttribute(Constants.METHOD_ID);
+                request.removeAttribute(Constants.PORTLET_REQUEST);
+                request.removeAttribute(Constants.PORTLET_RESPONSE);
+            }
+        } else {
+            String msg = EXCEPTIONS.getString(
+                "error.portlet.invoker.dispatcher",
+                new String[] {servletContext.getServletContextName(), uri}
+            );
+            if (LOG.isErrorEnabled()) {
+                LOG.error(msg);
+            }
+            throw new PortletException(msg);
+        }
+    }
+
+}