You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/04/30 06:17:17 UTC

svn commit: r770054 - /myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/DefaultViewHandlerSupport.java

Author: lu4242
Date: Thu Apr 30 04:17:16 2009
New Revision: 770054

URL: http://svn.apache.org/viewvc?rev=770054&view=rev
Log:
MYFACES-2222 ViewHandler.DEFAULT_SUFFIX could contain several suffixes

Modified:
    myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/DefaultViewHandlerSupport.java

Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/DefaultViewHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/DefaultViewHandlerSupport.java?rev=770054&r1=770053&r2=770054&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/DefaultViewHandlerSupport.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/application/DefaultViewHandlerSupport.java Thu Apr 30 04:17:16 2009
@@ -24,6 +24,8 @@
 import javax.faces.application.ViewHandler;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
+
+import java.net.MalformedURLException;
 import java.util.Map;
 
 /**
@@ -72,13 +74,19 @@
         {
             if (mapping.isExtensionMapping())
             {
-                String contextSuffix = getContextSuffix(context);
-                if (viewId.endsWith(contextSuffix))
+                String[] contextSuffixes = getContextSuffix(context); 
+                boolean founded = false;
+                for (String contextSuffix : contextSuffixes)
                 {
-                    builder.append(viewId.substring(0, viewId.indexOf(contextSuffix)));
-                    builder.append(mapping.getExtension());
+                    if (viewId.endsWith(contextSuffix))
+                    {
+                        builder.append(viewId.substring(0, viewId.indexOf(contextSuffix)));
+                        builder.append(mapping.getExtension());
+                        founded = true;
+                        break;
+                    }
                 }
-                else
+                if (!founded)
                 {
                     builder.append(viewId);
                 }
@@ -169,14 +177,14 @@
         }
     }
 
-    protected String getContextSuffix(FacesContext context)
+    protected String[] getContextSuffix(FacesContext context)
     {
         String defaultSuffix = context.getExternalContext().getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);
         if (defaultSuffix == null)
         {
             defaultSuffix = ViewHandler.DEFAULT_SUFFIX;
         }
-        return defaultSuffix;
+        return defaultSuffix.split(" ");
     }
 
     /**
@@ -187,27 +195,53 @@
      */
     protected String applyDefaultSuffix(FacesContext context, String viewId)
     {
-        String defaultSuffix = getContextSuffix(context);
+        String[] defaultSuffixes = getContextSuffix(context);
 
         if (viewId == null)
         {
             return null;
         }
 
-        if (!viewId.endsWith(defaultSuffix))
+        boolean endWithAnyDefaultSuffix = false;
+        for (String defaultSuffix : defaultSuffixes)
         {
-            StringBuilder builder = new StringBuilder(viewId);
-            int slashPos = viewId.lastIndexOf('/');
-            int extensionPos = viewId.lastIndexOf('.');
-            if (extensionPos > -1 && extensionPos > slashPos)
+            if (viewId.endsWith(defaultSuffix))
             {
-                builder.replace(extensionPos, viewId.length(), defaultSuffix);
+                endWithAnyDefaultSuffix = true;
+                break;
             }
-            else
+        }
+
+        if (!endWithAnyDefaultSuffix)
+        {
+            //Try to locate any resource that match with the expected id
+            for (String defaultSuffix : defaultSuffixes)
             {
-                builder.append(defaultSuffix);
+                StringBuilder builder = new StringBuilder(viewId);
+                int slashPos = viewId.lastIndexOf('/');
+                int extensionPos = viewId.lastIndexOf('.');
+                if (extensionPos > -1 && extensionPos > slashPos)
+                {
+                    builder.replace(extensionPos, viewId.length(), defaultSuffix);
+                }
+                else
+                {
+                    builder.append(defaultSuffix);
+                }
+                String tempViewId = builder.toString();
+                try
+                {
+                    if (context.getExternalContext().getResource(tempViewId) != null)
+                    {
+                        viewId = builder.toString();
+                        break;
+                    }                    
+                }
+                catch(MalformedURLException e)
+                {
+                    //Keep looking for an id
+                }
             }
-            viewId = builder.toString();
             if (log.isTraceEnabled())
             {
                 log.trace("view id after applying the context suffix: " + viewId);