portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msnickl...@apache.org
Subject portals-pluto git commit: Fixed problem where default view mode was not being recognized. Fixed problem with custom portlet modes not being recognized.
Date Tue, 23 Aug 2016 12:24:13 GMT
Repository: portals-pluto
Updated Branches:
  refs/heads/master 8f6f25f74 -> f88150568


Fixed problem where default view mode was not being recognized. Fixed
problem with custom portlet modes not being recognized.


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/f8815056
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/f8815056
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/f8815056

Branch: refs/heads/master
Commit: f881505689c42b3b994ae525270fbd8ac26e2fe7
Parents: 8f6f25f
Author: Scott Nicklous <msnicklous@apache.org>
Authored: Tue Aug 23 14:22:27 2016 +0200
Committer: Scott Nicklous <msnicklous@apache.org>
Committed: Tue Aug 23 14:22:27 2016 +0200

----------------------------------------------------------------------
 .../basic/portlet/PortletConfigPortlet.java     |  21 +
 .../src/main/resources/logging.properties       |   1 +
 .../src/main/webapp/WEB-INF/jsp/view-pcp.jsp    |   1 +
 .../resource/SupportedModesServiceImpl.java     | 409 ++++++--------
 .../driver/tags/PortletModeDropDownTag.java     | 546 +++++++++----------
 5 files changed, 475 insertions(+), 503 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f8815056/PortletV3Demo/src/main/java/basic/portlet/PortletConfigPortlet.java
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/java/basic/portlet/PortletConfigPortlet.java b/PortletV3Demo/src/main/java/basic/portlet/PortletConfigPortlet.java
index fa460db..8c67cb7 100644
--- a/PortletV3Demo/src/main/java/basic/portlet/PortletConfigPortlet.java
+++ b/PortletV3Demo/src/main/java/basic/portlet/PortletConfigPortlet.java
@@ -40,6 +40,7 @@ import javax.portlet.PortletContext;
 import javax.portlet.PortletException;
 import javax.portlet.PortletMode;
 import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderMode;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.ResourceRequest;
