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 2008/10/23 05:13:44 UTC

svn commit: r707252 - in /portals/pluto/branches/2.0-spi-refactoring: pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/ pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/ pluto-portal-driver...

Author: cdoremus
Date: Wed Oct 22 20:13:43 2008
New Revision: 707252

URL: http://svn.apache.org/viewvc?rev=707252&view=rev
Log:
Fix for PLUTO-513 to support portlet managed modes as defined in PLT.8.4. of the JSR-286 spec.

Modified:
    portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java
    portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java
    portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java
    portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedModesService.java
    portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java
    portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/portlet.xml
    portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/themes/portlet-skin.jsp
    portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/pluto.css

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java?rev=707252&r1=707251&r2=707252&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/config/impl/DriverConfigurationImpl.java Wed Oct 22 20:13:43 2008
@@ -17,9 +17,13 @@
 package org.apache.pluto.driver.config.impl;
 
 import java.util.Collection;
+import java.util.Set;
 
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletMode;
 import javax.servlet.ServletContext;
 
+import org.apache.pluto.PortletContainerException;
 import org.apache.pluto.driver.config.DriverConfiguration;
 import org.apache.pluto.driver.services.portal.PageConfig;
 import org.apache.pluto.driver.services.portal.PropertyConfigService;
@@ -218,5 +222,17 @@
 //    public Collection getPortletApplications() {
 //        return registryService.getPortletApplications();
 //    }
+
+    public Set<PortletMode> getSupportedPortletModes(String portletId) throws PortletContainerException {
+    	return supportedModesService.getSupportedPortletModes(portletId);
+    }
+
+	public boolean isPortletManagedMode(String portletId, String mode) {
+		return supportedModesService.isPortletManagedMode(portletId, mode);
+	}
+	
+    public PortletConfig getPortletConfig(String portletId)  throws PortletContainerException {
+    	return supportedModesService.getPortletConfig(portletId);
+    }
 }
 

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java?rev=707252&r1=707251&r2=707252&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java Wed Oct 22 20:13:43 2008
@@ -16,12 +16,11 @@
  */
 package org.apache.pluto.driver.services.impl.resource;
 
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.Set;
 
+import javax.portlet.PortletConfig;
 import javax.portlet.PortletMode;
 import javax.servlet.ServletContext;
 
@@ -29,6 +28,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.pluto.PortletContainer;
 import org.apache.pluto.PortletContainerException;
+import org.apache.pluto.descriptors.portlet.CustomPortletModeType;
 import org.apache.pluto.driver.AttributeKeys;
 import org.apache.pluto.driver.config.DriverConfigurationException;
 import org.apache.pluto.driver.services.portal.PortletWindowConfig;
@@ -55,11 +55,9 @@
     /** Logger */
     private static final Log LOG = LogFactory.getLog(SupportedModesServiceImpl.class);
 
-    /** Sets containing PortletMode objects keyed by String portlet Id */
-    private Map supportedPortletModesByPortlet = new HashMap();
     
     /** PortletMode objects supported by the portal */
-    private Set supportedPortletModesByPortal = new HashSet();
+    private Set<PortletMode> supportedPortletModesByPortal = new HashSet<PortletMode>();
 
     /** PortletRegistryService used to obtain PortletApplicationConfig objects */
     private PortletRegistryService portletRegistry;
@@ -82,8 +80,9 @@
     //  SupportedModesService Implementation -----------------
 
     public boolean isPortletModeSupported(String portletId, String mode)  {
-        return isPortletManagedMode(portletId, mode) || (isPortletModeSupportedByPortal(mode) &&
-            isPortletModeSupportedByPortlet(portletId, mode));
+        return (isPortletModeSupportedByPortal(mode) &&
+            isPortletModeSupportedByPortlet(portletId, mode)
+            || isPortletManagedMode(portletId, mode));
     }
 
     public boolean isPortletModeSupportedByPortal(String mode)  {
@@ -174,28 +173,117 @@
             supportedPortletModesByPortal.add(new PortletMode(mode));
         }
         LOG.debug("Loaded [" + supportedPortletModesByPortal.size() + "] supported portal modes");
