myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfreed...@apache.org
Subject svn commit: r1139083 [2/2] - in /myfaces/portlet-bridge/core/branches/refactored_3.0.x: controller-api/src/main/java/org/apache/myfaces/portlet/faces/bridge/ impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/ impl/src/main/java/org/apache/myfa...
Date Thu, 23 Jun 2011 21:45:13 GMT
Modified: myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/scope/BridgeRequestScopeManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/scope/BridgeRequestScopeManagerImpl.java?rev=1139083&r1=1139082&r2=1139083&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/scope/BridgeRequestScopeManagerImpl.java
(original)
+++ myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/scope/BridgeRequestScopeManagerImpl.java
Thu Jun 23 21:45:13 2011
@@ -14,12 +14,15 @@ package org.apache.myfaces.portlet.faces
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 
 import java.util.Set;
 
+import java.util.concurrent.ConcurrentHashMap;
+
 import javax.portlet.PortletContext;
 import javax.portlet.faces.Bridge;
 
@@ -38,33 +41,53 @@ public class BridgeRequestScopeManagerIm
 {
   private static final int DEFAULT_MAX_MANAGED_REQUEST_SCOPES = 100;
   
-  private BridgeConfig mBridgeConfig;
   private Map<String, BridgeRequestScope> mScopeRepository;
+  private Map<String, String> mIdMap;
   
   public BridgeRequestScopeManagerImpl(BridgeConfig bConfig)
-  {
-    mBridgeConfig = bConfig;
-    
+  {   
     // Create/Initialize the respository that will hold scopes
-    mScopeRepository = createRequestScopeRepository(mBridgeConfig.getPortletConfig().getPortletContext());
+    mScopeRepository = createRequestScopeRepository(bConfig.getPortletConfig().getPortletContext());
+    mIdMap = createIdMap(bConfig.getPortletConfig().getPortletContext());
   }
+  
   /**
-   * Create a new empty RequestScope.  As a by product of this call
-   * the manager should set the RequestScope prefix in a manner that allows it to 
-   * manage the various remove methods.
-   * @param ctx
+   * Create a new empty RequestScope.  
+   * @param bCtx
+   * @param portletName name of the portlet to which this scope pertains
+   * @param sessionId a unique identifier for the user session in which this scope pertains
+   * @param viewId the faces viewId of this scope
+   * @param portletMode the mode this scope pertains to
    * @return the new BridgeRequestScope
    */
-  public BridgeRequestScope createRequestScope(BridgeContext bCtx)
+  public BridgeRequestScope createRequestScope(BridgeContext bCtx, String portletName, String
sessionId,  String viewId, String portletMode)
   {
-    BridgeRequestScope scope = new BridgeRequestScopeImpl(getManagedKey(bCtx));
+    BridgeRequestScope scope = new BridgeRequestScopeImpl(portletName, sessionId, viewId,
portletMode);
     mScopeRepository.put((String) scope.getId(), scope);
+    mIdMap.put(getQualifiedKey(portletName, sessionId, viewId, portletMode), scope.getId());
     return scope;
   }
   
+  
+  /**
+   * Create a new empty RequestScope.  Scope qualifiers portletName, sessionId, and portletMode
are taken from the current request object
+   * in the <code>BridgeContext</code>.
+   * @param bCtx
+   * @param viewId the faces viewId of this scope
+   * @return the new BridgeRequestScope
+   */
+  public BridgeRequestScope createRequestScope(BridgeContext bCtx, String viewId)
+  {
+    return createRequestScope(bCtx,
+        bCtx.getBridgeConfig().getPortletConfig().getPortletName(),
+        bCtx.getPortletRequest().getPortletSession(true).getId(),
+        viewId,
+        bCtx.getPortletRequest().getPortletMode().toString());
+  }
+  
   /**
    * Returns the BridgeRequestScope corresponding to the supplied key (id)
-   * @param ctx
+   * @param bCtx
    * @param id BridgeRequestScope's id
    * @return the BridgeRequestScope that corresponds to the supplied key
    */
@@ -74,115 +97,274 @@ public class BridgeRequestScopeManagerIm
   }
   
   /**
+   * Returns the BridgeRequestScope corresponding to the portletName, sessionId, viewId and
portletMode.
+   * 
+   * @param bCtx
+   * @param portletName uniquely identifies this portlet.
+   * @param sessionId uniquely identifies a user context (session)
+   * @param viewId Faces view to which this scope pertains
+   * @param portletMode portlet mode that this scope represents
+   * @return the BridgeRequestScope that corresponds to the supplied key or null if no match
+   */
+  public BridgeRequestScope getRequestScope(BridgeContext bCtx, String portletName, String
sessionId,  String viewId, String portletMode)
+  {
+    String key = getQualifiedKey(portletName, sessionId, viewId, portletMode);
+    String id = mIdMap.get(key);
+    BridgeRequestScope scope = null;
+    if (id != null)
+    {
+      scope = getRequestScopeById(bCtx, id);
+      if (scope == null)
+      {
+        // Don't have a scope for this key mapping -- must have been removed -- so remove
now from IdMap
+        mIdMap.remove(key);
+      }
+    }
+    return scope;
+  }
+  
+  
+  /**
+   * Returns the BridgeRequestScope corresponding to the portletName, sessionId, viewId and
portletMode.
+   * PortletId and sessionId are taken from the current request/portlet config
+   * 
+   * @param bCtx
+   * @param viewId Faces view to which this scope pertains
+   * @param portletMode portlet mode that this scope represents
+   * @return the BridgeRequestScope that corresponds to the supplied key or null if no match
+   */
+  public BridgeRequestScope getRequestScope(BridgeContext bCtx, String viewId, String portletMode)
+  {
+    return getRequestScope(bCtx, bCtx.getBridgeConfig().getPortletConfig().getPortletName(),
+                           bCtx.getPortletRequest().getPortletSession(true).getId(),
+                           viewId, portletMode);
+
+  }
+  
+  /**
+   * Returns the BridgeRequestScope corresponding to the portletName, sessionId, viewId and
portletMode.
+   * PortletName, sessionId, and portletMode are taken from the current request/portlet config
+   * 
+   * @param bCtx
+   * @param viewId Faces view to which this scope pertains
+   * @return the BridgeRequestScope that corresponds to the supplied key or null if no match
+   */
+  public BridgeRequestScope getRequestScope(BridgeContext bCtx, String viewId)
+  {
+    return getRequestScope(bCtx, viewId, bCtx.getPortletRequest().getPortletMode().toString());
+  }
+  
+  /**
+   * Returns the BridgeRequestScope corresponding to the portletId, sessionId, viewId and
portletMode.
+   * PortletName, sessionId, and portletMode and viewId are taken from the current bridge
context
+   * 
+   * @param bCtx
+   * @return the BridgeRequestScope that corresponds to the supplied key or null if no match
+   */
+  public BridgeRequestScope getRequestScope(BridgeContext bCtx)
+  {
+    return getRequestScope(bCtx, bCtx.getFacesViewId(true));
+  }
+    
+  
+  /**
    * Removes the specific BridgeRequestScope (from management) that
    * corresponds to the supplied key.
-   * @param ctx
+   * @param bCtx
    * @param id
-   * @return the BridgeRequestScope that corresponds to the supplied key.
+   * @return the BridgeRequestScope that corresponds to the supplied key. (Note: scope
+   * is cleared before being returned)
    */
   public BridgeRequestScope removeRequestScopeById(BridgeContext bCtx, String id)
   {
-    return mScopeRepository.remove(id);
+    BridgeRequestScope scope = mScopeRepository.remove(id);
+    if (scope != null)
+    {
+      mIdMap.remove(getQualifiedKey(scope));
+    }
+    return scope;
   }
   
   
   /**
    * Removes the supplied BridgeRequestScope from management.
-   * @param ctx
+   * @param bCtx
    * @param scope
+   * @return scope that was removed or null -- if scope not in the repository. (Note: scope
+   * is cleared before being returned)
+   */
+  public BridgeRequestScope removeRequestScope(BridgeContext bCtx, BridgeRequestScope scope)
+  {
+    return removeRequestScope(bCtx, scope.getId());
+  }
+  
+  /**
+   * Removes the request scope pertaining to the portletId, sessionId, viewId and portletMode.
+   * This operation is a noop if a match is not found.
+   * 
+   * @param bCtx
+   * @param portletName uniquely identifies this portlet.
+   * @param sessionId uniquely identifies a user context (session)
+   * @param viewId Faces view to which this scope pertains
+   * @param portletMode portlet mode that this scope represents
+   * @return scope that was removed or null. (Note: scope
+   * is cleared before being returned)
    */
-  public void removeRequestScope(BridgeContext bCtx, BridgeRequestScope scope)
+  public BridgeRequestScope removeRequestScope(BridgeContext bCtx, String portletName, String
sessionId,  String viewId, String portletMode)
   {
-    mScopeRepository.remove(scope.getId());
+    String key = getQualifiedKey(portletName, sessionId, viewId, portletMode);
+    String id = mIdMap.get(key);
+    BridgeRequestScope scope = null;
+    if (id != null)
+    {
+      scope = removeRequestScopeById(bCtx, id);
+      if (scope == null)
+      {
+        // Don't have a scope for this key mapping -- must have been removed -- so remove
now from IdMap
+        mIdMap.remove(key);
+      }
+    }
+    return scope;
   }
   
   
   /**
+   * Removes the request scope pertaining to the portletId, sessionId, viewId and portletMode.
+   * Portletname and sessionId are taken from the current request/portlet config
+   * This operation is a noop if a match is not found.
+   * 
+   * @param bCtx
+   * @param viewId Faces view to which this scope pertains
+   * @param portletMode portlet mode that this scope represents
+   * @return scope that was removed or null. (Note: scope
+   * is cleared before being returned)
+   */
+  public BridgeRequestScope removeRequestScope(BridgeContext bCtx, String viewId, String
portletMode)
+  {
+    return removeRequestScope(bCtx, bCtx.getBridgeConfig().getPortletConfig().getPortletName(),
+                           bCtx.getPortletRequest().getPortletSession(true).getId(),
+                           viewId, portletMode);
+  }
+  
+  /**
+   * Removes the request scope pertaining to the portletId, sessionId, viewId and portletMode.
+   * PortletName, sessionId, and portletMode are taken from the current request/portlet config
+   * This operation is a noop if a match is not found.
+   * 
+   * @param bCtx
+   * @param viewId Faces view to which this scope pertains
+   * @return scope that was removed or null. (Note: scope
+   * is cleared before being returned)
+   */
+  public BridgeRequestScope removeRequestScope(BridgeContext bCtx, String viewId)
+  {
+    return removeRequestScope(bCtx, viewId, bCtx.getPortletRequest().getPortletMode().toString());
+  }
+  
+    
+  
+  /**
    * Removes all the BridgeRequestScope's currently by managed by this manager
-   * for the specific portlet that is identified in the PortletConfig object
-   * obtainable from the BridgeContext.
-   * @param ctx
+   * for the specific portlet that is identified <code>portletName</code>.
+   * @param bCtx
    */
-  public void removeRequestScopesByPortlet(BridgeContext bCtx)
+  public void removeRequestScopesByPortlet(BridgeContext bCtx, String portletId)  
   {
-    String portletToRemove = bCtx.getBridgeConfig().getPortletConfig().getPortletName();
-
-    if (portletToRemove != null) {
+    if (portletId != null) {
 
       Set<Map.Entry<String, BridgeRequestScope>> mapEntries = mScopeRepository.entrySet();
 
       if (mapEntries != null) {
 
         List<String> keysToRemove = new ArrayList<String>();
-
-        for (Map.Entry<String, BridgeRequestScope> mapEntry : mapEntries) {
-          BridgeRequestScope bridgeRequestScope = mapEntry.getValue();
-          String bridgeRequestScopeId = bridgeRequestScope.getId();
-          String portletName = bridgeRequestScopeId.split("[:][:][:]")[0];
-
-          if (portletToRemove.equals(portletName)) {
-            keysToRemove.add(mapEntry.getKey());
+        
+        synchronized(mScopeRepository)
+        {
+          for (Map.Entry<String, BridgeRequestScope> mapEntry : mapEntries) {
+            BridgeRequestScope bridgeRequestScope = mapEntry.getValue();
+  
+            if (portletId.equals(bridgeRequestScope.getPortletId())) {
+              keysToRemove.add(mapEntry.getKey());
+            }
+          }
+  
+          for (String key : keysToRemove) {
+            removeRequestScopeById(bCtx, key);
           }
-        }
-
-        for (String key : keysToRemove) {
-          mScopeRepository.remove(key);
         }
       }
     }
   }
   
+  /**
+   * Removes all the BridgeRequestScope's currently by managed by this manager
+   * for the specific portlet that is identified in the PortletConfig object
+   * obtainable from the BridgeContext.
+   * @param bCtx
+   */
+  public void removeRequestScopesByPortlet(BridgeContext bCtx)
+  {
+    removeRequestScopesByPortlet(bCtx, bCtx.getBridgeConfig().getPortletConfig().getPortletName());
+  }
+  
   
   /**
    * Removes all the  BridgeRequestScope's currently by managed by this manager
-   * for the current session.
+   * for the session identified by <code>sessionId</code>.
    * 
-   * @param ctx
+   * @param bCtx
    */
-  public void removeRequestScopesBySession(BridgeContext bCtx)
+  public void removeRequestScopesBySession(BridgeContext bCtx, String sessionId)
   {
-    String sessionToRemove = bCtx.getPortletRequest().getPortletSession(true).getId();
-
-    if (sessionToRemove != null) {
-
-      Set<Map.Entry<String, BridgeRequestScope>> mapEntries = mScopeRepository.entrySet();
+    {
+      if (sessionId != null) {
 
-      if (mapEntries != null) {
+        Set<Map.Entry<String, BridgeRequestScope>> mapEntries = mScopeRepository.entrySet();
 
-        List<String> keysToRemove = new ArrayList<String>();
+        if (mapEntries != null) {
 
-        for (Map.Entry<String, BridgeRequestScope> mapEntry : mapEntries) {
-          BridgeRequestScope bridgeRequestScope = mapEntry.getValue();
-          String bridgeRequestScopeId = bridgeRequestScope.getId();
-          String portletName = bridgeRequestScopeId.split("[:][:][:]")[1];
-
-          if (sessionToRemove.equals(portletName)) {
-            keysToRemove.add(mapEntry.getKey());
+          List<String> keysToRemove = new ArrayList<String>();
+          
+          synchronized(mScopeRepository)
+          {
+            for (Map.Entry<String, BridgeRequestScope> mapEntry : mapEntries) {
+              BridgeRequestScope bridgeRequestScope = mapEntry.getValue();
+  
+              if (sessionId.equals(bridgeRequestScope.getSessionId())) {
+                keysToRemove.add(mapEntry.getKey());
+              }
+            }
+  
+            for (String key : keysToRemove) {
+              removeRequestScopeById(bCtx, key);
+            }
           }
         }
-
-        for (String key : keysToRemove) {
-          mScopeRepository.remove(key);
-        }
       }
     }
   }
   
-  private String getManagedKey(BridgeContext bCtx)
+  /**
+   * Removes all the  BridgeRequestScope's currently by managed by this manager
+   * for the current session.
+   * 
+   * @param bCtx
+   */
+  public void removeRequestScopesBySession(BridgeContext bCtx)
   {
-    // a qualified scope Id must at a minimum be qualified by a portletId   
-    StringBuffer sb = new StringBuffer(mBridgeConfig.getPortletConfig().getPortletName());
-    
-    sb.append(':');
-    sb.append(bCtx.getPortletRequest().getPortletSession(true).getId());
-    sb.append(':');
-    sb.append(bCtx.getPortletRequest().getPortletMode().toString());
-    
-    return sb.toString();
+    removeRequestScopesByPortlet(bCtx, bCtx.getPortletRequest().getPortletSession(true).getId());
   }
   
+   
+  
+  
   private Map<String, BridgeRequestScope> createRequestScopeRepository(PortletContext
portletContext)
   {
+    return Collections.synchronizedMap(new BridgeRequestScopeRepository<String, BridgeRequestScope>(getRepositoryMax(portletContext)));
+  }
+  
+  private Map<String, String> createIdMap(PortletContext portletContext)
+  {
     // see if portlet has defined how many requestScopes to manage
     // for this portlet
     int managedScopes = DEFAULT_MAX_MANAGED_REQUEST_SCOPES;
@@ -194,8 +376,29 @@ public class BridgeRequestScopeManagerIm
       managedScopes = Integer.parseInt(managedScopesSetting);
     }
 
-    return Collections.synchronizedMap(new BridgeRequestScopeRepository<String, BridgeRequestScope>(managedScopes));
+    return new HashMap<String, String>(getRepositoryMax(portletContext));
   }
   
+  private int getRepositoryMax(PortletContext portletContext)
+  {
+    int managedScopes = DEFAULT_MAX_MANAGED_REQUEST_SCOPES;
+
+    String managedScopesSetting = 
+      portletContext.getInitParameter(Bridge.MAX_MANAGED_REQUEST_SCOPES);
+    if (managedScopesSetting != null)
+    {
+      managedScopes = Integer.parseInt(managedScopesSetting);
+    }
+    return managedScopes;
+  }
   
+  public String getQualifiedKey(String portletName, String sessionId,  String viewId, String
portletMode)  
+  {
+    return new StringBuffer(portletName).append(':').append(sessionId).append(':').append(viewId).append(':').append(portletMode).toString();
+  }
+  
+  public String getQualifiedKey(BridgeRequestScope scope)  
+  {
+    return new StringBuffer(scope.getPortletId()).append(':').append(scope.getSessionId()).append(':').append(scope.getViewId()).append(':').append(scope.getPortletMode()).toString();
+  }
 }
\ No newline at end of file

Modified: myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java?rev=1139083&r1=1139082&r2=1139083&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
(original)
+++ myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/context/PortletExternalContextImpl.java
Thu Jun 23 21:45:13 2011
@@ -92,13 +92,7 @@ import org.apache.myfaces.shared_portlet
  */
 public class PortletExternalContextImpl
   extends ExternalContext
-{
-  public static final String FACES_MAPPING_ATTRIBUTE = 
-    "org.apache.myfaces.portlet.faces.context.facesMapping";
-  
-  private static final String FACES_SUFFIXES = 
-    "org.apache.myfaces.portlet.faces.context.facesSuffixes";
-  
+{ 
   // Note: be careful -- as this attribute is prefixed to a value containing '.' it
   // wouldn't be exlcuded using normal logic -- so instead BridgeImpl specially
   // exlcudes/treats this package. -- i.e. all attrbiutes beginning with 
@@ -109,11 +103,7 @@ public class PortletExternalContextImpl
   
   public static final String BOOKMARKABLE_URL = "_jsfBridgeBookmarkableUrl";  
 
-  public static final String RENDER_POLICY_ATTRIBUTE = 
-    Bridge.BRIDGE_PACKAGE_PREFIX + "." + Bridge.RENDER_POLICY;
-
   // Render parameter to store the viewId
-  public static final String JSF_TARGET_VIEWID_RENDER_PARAMETER = "__jpfbJSFTARGET";
   public static final String RENDERURL_NO_SCOPE = "__jpfbUSESCOPE";
   public static final String NO_SCOPE = "org.apache.myfaces.portlet.faces.noScope";
   
@@ -414,7 +404,7 @@ public class PortletExternalContextImpl
     {
       return url;
     }  
-    else if (isDirectLink(url))
+    else if (isExternalURL(url) || isDirectLink(url))
     {
       // its not an absolute URL (or would have been handled in previous if) convert it into
one.
       return getAbsoluteUrlFromPath(url);
@@ -453,7 +443,7 @@ public class PortletExternalContextImpl
       }
     
       // Now se if this is a Faces URL
-      viewId = getViewIdFromPath(path);
+      viewId = getBridgeContext().getFacesViewIdFromPath(path);
 
       if (viewId != null)
       {
@@ -805,7 +795,7 @@ public class PortletExternalContextImpl
     if (params != null)
     {
       // Only can redirect to other Faces views in an render request
-      if (isRenderPhase && params.getParameter(JSF_TARGET_VIEWID_RENDER_PARAMETER)
== null)
+      if (isRenderPhase && params.getParameter(getBridgeContext().getBridgeConfig().getViewIdRenderParameterName())
== null)
       {
         throw new IllegalStateException("Can't redirect during render to a NonFaces target:
" + url); 
       }
@@ -1011,7 +1001,7 @@ public class PortletExternalContextImpl
     
     // Determine the viewId by inspecting the URL
     // Can't be relative by the time we get here so don't check
-    viewId = getViewIdFromPath(path);
+    viewId = getBridgeContext().getFacesViewIdFromPath(path);
     
     // TODO: Handle the case where this is a nonFaces (inprotocol) resource
     // I.e. viewId is null here.  Should we do something similar to
@@ -1021,7 +1011,7 @@ public class PortletExternalContextImpl
     {
       // This is a Faces resource
       // put the viewId in the QueryStr.
-      queryStr.addParameter(JSF_TARGET_VIEWID_RENDER_PARAMETER, viewId);
+      queryStr.addParameter(getBridgeContext().getBridgeConfig().getViewIdRenderParameterName(),
viewId);
       queryStr.removeParameter(Bridge.PORTLET_MODE_PARAMETER);
       queryStr.removeParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER);
     }
@@ -2060,78 +2050,11 @@ public class PortletExternalContextImpl
   }
 
   /**
-   * Gets the view identifier we should use for this request.
+   * Pulls params from the query string of the target (if any) and caches so they will
+   * get added to the ExternalContexts parameterMap
    */
-  private String getViewId(boolean updateHistory)
-    throws BridgeDefaultViewNotSpecifiedException, BridgeInvalidViewPathException
+  private String processParameters(String viewId)
   {
-    boolean modeChanged = false;
-    String requestedMode = mPortletRequest.getPortletMode().toString();
-    
-    // See if the portlet has specified the target view
-    String viewId = (String) mPortletRequest.getAttribute(Bridge.VIEW_ID);
-    String viewPath = null;
-    if (viewId == null)
-    {
-      viewPath = (String) mPortletRequest.getAttribute(Bridge.VIEW_PATH);
-      if (viewPath != null)
-      {
-        //convert the view path into a viewId
-        viewId = getViewIdFromPath(viewPath);
-        if (viewId == null)
-        {
-          throw new BridgeInvalidViewPathException("Unable to resolve faces viewId: "
-              + viewPath);
-        }
-      }
-    }
-      
-    // Normal case is its returned in the render parameter
-    if (viewId == null)
-    {
-     // Read the target from the request parameter
-        
-      viewId = mPortletRequest.getParameter(JSF_TARGET_VIEWID_RENDER_PARAMETER);
-
-      if (viewId != null) debugLog("PortletExternalContextImpl.getViewId: found jsf target
viewId = " + viewId);
-
-      // ViewIds stored in RenderParams are encoded with the Mode to which they apply
-      // Ensure current request Mode matches before using the viewId portion
-      if (viewId != null)
-      {
-        int i = viewId.indexOf(':');
-        if (i >= 0 )
-        {
-      
-          String mode = viewId.substring(0, i);
-          viewId = viewId.substring(i+1);
-          if (!mode.equalsIgnoreCase(requestedMode))
-          {
-            modeChanged = true;
-            viewId = null; // didn't match so don't use it
-          }
-        }
-      }
-    }
-    if (viewId == null)
-    {
-      @SuppressWarnings ("unchecked")
-      Map<String, String> m = getBridgeContext().getBridgeConfig().getDefaultViewMappings();
-
-      viewId = m.get(requestedMode);
-      if (viewId == null)
-      {
-        // If no defaultview then throw an exception
-        throw new BridgeDefaultViewNotSpecifiedException();
-      }
-
-      debugLog("PortletExternalContextImpl.getViewId: jsf target viewId not found, defaulting
to: " + viewId);
-    }
-
-    // Some viewId may have query string, so handle that here
-    // (e.g., TaskFlow has the following viewId:
-    // /adf.task-flow?_document=/WEB-INF/task-flow.xml&_id=task1
-
     int queryStart = viewId.indexOf('?');
     QueryString queryStr = null;
 
@@ -2176,31 +2099,17 @@ public class PortletExternalContextImpl
       debugLog("PortletExternalContextImpl.getViewId: special viewId: " + viewId);
     }
 
-    // before returning -- update the appropriate session attr with the current
-    // mode/viewid info so developers can access via EL when they want to navigate
-    // between modes and end up in the last view of the new mode
-    // Note: only do in render phase becase we need to remember the 
-    // render parameters -- during a render all parameters are render parameters
-    if (updateHistory && getPortletPhase() == Bridge.PortletPhase.RENDER_PHASE)
-    {
-      updateViewChainAttribute(mPortletRequest.getPortletMode().toString(), viewId, modeChanged);
-    }
-
-    // If the mode changes mark this so BridgeImpl (controller) can see it shouldn't
-    // restore/save the scope
-    this.getRequestMap().put(NO_SCOPE, Boolean.valueOf(modeChanged));
-
     return viewId;
   }
 
-  private void updateViewChainAttribute(String mode, String viewId, boolean modeChanged)
+  private void updateViewChainAttribute(String mode, String viewId, boolean preserveRenderParams)
   {
     QueryString qs = new QueryString("UTF8");
     
     // always encode the mode in the viewId as this is used for mode transitions
     qs.setParameter(Bridge.PORTLET_MODE_PARAMETER, mode);
     
-    if (!modeChanged)
+    if (preserveRenderParams)
     {
         // Build a QueryString from the request's render parameters so can preserve
       // with the viewId 
@@ -2213,7 +2122,7 @@ public class PortletExternalContextImpl
         {
           Map.Entry<String,String[]> e = i.next();
           // only add if not a viewId or viewState parameter
-          if (!e.getKey().equals(JSF_TARGET_VIEWID_RENDER_PARAMETER)
+          if (!e.getKey().equals(getBridgeContext().getBridgeConfig().getViewIdRenderParameterName())
           && !e.getKey().equals(ResponseStateManager.VIEW_STATE_PARAM))
           {
             for (String s : e.getValue())
@@ -2355,164 +2264,67 @@ public class PortletExternalContextImpl
     }
     return null;
   }
-
-  private String getViewIdFromPath(String url)
-  {
-    // Get a string that holds the path after the Context-Path through the
-    // target
-
-    // First remove the query string
-    int i = url.indexOf("?");
-    if (i != -1)
-    {
-      url = url.substring(0, i);
-    }
-
-    // Now remove up through the ContextPath
-    String ctxPath = getRequestContextPath();
-    i = url.indexOf(ctxPath);
-    if (i != -1)
-    {
-      url = url.substring(i + ctxPath.length());
-    }
-
-    String viewId = null;
-    // Okay now figure out whether this is prefix or suffixed mapped
-    List<String> facesMappings = getBridgeContext().getBridgeConfig().getFacesServletMappings();
-    List<String> facesSuffixes = getBridgeContext().getBridgeConfig().getFacesSuffixes();
-    if (isSuffixedMapped(url, facesMappings))
-    {
-      viewId = 
-          viewIdFromSuffixMapping(url, facesSuffixes);
-    }
-    else if (isPrefixedMapped(url, facesMappings))
-    {
-      viewId = viewIdFromPrefixMapping(url, facesMappings);
-    }
-    else
-    {
-      // Not a Faces URL
-      viewId = null;
-    }
-    return viewId;
-  }
   
-  private List<String> parseFacesSuffixes()
+  private void determineView(boolean updateHistory) throws FacesException
   {
-    String suffixString = mPortletContext.getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);
-    if (suffixString == null)
-    {
-      suffixString = ViewHandler.DEFAULT_SUFFIX;
-    }
-    
-    return Arrays.asList(suffixString.split(" "));
-  }
-
-  private boolean isSuffixedMapped(String url, List<String> mappings)
-  {
-    // see if the viewId terminates with an extension
-    // if non-null value contains *.XXX where XXX is the extension
-    String ext = extensionMappingFromViewId(url);
-    return ext != null && mappings.contains(ext);
-  }
-
-  private String viewIdFromSuffixMapping(String url, List<String> suffixes)
-  {
-    int i = url.lastIndexOf(".");
-    if (i != -1)
+    // viewId is the actual context relative path to the resource
+    // We get the viewId with any associated query string so we can add these to the parameter
map
+    try
     {
-      for (String suffix : suffixes)
+      String viewId = getBridgeContext().getFacesViewIdFromRequest(false);
+      boolean useDefaultViewId = (viewId == null);
+      
+      if (useDefaultViewId)
       {
-        if (suffix.startsWith("."))
-        {
-          url = url.substring(0, i) + suffix;
-        }
-        else
-        {
-          // shouldn't happen
-          url = url.substring(0, i) + "." + suffix;
-        }
-        // now verify if this exists
-        String testPath = url.startsWith("/") ? url : "/"+url;
-        try
-        {
-          if (mPortletContext.getResource(testPath) != null)
-          {
-            break;
-          }
-        } catch (MalformedURLException m)
-        {
-            // TODO: didn't expect to get here
-        }
+        viewId = getBridgeContext().getDefaultFacesViewIdForRequest(false);
       }
-    }
-    return url;
-  }
-
-  private boolean isPrefixedMapped(String url, List<String> mappings)
-  {
-    for (int i = 0; i < mappings.size(); i++)
-    {
-      String prefix = null;
-      String mapping = mappings.get(i);
-      if (mapping.startsWith("/"))
+      
+      if (viewId != null)   
       {
-        int j = mapping.lastIndexOf("/*");
-        if (j != -1)
+        viewId = processParameters(viewId);
+      
+        // update the appropriate session attr with the current
+        // mode/viewid info so developers can access via EL when they want to navigate
+        // between modes and end up in the last view of the new mode
+        // Note: only do in render phase becase we need to remember the 
+        // render parameters -- during a render all parameters are render parameters
+        if (updateHistory && getPortletPhase() == Bridge.PortletPhase.RENDER_PHASE)
         {
-          prefix = mapping.substring(0, j);
+          updateViewChainAttribute(mPortletRequest.getPortletMode().toString(), viewId, !useDefaultViewId);
         }
       }
-      if (prefix != null && url.startsWith(prefix))
+  
+      // If the mode changes mark this so BridgeImpl (controller) can see it shouldn't
+      // restore/save the scope
+      this.getRequestMap().put(NO_SCOPE, Boolean.valueOf(useDefaultViewId));
+      
+      if (mViewId != null && viewId.equals((mViewId)))
       {
-        return true;
+        return;  // No change
       }
-    }
-    return false;
-  }
+      
+      mViewId = viewId;
   
-  private void determineView(boolean updateHistory)
-  {
-    // viewId is the actual context relative path to the resource
-    String viewId = getViewId(updateHistory);
-    
-    if (mViewId != null && viewId.equals((mViewId)))
-    {
-      return;  // No change
+      // Now reverse engineer the servlet paths from the mappings 
+      // So Faces thinks was a client request
+      mapPathsFromViewId(mViewId, getBridgeContext().getBridgeConfig().getFacesServletMappings());
+  
+      // JSF RI relies on a request attribute setting to properly handle
+      // suffix mapping -- but because their suffix mapping code is servlet dependent
+      // we need to set it for them
+      setFacesMapping();
     }
-    
-    mViewId = viewId;
-
-    // Now reverse engineer the servlet paths from the mappings 
-    // So Faces thinks was a client request
-    mapPathsFromViewId(mViewId, getBridgeContext().getBridgeConfig().getFacesServletMappings());
-
-    // JSF RI relies on a request attribute setting to properly handle
-    // suffix mapping -- but because their suffix mapping code is servlet dependent
-    // we need to set it for them
-    setFacesMapping();
-  }
-
-  private String viewIdFromPrefixMapping(String url, List<String> mappings)
-  {
-    for (int i = 0; i < mappings.size(); i++)
+    catch (Exception e)
     {
-      String prefix = null;
-      String mapping = mappings.get(i);
-      if (mapping.startsWith("/"))
-      {
-        int j = mapping.lastIndexOf("/*");
-        if (j != -1)
+        if (e instanceof FacesException)
         {
-          prefix = mapping.substring(0, j);
+          throw (FacesException) e;
+        }
+        else
+        {
+          throw new FacesException(e);
         }
-      }
-      if (prefix != null && url.startsWith(prefix))
-      {
-        return url.substring(prefix.length());
-      }
     }
-    return null;
   }
 
   private void setFacesMapping()
@@ -2666,7 +2478,7 @@ public class PortletExternalContextImpl
 
   private boolean isExternalURL(String url)
   {
-    if (!isAbsoluteURL(url))
+    if (!isAbsoluteURL(url) && !url.startsWith("/"))
     {
       return false;
     }
@@ -2698,7 +2510,7 @@ public class PortletExternalContextImpl
     }
     
     // Now se if this is a Faces URL
-    viewId = getViewIdFromPath(url);
+    viewId = getBridgeContext().getFacesViewIdFromPath(url);
 
     return viewId != null;
   }
@@ -2789,7 +2601,7 @@ public class PortletExternalContextImpl
     }
     
     // put the viewId in the QueryStr.
-    queryStr.setParameter(JSF_TARGET_VIEWID_RENDER_PARAMETER,
+    queryStr.setParameter(getBridgeContext().getBridgeConfig().getViewIdRenderParameterName(),
                           new StringBuffer(100).append(mode).append(':').append(target).toString());
   }
   



Mime
View raw message