@@ -55,6 +56,26 @@ public class PortletConfigPortlet extends GenericPortlet {
    // Set up logging
    private static final String LOG_CLASS = PortletConfigPortlet.class.getName();
    private final Logger logger = Logger.getLogger(LOG_CLASS);
+   
+   @Override
+   protected void doHelp(RenderRequest request, RenderResponse response) throws PortletException,
IOException {
+      doView(request, response);
+   }
+   
+   @Override
+   protected void doEdit(RenderRequest request, RenderResponse response) throws PortletException,
IOException {
+      doView(request, response);
+   }
+   
+   @RenderMode(name="MyMode_nonPortalManaged_1")
+   public void doMyMode_nonPortalManaged_1(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
+      doView(request, response);
+   }
+   
+   @RenderMode(name="MyMode_nonPortalManaged_2")
+   public void doMyMode_nonPortalManaged_2(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
+      doView(request, response);
+   }
 
    protected void doView(RenderRequest req, RenderResponse resp)
          throws PortletException, IOException {

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f8815056/PortletV3Demo/src/main/resources/logging.properties
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/resources/logging.properties b/PortletV3Demo/src/main/resources/logging.properties
index a83e946..0542296 100644
--- a/PortletV3Demo/src/main/resources/logging.properties
+++ b/PortletV3Demo/src/main/resources/logging.properties
@@ -34,4 +34,5 @@ org.apache.juli.FileHandler.directory = ${catalina.base}/logs
 org.apache.juli.FileHandler.prefix = PortletV3Demo.
 
 org.apache.pluto.level=FINE
+javax.portlet.level=FINEST
 basic.portlet.level=FINEST

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f8815056/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-pcp.jsp
----------------------------------------------------------------------
diff --git a/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-pcp.jsp b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-pcp.jsp
index 75e9f1f..ba56f3a 100644
--- a/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-pcp.jsp
+++ b/PortletV3Demo/src/main/webapp/WEB-INF/jsp/view-pcp.jsp
@@ -35,6 +35,7 @@ limitations under the License.
 <hr/>
 <p>This portlet displays information from the new V3.0 PortletConfig APIs
 getPortletModes(String), getWindowStates(String), and getPublicRenderParameterDefinitions()</p>
+<h5>Current Portlet Mode: <%=renderRequest.getPortletMode().toString() %></h5>
 <h5>Portlet Modes:</h5>
 <ul>
 <c:forEach items="<%=renderRequest.getAttribute(ATTRIB_PMS) %>" var="pm">

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f8815056/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java
b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java
index 7c4f9e2..23eae44 100644
--- a/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java
+++ b/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/impl/resource/SupportedModesServiceImpl.java
@@ -16,254 +16,207 @@
  */
 package org.apache.pluto.driver.services.impl.resource;
 
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletMode;
+
 import org.apache.pluto.container.PortletContainerException;
 import org.apache.pluto.container.driver.PortletContextService;
 import org.apache.pluto.container.driver.PortletRegistryService;
+import org.apache.pluto.container.om.portlet.CustomPortletMode;
 import org.apache.pluto.container.om.portlet.PortletApplicationDefinition;
-import org.apache.pluto.container.om.portlet.PortletDefinition;
 import org.apache.pluto.container.om.portlet.Supports;
-import org.apache.pluto.container.om.portlet.CustomPortletMode;
 import org.apache.pluto.driver.services.portal.PortletWindowConfig;
 import org.apache.pluto.driver.services.portal.PropertyConfigService;
 import org.apache.pluto.driver.services.portal.SupportedModesService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletMode;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
 /**
- * Allows clients to determine if a particular PortletMode is supported
- * by the portal, a particular portlet, or both.
+ * Allows clients to determine if a particular PortletMode is supported by the portal, a
particular portlet, or both.
  * <p/>
  * This implementation depends on {@link PropertyConfigService}.
  * <p/>
  * The service implementations are injected by Spring.
- *
+ * 
  * @version $Id$
  * @since September 9, 2006
  */
-public class SupportedModesServiceImpl implements SupportedModesService
-{
-    /**
-     * Logger
-     */
-    private static final Logger LOG = LoggerFactory.getLogger(SupportedModesServiceImpl.class);
-
-
-    /**
-     * PortletMode objects supported by the portal
-     */
-    private Set<PortletMode> supportedPortletModesByPortal = new HashSet<PortletMode>();
-
-    /**
-     * PropertyConfig Service used to obtain supported portal modes
-     */
-    private final PropertyConfigService propertyService;
-
-    private final PortletContextService portletContextService;
-
-    /**
-     * PortletRegistryService used to obtain PortletApplicationConfig objects
-     */
-    private final PortletRegistryService portletRegistry;
-
-    /**
-     * Constructs a SupportedModesService with its dependencies.
-     *
-     * @param propertyService the PropertyConfigService
-     */
-    public SupportedModesServiceImpl(PropertyConfigService propertyService, PortletContextService
portletContextService, PortletRegistryService portletRegistry)
-    {
-        this.propertyService = propertyService;
-        this.portletContextService = portletContextService;
-        this.portletRegistry = portletRegistry;
-        loadPortalModes();
-    }
-
-    //  SupportedModesService Implementation -----------------
-
-    public boolean isPortletModeSupported(String portletId, String mode)
-    {
-        return (isPortletModeSupportedByPortal(mode) &&
-                isPortletModeSupportedByPortlet(portletId, mode)
-                || isPortletManagedMode(portletId, mode));
-    }
-
-    public boolean isPortletModeSupportedByPortal(String mode)
-    {
-        return supportedPortletModesByPortal.contains(new PortletMode(mode));
-    }
-
-    public boolean isPortletModeSupportedByPortlet(String portletId, String mode)
-    {
-        String applicationId = PortletWindowConfig.parseContextPath(portletId);
-        String applicationName = applicationId;
-        String portletName = PortletWindowConfig.parsePortletName(portletId);
-
-        try
-        {
-            if (portletRegistry == null)
-            {
-                LOG.error("Optional Portlet Registry Service not found.");
-                throw new PortletContainerException("Optional Portlet Registry Service not
found.");
-            }
-            PortletApplicationDefinition ctx = portletRegistry.getPortletApplication(applicationName);
-            Iterator<? extends PortletDefinition> i = ctx.getPortlets().iterator();
-            while (i.hasNext())
-            {
-                PortletDefinition dd = (PortletDefinition) i.next();
-                if (portletName.equals(dd.getPortletName()))
-                {
-                    Iterator<? extends Supports> i2 = dd.getSupports().iterator();
-                    while (i2.hasNext())
-                    {
-                        Supports sd = (Supports) i2.next();
-                        if (sd.getPortletModes() == null)
-                        {
-                            if (mode.equalsIgnoreCase(PortletMode.VIEW.toString()))
-                                return true;
-                        } else
-                        {
-                            Iterator<String> pd = sd.getPortletModes().iterator();
-                            while (pd.hasNext())
-                            {
-                                if (mode.equalsIgnoreCase((String) pd.next()))
-                                {
-                                    return true;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-        } catch (PortletContainerException e)
-        {
-            LOG.error("Error determining mode support.", e);
-        }
-        LOG.info("Portlet mode '" + mode + "' not found for portletId: '" + portletId + "'");
-        return false;
-    }
-
-    /**
-     * Populates the supportedPortletModesByPortal set.
-     */
-    private void loadPortalModes()
-    {
-        // Add the PortletModes supported by the portal to the
-        // supportedPortletModesByPortal set.
-        LOG.debug("Loading supported portal modes...");
-        Iterator<String> modes = propertyService.getSupportedPortletModes().iterator();
-        while (modes.hasNext())
-        {
-            String mode = (String) modes.next();
-            LOG.debug("Loading mode [" + mode + "]");
-            supportedPortletModesByPortal.add(new PortletMode(mode));
-        }
-        LOG.debug("Loaded [" + supportedPortletModesByPortal.size() + "] supported portal
modes");
-
-    }
-
-
-    public boolean isPortletManagedMode(String portletId, String mode)
-    {
-        String applicationId = PortletWindowConfig.parseContextPath(portletId);
-        String applicationName = applicationId;
-//        if (applicationName.length() > 0)
-//        {
-//            applicationName = applicationName.substring(1);
-//        }
-        try
-        {
-            PortletApplicationDefinition portletApp = portletRegistry.getPortletApplication(applicationName);
-            Iterator<? extends CustomPortletMode> customModes = portletApp.getCustomPortletModes().iterator();
-            while (customModes.hasNext())
-            {
-                CustomPortletMode customMode = (CustomPortletMode) 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 portletId 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);
-
-        if (portletRegistry == null)
-        {
+public class SupportedModesServiceImpl implements SupportedModesService {
+   /**
+    * Logger
+    */
+   private static final Logger          LOG                           = LoggerFactory.getLogger(SupportedModesServiceImpl.class);
+
+   /**
+    * PortletMode objects supported by the portal
+    */
+   private Set<PortletMode>             supportedPortletModesByPortal = new HashSet<PortletMode>();
+
+   /**
+    * PropertyConfig Service used to obtain supported portal modes
+    */
+   private final PropertyConfigService  propertyService;
+
+   private final PortletContextService  portletContextService;
+
+   /**
+    * PortletRegistryService used to obtain PortletApplicationConfig objects
+    */
+   private final PortletRegistryService portletRegistry;
+
+   /**
+    * Constructs a SupportedModesService with its dependencies.
+    * 
+    * @param propertyService
+    *           the PropertyConfigService
+    */
+   public SupportedModesServiceImpl(PropertyConfigService propertyService, PortletContextService
portletContextService, PortletRegistryService portletRegistry) {
+      this.propertyService = propertyService;
+      this.portletContextService = portletContextService;
+      this.portletRegistry = portletRegistry;
+      loadPortalModes();
+   }
+
+   // SupportedModesService Implementation -----------------
+
+   public boolean isPortletModeSupported(String portletId, String mode) {
+      if (LOG.isDebugEnabled()) {
+         StringBuilder txt = new StringBuilder();
+         txt.append("Determining support for PM: ").append(mode);
+         txt.append(", portletID: ").append(portletId);
+         txt.append(", by portal: ").append(isPortletModeSupportedByPortal(mode));
+         txt.append(", by portlet: ").append(isPortletModeSupportedByPortlet(portletId, mode));
+         txt.append(", is portlet managed: ").append(isPortletManagedMode(portletId, mode));
+         LOG.debug(txt.toString());
+      }
+      return (isPortletModeSupportedByPortal(mode) && isPortletModeSupportedByPortlet(portletId,
mode) || isPortletManagedMode(portletId, mode));
+   }
+
+   public boolean isPortletModeSupportedByPortal(String mode) {
+      return supportedPortletModesByPortal.contains(new PortletMode(mode));
+   }
+
+   public boolean isPortletModeSupportedByPortlet(String portletId, String mode) {
+
+      // View mode is always supported
+      if (mode.equalsIgnoreCase(PortletMode.VIEW.toString())) {
+         return true;
+      }
+
+      String applicationId = PortletWindowConfig.parseContextPath(portletId);
+      String applicationName = applicationId;
+      String portletName = PortletWindowConfig.parsePortletName(portletId);
+
+      try {
+         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<? extends PortletDefinition> i = portletApp.getPortlets().iterator();
-        while (i.hasNext())
-        {
-            PortletDefinition dd = (PortletDefinition) i.next();
-            if (portletName.equals(dd.getPortletName()))
-            {
-                Iterator<? extends Supports> 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()));
-                        }
-                    }
-                }
+         }
+         PortletApplicationDefinition ctx = portletRegistry.getPortletApplication(applicationName);
+
+         for (Supports sd : ctx.getPortlet(portletName).getSupports()) {
+            if (sd.getMimeType().matches("(?:\\*|\\*/\\*|text/html|text/\\*)")) {
+               for (String pm : sd.getPortletModes()) {
+                  if (pm.equalsIgnoreCase(mode)) {
+                     return true;
+                  }
+               }
             }
-        }
-
-        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);
-
-        return portletContextService.getPortletConfig(applicationName, portletName);
-    }
+         }
+
+      } catch (PortletContainerException e) {
+         LOG.error("Error determining mode support.", e);
+      }
+      LOG.info("Portlet mode '" + mode + "' not found for portletId: '" + portletId + "'");
+      return false;
+   }
+
+   /**
+    * Populates the supportedPortletModesByPortal set.
+    */
+   private void loadPortalModes() {
+      // Add the PortletModes supported by the portal to the
+      // supportedPortletModesByPortal set.
+      LOG.debug("Loading supported portal modes...");
+      Iterator<String> modes = propertyService.getSupportedPortletModes().iterator();
+      while (modes.hasNext()) {
+         String mode = (String) modes.next();
+         LOG.debug("Loading mode [" + mode + "]");
+         supportedPortletModesByPortal.add(new PortletMode(mode));
+      }
+      LOG.debug("Loaded [" + supportedPortletModesByPortal.size() + "] supported portal modes");
+
+   }
+
+   public boolean isPortletManagedMode(String portletId, String mode) {
+      String applicationId = PortletWindowConfig.parseContextPath(portletId);
+      String applicationName = applicationId;
+      // if (applicationName.length() > 0)
+      // {
+      // applicationName = applicationName.substring(1);
+      // }
+      try {
+         PortletApplicationDefinition portletApp = portletRegistry.getPortletApplication(applicationName);
+         Iterator<? extends CustomPortletMode> customModes = portletApp.getCustomPortletModes().iterator();
+         while (customModes.hasNext()) {
+            CustomPortletMode customMode = (CustomPortletMode) 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 portletId
+    *           of interest.
+    * @return all portlet modes supported by a portlet.
+    */
+   public Set<PortletMode> getSupportedPortletModes(String portletId) throws PortletContainerException
{
+      Set<PortletMode> modeSet = new HashSet<PortletMode>();
+      modeSet.add(PortletMode.VIEW); // view is always supported
+
+      String applicationId = PortletWindowConfig.parseContextPath(portletId);
+      String applicationName = applicationId;
+      String portletName = PortletWindowConfig.parsePortletName(portletId);
+
+      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);
+
+      for (Supports sd : portletApp.getPortlet(portletName).getSupports()) {
+         if (sd.getMimeType().matches("(?:\\*|\\*/\\*|text/html|text/\\*)")) {
+            for (String pm : sd.getPortletModes()) {
+               modeSet.add((new PortletMode(pm)));
+            }
+         }
+      }
+
+      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);
+
+      return portletContextService.getPortletConfig(applicationName, portletName);
+   }
 }

http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/f8815056/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletModeDropDownTag.java
----------------------------------------------------------------------
diff --git a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletModeDropDownTag.java
b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletModeDropDownTag.java
index dd1cd13..fc32440 100644
--- a/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletModeDropDownTag.java
+++ b/pluto-portal-driver/src/main/java/org/apache/pluto/driver/tags/PortletModeDropDownTag.java
@@ -1,275 +1,271 @@
-/*
- * 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.driver.tags;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.ResourceBundle;
-import java.util.Set;
-
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletMode;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequest;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspWriter;
-import javax.servlet.jsp.tagext.BodyTagSupport;
-import javax.servlet.jsp.tagext.TagSupport;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.pluto.container.PortletContainer;
-import org.apache.pluto.container.PortletContainerException;
-import org.apache.pluto.container.PortletWindow;
-import org.apache.pluto.driver.AttributeKeys;
-import org.apache.pluto.driver.config.DriverConfiguration;
-import org.apache.pluto.driver.core.PortalRequestContext;
-import org.apache.pluto.driver.core.PortletWindowImpl;
-import org.apache.pluto.driver.services.portal.PortletWindowConfig;
-import org.apache.pluto.driver.url.PortalURL;
-import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
-
-/**
- * The tag is used to render a portlet mode anchor specified by the portlet ID and mode.
- * This is designed to live inside of a <pluto:portlet/> tag.
- * 
- * <pluto:modeDropDown />
- *
- */
-public class PortletModeDropDownTag extends BodyTagSupport {
-    
-	private static final long serialVersionUID = 1L;
-
-
-	/** Logger. */
-    private static final Logger LOG = LoggerFactory.getLogger(PortletModeDropDownTag.class);
-        
-    
-    // Private Member Variables ------------------------------------------------
-    private String portletMode = null;
-    
-    /** The portlet ID attribute obtained from parent tag. */
-    private String portletId = null;
-    
-    /** The evaluated value of the portlet ID attribute. */
-    private String evaluatedPortletId = null;       
-    
-    // BodyTagSupport Impl -----------------------------------------------------
-    
-    /**
-     * Method invoked when the start tag is encountered.
-     * @throws JspException  if an error occurs.
-     */
-    public int doStartTag() throws JspException {
-        
-        // Ensure that the modeAnchor tag resides within a portlet tag.
-        PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(
-                this, PortletTag.class);
-        if (parentTag == null) {
-            throw new JspException("Portlet window controls may only reside "
-                    + "within a pluto:portlet tag.");
-        }
-        
-        portletId = parentTag.getPortletId();        
-        // Evaluate portlet ID attribute.
-        evaluatePortletId();
-        
-        // Retrieve the portlet window config for the evaluated portlet ID.
-        ServletContext servletContext = pageContext.getServletContext();
-        DriverConfiguration driverConfig = (DriverConfiguration)
-                servletContext.getAttribute(AttributeKeys.DRIVER_CONFIG);
-        
-        // Retrieve the portal environment.
-        PortalRequestContext portalEnv = PortalRequestContext.getContext(
-                (HttpServletRequest) pageContext.getRequest());        
-        
-        //find the current mode for use in 'selected' attrib of select option
-		PortalURL requestedPortalUrl = portalEnv.getRequestedPortalURL();
-        PortletWindowConfig windowConfig =
-            PortletWindowConfig.fromId(evaluatedPortletId);
-        // Retrieve the portlet container from servlet context.
-        PortletContainer container = (PortletContainer)
-                servletContext.getAttribute(AttributeKeys.PORTLET_CONTAINER);
-        
-        // Create the portlet window to render.
-        PortletWindow window = null;
-        
-        
-        try
-        {
-        	// If this fails it means that the portlet will be not available.
-        	// Render Tag will take care of it.
-        	window = new PortletWindowImpl(container, windowConfig, requestedPortalUrl);
-        }
-        catch(RuntimeException ex) 
-        {
-        	  if (LOG.isDebugEnabled()) {
-                  LOG.debug("The portlet " + windowConfig.getPortletName() + " is not available.
Is already deployed?");
-              }
-        }
-		
-        //start the markup
-        StringBuffer tag = new StringBuffer();
-     
-        // Do not render if we don't have a window.
-        if(window!=null)
-        {
-        	PortletMode currentMode = requestedPortalUrl.getPortletMode(window.getId().getStringId());
-
-
-        	//        String strCurrentMode = currentMode.toString();        
-        	//        tag.append("Current mode: " + currentMode.toString());
-        	tag.append("<form action=\"\" name=\"modeSelectionForm\" style=\"display:inline\"><select
onchange=\"self.location=this.options[this.selectedIndex].value\">");
-        	Set<PortletMode> modeSet = null;
-        	try {
-        		modeSet = driverConfig.getSupportedPortletModes(evaluatedPortletId);
-        	} catch (PortletContainerException e) {
-        		throw new JspException(e);
-        	}
-
-        	if (modeSet != null) {
-        		Iterator<PortletMode> i = modeSet.iterator();
-        		while (i.hasNext()) {
-        			PortletMode mode = i.next();
-
-        			PortalURL portalUrl =  portalEnv.createPortalURL();
-        			portalUrl.setPortletMode(evaluatedPortletId, mode);
-
-        			// Build a string buffer containing the anchor tag
-        			tag.append("<option value=\"" + portalUrl.toString() + "\"");
-        			//Add 'selected' attribute for current mode.
-        			if (mode.equals(currentMode)) {
-        				tag.append(" selected=\"true\"");
-        			}
-        			tag.append(">");
-        			if (driverConfig.isPortletManagedMode(evaluatedPortletId, mode.toString())) {
-        				tag.append(getCustomModeDecorationName(driverConfig, mode));	            	
-        			} else {
-        				tag.append(mode.toString().toUpperCase());
-        			}
-        			//	            tag.append(mode.toString().toUpperCase());
-        			tag.append("</option>");
-        		}
-        	}
-        	tag.append("</select></form>");
-
-        }
-        
-        // Print the mode anchor tag.
-        try {
-            JspWriter out = pageContext.getOut();
-            out.print(tag.toString());
-        } catch (IOException ex) {
-            throw new JspException(ex);
-        }
-        
-        // Continue to evaluate the tag body.
-        return EVAL_BODY_INCLUDE;
-    }
-    
-    // Package Methods ---------------------------------------------------------
-    
-    /**
-     * Returns the evaluated portlet ID.
-     * @return the evaluated portlet ID.
-     */
-    String getEvaluatedPortletId() {
-        return evaluatedPortletId;
-    }
-
-    
-    
-    // Private Methods ---------------------------------------------------------
-    
-    /**
-     * Evaluates the portlet ID attribute passed into this tag. This method
-     * evaluates the member variable <code>portletId</code> and saves the
-     * evaluated result to <code>evaluatedPortletId</code>
-     * @throws JspException  if an error occurs.
-     */
-    private void evaluatePortletId() throws JspException {
-        Object obj = ExpressionEvaluatorManager.evaluate(
-                "portletId", portletId, String.class, this, pageContext);
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Evaluated portletId to: " + obj);
-        }
-        evaluatedPortletId = (String) obj;
-    }
-
-    /**
-     * @return the portletMode
-     */
-    public String getPortletMode() {
-        return portletMode;
-    }
-
-    /**
-     * @param portletMode the portletMode to set
-     */
-    public void setPortletMode(String portletMode) {
-        this.portletMode = portletMode;
-    }
-    
-    private boolean isPortletModeAllowed(DriverConfiguration config, String mode) {
-        LOG.debug("Testing if PortletWindowConfig [" + getEvaluatedPortletId() + "] supports
mode [" + mode + "]");
-        return config.isPortletModeSupported(getEvaluatedPortletId(), mode);
-    }
-
-    /**
-     * Obtains decoration name for a portlet managed mode from the portlet's resource bundle
-     * as defined in PLT.8.4 of the JSR-286 spec using the key 
-     * javax.portlet.app.custom-portlet-mode.<custom mode>.decoration-name where
-     * custom mode is the name of the custom mode as defined in portlet.xml
-     * (//portlet-app/custom-portlet-mode/portlet-mode element). If the decoration
-     * name is not found in the resource bundle, this method returns the uppercased
-     * mode name.
-     * 
-     * @param driverConfig the driver config object found in the session.
-     * @param mode the portlet managed custom mode that will be searched for decoration name
-     * in the resource bundle.
-     * @return the decoration name for a portlet managed mode in the resource bundle
-     * using the key javax.portlet.app.custom-portlet-mode.<custom mode>.decoration-name

-     * where custom mode is the name of the custom mode as defined in portlet.xml
-     * (//portlet-app/custom-portlet-mode/portlet-mode element). If the decoration
-     * name is not found in the resource bundle, the uppercased
-     * mode name is returned.
-     */
-    private String getCustomModeDecorationName(DriverConfiguration driverConfig, 
-    		PortletMode mode) {
-    	//decoration name is mode name by default
-		String decorationName = mode.toString().toUpperCase();
-		ResourceBundle bundle;
-		StringBuffer res;
-		try {
-			PortletConfig config = driverConfig.getPortletConfig(evaluatedPortletId);
-			ServletRequest request = pageContext.getRequest();
-			Locale defaultLocale = request.getLocale();
-			bundle = config.getResourceBundle(defaultLocale);
-			res = new StringBuffer();
-			res.append("javax.portlet.app.custom-portlet-mode.");
-			res.append(mode.toString());
-			res.append(".decoration-name");
-			decorationName = bundle.getString(res.toString());
-		} catch (Exception e) {
-			LOG.debug("Problem finding decoration-name for custom mode: " + mode.toString());
-		}
-		return decorationName;
-    }
-    
-}
+/*
+ * 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.driver.tags;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletMode;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.pluto.container.PortletContainer;
+import org.apache.pluto.container.PortletContainerException;
+import org.apache.pluto.container.PortletWindow;
+import org.apache.pluto.driver.AttributeKeys;
+import org.apache.pluto.driver.config.DriverConfiguration;
+import org.apache.pluto.driver.core.PortalRequestContext;
+import org.apache.pluto.driver.core.PortletWindowImpl;
+import org.apache.pluto.driver.services.portal.PortletWindowConfig;
+import org.apache.pluto.driver.url.PortalURL;
+import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
+
+/**
+ * The tag is used to render a portlet mode anchor specified by the portlet ID and mode.
+ * This is designed to live inside of a <pluto:portlet/> tag.
+ * 
+ * <pluto:modeDropDown />
+ *
+ */
+public class PortletModeDropDownTag extends BodyTagSupport {
+    
+	private static final long serialVersionUID = 1L;
+
+
+	/** Logger. */
+    private static final Logger LOG = LoggerFactory.getLogger(PortletModeDropDownTag.class);
+        
+    
+    // Private Member Variables ------------------------------------------------
+    private String portletMode = null;
+    
+    /** The portlet ID attribute obtained from parent tag. */
+    private String portletId = null;
+    
+    /** The evaluated value of the portlet ID attribute. */
+    private String evaluatedPortletId = null;       
+    
+    // BodyTagSupport Impl -----------------------------------------------------
+    
+    /**
+     * Method invoked when the start tag is encountered.
+     * @throws JspException  if an error occurs.
+     */
+    @SuppressWarnings("deprecation")
+   public int doStartTag() throws JspException {
+        
+        // Ensure that the modeAnchor tag resides within a portlet tag.
+        PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass(
+                this, PortletTag.class);
+        if (parentTag == null) {
+            throw new JspException("Portlet window controls may only reside "
+                    + "within a pluto:portlet tag.");
+        }
+        
+        portletId = parentTag.getPortletId();        
+        // Evaluate portlet ID attribute.
+        evaluatePortletId();
+        
+        // Retrieve the portlet window config for the evaluated portlet ID.
+        ServletContext servletContext = pageContext.getServletContext();
+        DriverConfiguration driverConfig = (DriverConfiguration)
+                servletContext.getAttribute(AttributeKeys.DRIVER_CONFIG);
+        
+        // Retrieve the portal environment.
+        PortalRequestContext portalEnv = PortalRequestContext.getContext(
+                (HttpServletRequest) pageContext.getRequest());        
+        
+        //find the current mode for use in 'selected' attrib of select option
+		PortalURL requestedPortalUrl = portalEnv.getRequestedPortalURL();
+        PortletWindowConfig windowConfig =
+            PortletWindowConfig.fromId(evaluatedPortletId);
+        // Retrieve the portlet container from servlet context.
+        PortletContainer container = (PortletContainer)
+                servletContext.getAttribute(AttributeKeys.PORTLET_CONTAINER);
+        
+        // Create the portlet window to render.
+        PortletWindow window = null;
+        
+        
+        try
+        {
+        	// If this fails it means that the portlet will be not available.
+        	// Render Tag will take care of it.
+        	window = new PortletWindowImpl(container, windowConfig, requestedPortalUrl);
+        }
+        catch(RuntimeException ex) 
+        {
+        	  if (LOG.isDebugEnabled()) {
+                  LOG.debug("The portlet " + windowConfig.getPortletName() + " is not available.
Is already deployed?");
+              }
+        }
+		
+        //start the markup
+        StringBuffer tag = new StringBuffer();
+     
+        // Do not render if we don't have a window.
+        if(window!=null)
+        {
+        	PortletMode currentMode = requestedPortalUrl.getPortletMode(window.getId().getStringId());
+
+
+        	//        String strCurrentMode = currentMode.toString();        
+        	//        tag.append("Current mode: " + currentMode.toString());
+        	tag.append("<form action=\"\" name=\"modeSelectionForm\" style=\"display:inline\"><select
onchange=\"self.location=this.options[this.selectedIndex].value\">");
+        	Set<PortletMode> modeSet = null;
+        	try {
+        		modeSet = driverConfig.getSupportedPortletModes(evaluatedPortletId);
+        	} catch (PortletContainerException e) {
+        		throw new JspException(e);
+        	}
+
+        	if (modeSet != null) {
+        		Iterator<PortletMode> i = modeSet.iterator();
+        		while (i.hasNext()) {
+        			PortletMode mode = i.next();
+
+        			PortalURL portalUrl =  requestedPortalUrl.clone();
+        			portalUrl.setPortletMode(evaluatedPortletId, mode);
+
+        			// Build a string buffer containing the anchor tag
+        			tag.append("<option value=\"" + portalUrl.toString() + "\"");
+        			//Add 'selected' attribute for current mode.
+        			if (mode.equals(currentMode)) {
+        				tag.append(" selected=\"true\"");
+        			}
+        			tag.append(">");
+        			if (driverConfig.isPortletManagedMode(evaluatedPortletId, mode.toString())) {
+        				tag.append(getCustomModeDecorationName(driverConfig, mode));	            	
+        			} else {
+        				tag.append(mode.toString().toUpperCase());
+        			}
+        			//	            tag.append(mode.toString().toUpperCase());
+        			tag.append("</option>");
+        		}
+        	}
+        	tag.append("</select></form>");
+
+        }
+        
+        // Print the mode anchor tag.
+        try {
+            JspWriter out = pageContext.getOut();
+            out.print(tag.toString());
+        } catch (IOException ex) {
+            throw new JspException(ex);
+        }
+        
+        // Continue to evaluate the tag body.
+        return EVAL_BODY_INCLUDE;
+    }
+    
+    // Package Methods ---------------------------------------------------------
+    
+    /**
+     * Returns the evaluated portlet ID.
+     * @return the evaluated portlet ID.
+     */
+    String getEvaluatedPortletId() {
+        return evaluatedPortletId;
+    }
+
+    
+    
+    // Private Methods ---------------------------------------------------------
+    
+    /**
+     * Evaluates the portlet ID attribute passed into this tag. This method
+     * evaluates the member variable <code>portletId</code> and saves the
+     * evaluated result to <code>evaluatedPortletId</code>
+     * @throws JspException  if an error occurs.
+     */
+    private void evaluatePortletId() throws JspException {
+        Object obj = ExpressionEvaluatorManager.evaluate(
+                "portletId", portletId, String.class, this, pageContext);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Evaluated portletId to: " + obj);
+        }
+        evaluatedPortletId = (String) obj;
+    }
+
+    /**
+     * @return the portletMode
+     */
+    public String getPortletMode() {
+        return portletMode;
+    }
+
+    /**
+     * @param portletMode the portletMode to set
+     */
+    public void setPortletMode(String portletMode) {
+        this.portletMode = portletMode;
+    }
+
+    /**
+     * Obtains decoration name for a portlet managed mode from the portlet's resource bundle
+     * as defined in PLT.8.4 of the JSR-286 spec using the key 
+     * javax.portlet.app.custom-portlet-mode.<custom mode>.decoration-name where
+     * custom mode is the name of the custom mode as defined in portlet.xml
+     * (//portlet-app/custom-portlet-mode/portlet-mode element). If the decoration
+     * name is not found in the resource bundle, this method returns the uppercased
+     * mode name.
+     * 
+     * @param driverConfig the driver config object found in the session.
+     * @param mode the portlet managed custom mode that will be searched for decoration name
+     * in the resource bundle.
+     * @return the decoration name for a portlet managed mode in the resource bundle
+     * using the key javax.portlet.app.custom-portlet-mode.<custom mode>.decoration-name

+     * where custom mode is the name of the custom mode as defined in portlet.xml
+     * (//portlet-app/custom-portlet-mode/portlet-mode element). If the decoration
+     * name is not found in the resource bundle, the uppercased
+     * mode name is returned.
+     */
+    private String getCustomModeDecorationName(DriverConfiguration driverConfig, 
+    		PortletMode mode) {
+    	//decoration name is mode name by default
+		String decorationName = mode.toString().toUpperCase();
+		ResourceBundle bundle;
+		StringBuffer res;
+		try {
+			PortletConfig config = driverConfig.getPortletConfig(evaluatedPortletId);
+			ServletRequest request = pageContext.getRequest();
+			Locale defaultLocale = request.getLocale();
+			bundle = config.getResourceBundle(defaultLocale);
+			res = new StringBuffer();
+			res.append("javax.portlet.app.custom-portlet-mode.");
+			res.append(mode.toString());
+			res.append(".decoration-name");
+			decorationName = bundle.getString(res.toString());
+		} catch (Exception e) {
+			LOG.debug("Problem finding decoration-name for custom mode: " + mode.toString());
+		}
+		return decorationName;
+    }
+    
+}


Mime
View raw message