+
     }
+
+
     
 	public boolean isPortletManagedMode(String portletId, String mode) {
-		//FIXME: This needs to be implemented properly:
-		// 1. Need to create a Map of custom modes (CustomModeDD) keyed by portlet ID in init().
-		//		a. Each mode has a 'portal-managed' property (true is default)
-		// 2. Add code to this method like this:
-//		PortletMode oMode = null;		
-//		CustomModeDD cmode = null;		
-//		if (mode != null) {
-//			oMode = new PortletMode(mode);		
-//		}
-//		cmode = customModes.get(portletId);		
-//		if (portletId != null && mode != null && cmode != null 
-//			&& supportedPortletModesByPortlet.get(portletId).equals(oMode)
-//			&& cmode.getPortletMode().equals(mode) && !cmode.isPortalManaged()) {
-//			return true;
-//		} else {
-//			return false;
-//		}
-			return false;
+
+		if (portletRegistry == null) {
+            portletRegistry = ((PortletContainer)servletContext
+                    .getAttribute(AttributeKeys.PORTLET_CONTAINER))
+                    .getOptionalContainerServices()
+                    .getPortletRegistryService();
+        }
+        //
+        
+        //
+        String applicationId = PortletWindowConfig.parseContextPath(portletId);
+        String applicationName = applicationId;
+        if (applicationName.length() > 0 )
+        {
+            applicationName = applicationName.substring(1);
+        }
+        try {
+			PortletApplicationDefinition portletApp = portletRegistry.getPortletApplication(applicationName);
+            Iterator customModes = portletApp.getCustomPortletModes().iterator();
+            while (customModes.hasNext()) {
+				CustomPortletModeType customMode = (CustomPortletModeType)customModes.next();
+				boolean isPortletManagedMode = !customMode.isPortalManaged(); 
+				if (isPortletManagedMode && customMode.getPortletMode().equalsIgnoreCase(mode)) {
+					return true;
+				}
+			}
+		} catch (PortletContainerException e) {
+            LOG.error("Error determining portlet managed mode support, so we assume that it is false.", e);
+		}
+
+		
+		return false;
 	}
 
 
+	/**
+	 * Gets all modes supported by a portlet that are defined in the portlet's supports child element 
+	 * in portlet.xml.
+	 * 
+	 * @param portlet of interest.
+	 * @return all portlet modes supported by a portlet.
+	 */
+	public Set<PortletMode> getSupportedPortletModes(String portletId) throws PortletContainerException {
+		Set<PortletMode> modeSet = new HashSet<PortletMode>();
+
+	       String applicationId = PortletWindowConfig.parseContextPath(portletId);
+	        String applicationName = applicationId;
+	        if (applicationName.length() >0 )
+	        {
+	            applicationName = applicationName.substring(1);
+	        }
+	        String portletName = PortletWindowConfig.parsePortletName(portletId);
+	        // since SupportedModesService is consulted per portal portal mode per portlet
+	        // per render request, store a reference to the registry instead of looking
+	        // it up each time.  Is this premature optimization?
+	        if (portletRegistry == null) {
+	            portletRegistry = ((PortletContainer)servletContext
+	                    .getAttribute(AttributeKeys.PORTLET_CONTAINER))
+	                    .getOptionalContainerServices()
+	                    .getPortletRegistryService();
+	        }
+
+            if (portletRegistry == null) {
+                LOG.error("Optional Portlet Registry Service not found.");
+                throw new PortletContainerException("Optional Portlet Registry Service not found.");
+            }
+            PortletApplicationDefinition portletApp = portletRegistry.getPortletApplication(applicationName);
+            Iterator i =  portletApp.getPortlets().iterator();
+            while(i.hasNext()) {
+                PortletDefinition dd = (PortletDefinition)i.next();
+                if(portletName.equals(dd.getPortletName())) {
+                    Iterator i2 = dd.getSupports().iterator();
+                    while(i2.hasNext()) {
+                        Supports sd = (Supports)i2.next();
+                        if (sd.getPortletModes()== null){
+                        	modeSet.add(PortletMode.VIEW);
+                        }
+                        else{
+	                        Iterator<String> pd = sd.getPortletModes().iterator();
+	                        while(pd.hasNext()) {
+	                        	modeSet.add(new PortletMode(pd.next()));
+	                        }
+                        }
+                    }
+                }
+            }
+
+		return modeSet;
+	}
+	
+	public PortletConfig getPortletConfig(String portletId) throws PortletContainerException {
+	       String applicationId = PortletWindowConfig.parseContextPath(portletId);
+	        String applicationName = applicationId;
+	        if (applicationName.length() >0 )
+	        {
+	            applicationName = applicationName.substring(1);
+	        }
+	        String portletName = PortletWindowConfig.parsePortletName(portletId);
+	        if (portletRegistry == null) {
+	            portletRegistry = ((PortletContainer)servletContext
+	                    .getAttribute(AttributeKeys.PORTLET_CONTAINER))
+	                    .getOptionalContainerServices()
+	                    .getPortletRegistryService();
+	        }
+	        
+		return portletRegistry.getPortletConfig(applicationName, portletName);
+	}
 }

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java?rev=707252&r1=707251&r2=707252&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/config/DriverConfiguration.java Wed Oct 22 20:13:43 2008
@@ -16,9 +16,13 @@
 package org.apache.pluto.driver.config;
 
 import java.util.Collection;
+import java.util.Set;
 
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletMode;
 import javax.servlet.ServletContext;
 
+import org.apache.pluto.PortletContainerException;
 import org.apache.pluto.driver.services.portal.PageConfig;
 import org.apache.pluto.driver.services.portal.RenderConfigService;
 import org.apache.pluto.driver.url.PortalURLParser;
@@ -117,4 +121,10 @@
     
     public RenderConfigService getRenderConfigService();
 
+    public Set<PortletMode> getSupportedPortletModes(String portletId) throws PortletContainerException; 
+    
+    public PortletConfig getPortletConfig(String portletId)  throws PortletContainerException;
+
+	public boolean isPortletManagedMode(String portletId, String mode);
+    
 }

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedModesService.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedModesService.java?rev=707252&r1=707251&r2=707252&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedModesService.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/services/portal/SupportedModesService.java Wed Oct 22 20:13:43 2008
@@ -16,8 +16,13 @@
  */
 package org.apache.pluto.driver.services.portal;
 
+import java.util.Set;
+
+import javax.portlet.PortletConfig;
 import javax.portlet.PortletMode;
 
+import org.apache.pluto.PortletContainerException;
+
 /**
  * Allows clients to determine if a particular PortletMode is supported
  * by the portal, a particular portlet, or both.
@@ -62,4 +67,17 @@
      * @return
      */
     boolean isPortletManagedMode(String portletId, String mode);    
+
+	/**
+	 * Gets all modes supported by a portlet that are defined in the portlet's supports child element 
+	 * in portlet.xml.
+	 * 
+     * @param portletId Id of the portlet of interest
+	 * @return all portlet modes supported by a portlet.
+	 * @throws PortletContainerException
+     */
+    Set<PortletMode> getSupportedPortletModes(String portletId) throws PortletContainerException;
+
+	PortletConfig getPortletConfig(String portletId) throws PortletContainerException;
+
 }

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java?rev=707252&r1=707251&r2=707252&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletWindowStateAnchorTag.java Wed Oct 22 20:13:43 2008
@@ -48,8 +48,12 @@
 
 
     // Private Member Variables ------------------------------------------------
+    /** Window state name */
     private String state;
 
+    /** Context-relative URL to icon representing window state */
+	private String icon;
+    
     /** The portlet ID attribute obtained from parent tag. */
     private String portletId;
 
@@ -100,8 +104,8 @@
             tag.append(ToolTips.forWindowState(new WindowState(state)));
             tag.append("\" ");
             tag.append("href=\"" + portalUrl.toString() + "\">");
-            tag.append("<span class=\"" + state + "\">");
-            tag.append("</span></a>");
+            tag.append("<img border=\"0\" src=\"" + icon + "\" />");
+            tag.append("</a>");
 
             // Print the mode anchor tag.
             try {
@@ -161,6 +165,15 @@
         this.state = state;
     }
 
+    public String getIcon() {
+		return icon;
+	}
+
+
+	public void setIcon(String icon) {
+		this.icon = icon;
+	}
+    
     private boolean isWindowStateAllowed(DriverConfiguration config, String state) {
         LOG.debug("Testing if PortletWindowConfig [" + getEvaluatedPortletId() + "] supports window state [" + state + "]");
         return config.isWindowStateSupported(getEvaluatedPortletId(), state);

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/portlet.xml?rev=707252&r1=707251&r2=707252&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/portlet.xml (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/portlet.xml Wed Oct 22 20:13:43 2008
@@ -64,7 +64,6 @@
         <supports>
             <mime-type>text/html</mime-type>
             <portlet-mode>VIEW</portlet-mode>
-            <portlet-mode>EDIT</portlet-mode>
             <portlet-mode>HELP</portlet-mode>
         </supports>
         <portlet-info>

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/themes/portlet-skin.jsp
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/themes/portlet-skin.jsp?rev=707252&r1=707251&r2=707252&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/themes/portlet-skin.jsp (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/WEB-INF/themes/portlet-skin.jsp Wed Oct 22 20:13:43 2008
@@ -24,18 +24,23 @@
 
   <!-- Assemble the rendering result -->
   <div class="portlet">
-    <div class="header">
-      <!-- Portlet Mode Controls -->
-      <pluto:modeAnchor portletMode="view"/>
-      <pluto:modeAnchor portletMode="edit"/>
-      <pluto:modeAnchor portletMode="help"/>
-      <!-- Window State Controls -->
-      <pluto:windowStateAnchor windowState="minimized"/>
-      <pluto:windowStateAnchor windowState="maximized"/>
-      <pluto:windowStateAnchor windowState="normal"/>
-      <!-- Portlet Title -->
-      <h2 class="title"><pluto:title/></h2>
-    </div>
+    <table class="header" width="100%">
+    	<tr>
+    	<td class="header" align="left">
+	      <!-- Portlet Title -->
+	      <h2 class="title"><pluto:title/></h2>
+	</td>
+        <td class="header" align="right">
+	      <!-- Portlet Mode Controls -->
+	      <pluto:modeDropDown />
+	
+	      <!-- Window State Controls -->
+	      <pluto:windowStateAnchor windowState="minimized" icon="<%= request.getContextPath() + "/images/controls/min.png"%>" />
+	      <pluto:windowStateAnchor windowState="maximized" icon="<%= request.getContextPath() + "/images/controls/max.png"%>" />
+	      <pluto:windowStateAnchor windowState="normal" icon="<%= request.getContextPath() + "/images/controls/norm.png"%>" />
+    	</td>
+    	</tr>
+    </table>
     <div class="body">
       <pluto:render/>
     </div>

Modified: portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/pluto.css
URL: http://svn.apache.org/viewvc/portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/pluto.css?rev=707252&r1=707251&r2=707252&view=diff
==============================================================================
--- portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/pluto.css (original)
+++ portals/pluto/branches/2.0-spi-refactoring/pluto-portal/src/main/webapp/pluto.css Wed Oct 22 20:13:43 2008
@@ -108,14 +108,13 @@
 }
 
 .portlet {
-  margin: 10px 0px 10px 0px;
+  margin: 0px;
   padding: 0px;
   border: 1px solid #2E6794;
 }
 
 .portlet .header {
   white-space: nowrap;
-  padding-left: 0.25em;
   background-color: #8DB7DF;
   color: #FFFFFF;
   font-weight: bold;