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 2012/03/27 01:34:18 UTC

svn commit: r1305670 [2/2] - in /myfaces/shared/trunk/core: ./ src/main/java/org/apache/myfaces/shared/application/ src/main/java/org/apache/myfaces/shared/config/ src/main/java/org/apache/myfaces/shared/renderkit/ src/main/java/org/apache/myfaces/shar...

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ExternalContextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ExternalContextUtils.java?rev=1305670&r1=1305669&r2=1305670&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ExternalContextUtils.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/ExternalContextUtils.java Mon Mar 26 23:34:17 2012
@@ -27,686 +27,753 @@ import java.util.logging.Logger;
 import javax.faces.context.ExternalContext;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
 import javax.servlet.ServletResponseWrapper;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.myfaces.shared.view.HttpServletResponseSwitch;
-import org.apache.myfaces.shared.view.ResponseSwitch;
-import org.apache.myfaces.shared.view.ServletResponseSwitch;
-
 /**
- * This provides some functionality for determining some things about the 
- * native request object that is not provided by the base utils.
- *
- * @version $Revision$ $Date$
+ * This provides some functionality for determining some things about the
+ * native request object that is not provided by JSF.  This class is useful
+ * for use in places where Portlet API's may or may not be present and can
+ * also provide access to some request-specific items which are not available on
+ * the JSF ExternalContext.  If portlet API's are not present, this class simply 
+ * handles the Servlet Request type.
  */
 public final class ExternalContextUtils
 {
-  
-  /**
-   * Returns <code>true</code> if a particular class relating to the supplied
-   * request type is available on the current classpath or <code>false</code> 
-   * if it is not.  This class assumes that all containers have a servlet type
-   * request available, but the portlet request types are all dependant on the 
-   * portlet container being used.
-   * 
-   * @param type the RequestType to test
-   * @return a boolean value of <code>true</code> if the container contains the
-   *         request type in the classpath
-   * @since 2.0
-   */
-  public static final boolean isRequestTypeAvailable(RequestType type)
-  {
-    switch (type)
+
+    /**
+     * Returns <code>true</code> if a particular class relating to the supplied
+     * request type is available on the current classpath or <code>false</code> 
+     * if it is not.  This class assumes that all containers have a servlet type
+     * request available, but the portlet request types are all dependant on the 
+     * portlet container being used.
+     * 
+     * @param type the RequestType to test
+     * @return a boolean value of <code>true</code> if the container contains the
+     *         request type in the classpath
+     * @since 2.0
+     */
+    public static final boolean isRequestTypeAvailable(RequestType type)
     {
-      case SERVLET:
-        return true;
-        
-      case ACTION:
-      case RENDER:
-        return _PORTLET_CONTEXT_CLASS != null;
-      
-      case RESOURCE:
-      case EVENT:
-        return _PORTLET_RENDER_REQUEST_CLASS != null;
-        
-      default:
-        return false;
+        switch (type)
+        {
+        case SERVLET:
+            return true;
+
+        case ACTION:
+        case RENDER:
+            return _PORTLET_CONTEXT_CLASS != null;
+
+        case RESOURCE:
+        case EVENT:
+            return _PORTLET_RENDER_REQUEST_CLASS != null;
+
+        default:
+            return false;
+        }
     }
-  }
 
-  /**
-   * Returns <code>true</code> if a particular request type is supported by the
-   * container.  For a request type to be supported, the required objects must
-   * be on the classpath AND and, in the case of Portlet RequestTypes, an 
-   * appropriate bridge must be avaialble which supports those objects.  This
-   * means that if the supplied RequestType is RESOURCE, the 
-   * javax.portlet.ResourceRequest object must be available on the classpath AND
-   * a bridge which supports the Portlet 2.0 specification would also need to be
-   * available.
-   * 
-   * @param type the RequestType to test
-   * @return a boolean value of <code>true</code> if the container supports the
-   *         current request type
-   * @since 2.0
-   */
-  public static final boolean isRequestTypeSupported(RequestType type)
-  {
-    switch (type)
+    /**
+     * Returns <code>true</code> if a particular request type is supported by the
+     * container.  For a request type to be supported, the required objects must
+     * be on the classpath AND and, in the case of Portlet RequestTypes, an 
+     * appropriate bridge must be avaialble which supports those objects.  This
+     * means that if the supplied RequestType is RESOURCE, the 
+     * javax.portlet.ResourceRequest object must be available on the classpath AND
+     * a bridge which supports the Portlet 2.0 specification would also need to be
+     * available.
+     * 
+     * @param type the RequestType to test
+     * @return a boolean value of <code>true</code> if the container supports the
+     *         current request type
+     * @since 2.0
+     */
+    public static final boolean isRequestTypeSupported(RequestType type)
     {
-      case SERVLET:
-        return true;
+        switch (type)
+        {
+        case SERVLET:
+            return true;
+
+        case ACTION:
+        case RENDER:
+            return _PORTLET_10_SUPPORTED;
+
+        case RESOURCE:
+        case EVENT:
+            return _PORTLET_20_SUPPORTED;
+
+        default:
+            return false;
+        }
+    }
+    
+    /**
+     * Returns the requestType of this ExternalContext.
+     * 
+     * @param externalContext the current external context
+     * @return the appropriate RequestType for this external context
+     * @see RequestType
+     */
+    public static final RequestType getRequestType(ExternalContext externalContext)
+    {
+        //Stuff is laid out strangely in this class in order to optimize
+        //performance.  We want to do as few instanceof's as possible so
+        //things are laid out according to the expected frequency of the
+        //various requests occurring.
+        if(_PORTLET_10_SUPPORTED || _PORTLET_20_SUPPORTED)
+        {
+            if (_PORTLET_CONTEXT_CLASS.isInstance(externalContext.getContext()))
+            {
+                //We are inside of a portlet container
+                Object request = externalContext.getRequest();
+                
+                if(_PORTLET_RENDER_REQUEST_CLASS.isInstance(request))
+                {
+                    return RequestType.RENDER;
+                }
+                
+                if(_PORTLET_RESOURCE_REQUEST_CLASS != null)
+                {
+                    if(_PORTLET_ACTION_REQUEST_CLASS.isInstance(request))
+                    {
+                        return RequestType.ACTION;
+                    }
+
+                    //We are in a JSR-286 container
+                    if(_PORTLET_RESOURCE_REQUEST_CLASS.isInstance(request))
+                    {
+                        return RequestType.RESOURCE;
+                    }
+                    
+                    return RequestType.EVENT;
+                }
+                
+                return RequestType.ACTION;
+            }
+        }
         
-      case ACTION:
-      case RENDER:
-        return _PORTLET_10_SUPPORTED;
-      
-      case RESOURCE:
-      case EVENT:
-        return _PORTLET_20_SUPPORTED;
+        return RequestType.SERVLET;
+    }
+
+    /**
+     * This method is used when a ExternalContext object is not available,
+     * like in TomahawkFacesContextFactory.
+     * 
+     * According to TOMAHAWK-1331, the object context could receive an
+     * instance of javax.portlet.PortletContext or javax.portlet.PortletConfig,
+     * so we check both cases.
+     * 
+     * @param context
+     * @param request
+     * @return
+     */
+    public static final RequestType getRequestType(Object context, Object request)
+    {
+        //Stuff is laid out strangely in this class in order to optimize
+        //performance.  We want to do as few instanceof's as possible so
+        //things are laid out according to the expected frequency of the
+        //various requests occurring.
+
+        if(_PORTLET_10_SUPPORTED || _PORTLET_20_SUPPORTED)
+        {
+            if (_PORTLET_CONFIG_CLASS.isInstance(context) ||
+                _PORTLET_CONTEXT_CLASS.isInstance(context))
+            {
+                //We are inside of a portlet container
+                
+                if(_PORTLET_RENDER_REQUEST_CLASS.isInstance(request))
+                {
+                    return RequestType.RENDER;
+                }
+                
+                if(_PORTLET_RESOURCE_REQUEST_CLASS != null)
+                {
+                    if(_PORTLET_ACTION_REQUEST_CLASS.isInstance(request))
+                    {
+                        return RequestType.ACTION;
+                    }
+
+                    //We are in a JSR-286 container
+                    if(_PORTLET_RESOURCE_REQUEST_CLASS.isInstance(request))
+                    {
+                        return RequestType.RESOURCE;
+                    }
+                    
+                    return RequestType.EVENT;
+                }
+                
+                return RequestType.ACTION;
+            }
+        }
         
-      default:
-        return false;
+        return RequestType.SERVLET;
+    }
+
+    /**
+     * Returns the current active session id or <code>null</code> if there is
+     * none.  If a session is not already created, this method will create one
+     * for you.
+     * 
+     * @param ec the current external context
+     * @return a string containing the requestedSessionId
+     */
+    public static String getSessionId(ExternalContext ec)
+    {
+        return getSessionId(ec, true);
+    }
+
+    /**
+     * Returns the current active session id or <code>null</code> if there is
+     * none.
+     * 
+     * @param ec the current external context
+     * @param create create a new session if one is not created
+     * @return a string containing the requestedSessionId
+     */
+    public static String getSessionId(ExternalContext ec, boolean create)
+    {
+        Object session = ec.getSession(create);
+        return (null != session) ? (String) _runMethod(session, "getId") : null;
+    }
+
+    /**
+     * Returns the session ID for the client, or <code>null</code> if there is none.
+     *
+     * @param ec the current external context
+     * @return a string containing the requestedSessionId
+     */
+    public static String getRequestedSessionId(ExternalContext ec)
+    {
+        return (String) _runMethod(ec.getRequest(), "getRequestedSessionId");
+    }
+
+    /**
+     * Checks if the requested session ID is still valid.
+     *
+     * @param ec the current external context
+     * @return a boolean containing <code>true</code> if the request session is
+     *         valid or <code>false</code> if it is not
+     */
+    public static boolean isRequestedSessionIdValid(ExternalContext ec)
+    {
+        return (Boolean) _runMethod(ec.getRequest(),
+                "isRequestedSessionIdValid");
+    }
+
+    /**
+     * Returns the contextPath of the ServletContext or <code>null</code> for portlets
+     *
+     * @param ec the current external context
+     * @return a String containing the servletContextPath
+     */
+    public static String getServletContextPath(ExternalContext ec)
+    {
+        if (!isPortlet(ec))
+        {
+            return ((ServletContext) ec.getContext()).getContextPath();
+        }
+        else
+        {
+            return null;
+        }
     }
-  }
-  
-  /**
-   * Returns the requestType of this ExternalContext.
-   * 
-   * @param ec the current external context
-   * @return the appropriate RequestType for this external context
-   * @see RequestType
-   * @since 2.0
-   */
-  public static final RequestType getRequestType(ExternalContext ec)
-  {
-    // Stuff is laid out strangely in this class in order to optimize
-    // performance. We want to do as few instanceof's as possible so
-    // things are laid out according to the expected frequency of the
-    // various requests occurring.
-    if(_PORTLET_10_SUPPORTED)
-    {
-      if (_PORTLET_CONTEXT_CLASS.isInstance(ec.getContext()))
-      {
-        //We are inside of a portlet container
-        Object request = ec.getRequest();
-
-        if(_PORTLET_RENDER_REQUEST_CLASS.isInstance(request))
-        {
-          return RequestType.RENDER;
-        }
-
-        if(_PORTLET_RESOURCE_REQUEST_CLASS != null)
-        {
-          if(_PORTLET_ACTION_REQUEST_CLASS.isInstance(request))
-          {
-            return RequestType.ACTION;
-          }
-
-          // We are in a JSR-286 container
-          if(_PORTLET_RESOURCE_REQUEST_CLASS.isInstance(request))
-          {
-            return RequestType.RESOURCE;
-          }
-
-          return RequestType.EVENT;
-        }
-
-        return RequestType.ACTION;
-      }
-    }
-
-    return RequestType.SERVLET;
-  }
-  
-  /**
-   * Returns the current active session id or <code>null</code> if there is
-   * none.  If a session is not already created, this method will create one
-   * for you.
-   * 
-   * @param ec the current external context
-   * @return a string containing the requestedSessionId
-   */
-  public static String getSessionId(ExternalContext ec)
-  {
-    return getSessionId(ec, true);
-  }
-
-  /**
-   * Returns the current active session id or <code>null</code> if there is
-   * none.
-   * 
-   * @param ec the current external context
-   * @param create create a new session if one is not created
-   * @return a string containing the requestedSessionId
-   */
-  public static String getSessionId(ExternalContext ec, boolean create)
-  {
-    Object session = ec.getSession(create);   
-    return (null!=session)?(String)_runMethod(session, "getId"):null;
-  }
-
-  /**
-   * Returns the session ID for the client, or <code>null</code> if there is none.
-   *
-   * @param ec the current external context
-   * @return a string containing the requestedSessionId
-   */
-  public static String getRequestedSessionId(ExternalContext ec)
-  {
-    return (String) _runMethod(ec.getRequest(), "getRequestedSessionId");
-  }
-
-  /**
-   * Checks if the requested session ID is still valid.
-   *
-   * @param ec the current external context
-   * @return a boolean containing <code>true</code> if the request session is
-   *         valid or <code>false</code> if it is not
-   */
-  public static boolean isRequestedSessionIdValid(ExternalContext ec)
-  {
-    return (Boolean) _runMethod(ec.getRequest(), "isRequestedSessionIdValid");
-  }
-  
-  /**
-   * Returns the contextPath of the ServletContext or <code>null</code> for portlets
-   *
-   * @param ec the current external context
-   * @return a String containing the servletContextPath
-   */
-  public static String getServletContextPath(ExternalContext ec)
-  {
-    if(!isPortlet(ec))
-    {
-      return ((ServletContext) ec.getContext()).getContextPath();
-    }
-    else
-    {
-      return null;
-    }
-  }
-
-  /**
-   * Returns the contextPath of the ServletRequest or <code>null</code> for portlet requests
-   *
-   * @param ec the current external context
-   * @return a String containing the request context path
-   * @see ExternalContext#getRequestContextPath()
-   * 
-   * @deprecated use ExternalContext.getRequestContextPath() as of JSF 1.2.  This method
-   *             does not appropriately handle portlet environments, but the functionality
-   *             is maintained to prevent needing to change the contract.
-   */
-  @Deprecated
-  public static String getRequestContextPath(ExternalContext ec)
-  { 
-    if(!isPortlet(ec))
-    {
-      return ec.getRequestContextPath();
-    }
-    else
-    {
-     return null;
-    }
-  }
-
-  /**
-   * Returns the requestURI of the HttpServletRequest or <code>null</code> for 
-   * portlet requests
-   *
-   * @param ec the current external context
-   * @return A string containing the current request uri
-   */
-  public static String getRequestURI(ExternalContext ec)
-  { 
-    if (!isPortlet(ec))
-    {
-      return ((HttpServletRequest) ec.getRequest()).getRequestURI();
-    }
-    else
-    {
-      return null;
-    }
-  }
-
-  /**
-   * Returns the character encoding or <code>null</code> if there isn't any
-   *
-   * @param ec the current external context
-   * @return a string containing the request's character encoding
-   * @see ExternalContext#getRequestCharacterEncoding()
-   * 
-   * @deprecated replaced by an API in JSF.  Use ExternalContext.getRequestCharacterEncoding()
-   */
-  @Deprecated
-  public static String getCharacterEncoding(ExternalContext ec)
-  {
-    return ec.getRequestCharacterEncoding();
-  }
-  
-  /**
-   * Returns the name of the underlying context or <code>null</code> if something
-   * went wrong in trying to retrieve the context.
-   * 
-   * @param ec the current external context
-   * @return a String containing the context name
-   */
-  public static String getContextName(ExternalContext ec)
-  {
-    try
-    {
-      if (isPortlet(ec))
-      {
-        return (String) _runMethod(ec.getContext(), "getPortletContextName");
-      }
-      else
-      {
-        return ((ServletContext) ec.getContext()).getServletContextName();
-      }
-    }
-    catch (final ClassCastException e)
-    {
-      _LOG.severe(e.getMessage());
-    }
-    return null;
-  }
-
-  /**
-   * Returns the name and version of the underlying servlet container or <code>null</code> if something
-   * went wrong in trying to retrieve the context.
-   *
-   * @param ec the current external context
-   * @return a String containing the name and version of the underlying servlet container
-   */
-  public static String getServerInfo(ExternalContext ec)
-  {
-    try
-    {
-      if (isPortlet(ec))
-      {
-        return (String) _runMethod(ec.getContext(), "getServerInfo");
-      }
-      else
-      {
-        return ((ServletContext) ec.getContext()).getServerInfo();
-      }
-    }
-    catch (final ClassCastException e)
-    {
-      _LOG.severe(e.getMessage());
-    }
-    return null;
-  }
-
-  /**
-   * Returns the content length or -1 if the unknown.
-   *
-   * @param ec the current external context
-   * @return the length or -1 if the length is unknown
-   */
-  public static int getContentLength(ExternalContext ec)
-  {
-    if(isRequestFromClient(ec))
-    {
-      return (Integer) _runMethod(ec.getRequest(), "getContentLength");
-    }
-
-    return -1;
-  }
-
-  /**
-   * Returns the content type from the current externalContext or
-   * <code>null</code> if unknown.
-   *
-   * @param ec the current external context
-   * @return a String contining the the content type or <code>null</code>
-   * @see ExternalContext#getRequestContentType()
-   *
-   * @deprecated use ExternalContext.getRequestContentType()
-   */
-  @Deprecated
-  public static String getContentType(ExternalContext ec)
-  {
-    return ec.getRequestContentType();
-  }
-
-  /**
-   * Returns the request input stream if one is available
-   *
-   * @param ec the current external context
-   * @return the request's input stream
-   * @throws IOException if there was a problem getting the input stream
-   */
-  public static InputStream getRequestInputStream(ExternalContext ec)
-      throws IOException
-  { 
-    RequestType type = getRequestType(ec);
-    if(type.isRequestFromClient())
-    {
-      Object req = ec.getRequest();
-      if(type.isPortlet())
-      {
-        return (InputStream)_runMethod(req, "getPortletInputStream");
-      }
-      else
-      {
-        return ((ServletRequest) ec.getRequest()).getInputStream();
-      }
+
+    /**
+     * Returns the contextPath of the ServletRequest or <code>null</code> for portlet requests
+     *
+     * @param ec the current external context
+     * @return a String containing the request context path
+     * @see ExternalContext#getRequestContextPath()
+     * 
+     * @deprecated use ExternalContext.getRequestContextPath() as of JSF 1.2.  This method
+     *             does not appropriately handle portlet environments, but the functionality
+     *             is maintained to prevent needing to change the contract.
+     */
+    @Deprecated
+    public static String getRequestContextPath(ExternalContext ec)
+    {
+        if (!isPortlet(ec))
+        {
+            return ec.getRequestContextPath();
+        }
+        else
+        {
+            return null;
+        }
     }
-    
-    return null;
-  }
 
-  /**
-   * Returns <code>true</code> if this externalContext represents an "action". 
-   * An action request is any ServletRequest or a portlet ActionRequest or 
-   * ResourceRequest.
-   *
-   * @param ec the current external context
-   * @return a boolean of <code>true</code> if this request is an action-type
-   *         request.
-   * @see #isRequestFromClient(ExternalContext)
-   *         
-   * @deprecated replaced with {@link #isRequestFromClient(ExternalContext)}
-   */
-  @Deprecated
-  public static boolean isAction(ExternalContext ec)
-  {
-    return isRequestFromClient(ec);
-  }
-
-  /**
-   * Returns the value of {@link RequestType#isPortlet()} for the current
-   * RequestType. This is a convenience function designed to perform a quick
-   * check of the current request. If more capabilities need to be tested for
-   * the given request, then it is more efficient to pull this information from
-   * the RequestType itself.
-   * 
-   * @param ec the current external context
-   * @return a boolean value of <code>true</code> if the current RequestType
-   *         is a portlet request.
-   * 
-   * @see RequestType#isPortlet()
-   * @see #getRequestType(ExternalContext)
-   */
-  public static boolean isPortlet(ExternalContext ec)
-  {
-    return getRequestType(ec).isPortlet();
-  }
-
-  /**
-   * Returns the value of {@link RequestType#isResponseWritable()} for the
-   * current RequestType. This is a convenience function designed to perform a
-   * quick check of the current request. If more capabilities need to be tested
-   * for the given request, then it is more efficient to pull this information
-   * from the RequestType itself.
-   * 
-   * @param ec the current external context
-   * @return a boolean value of <code>true</code> if the current RequestType
-   *         is a "render" type response.
-   * 
-   * @see RequestType#isResponseWritable()
-   * @see #getRequestType(ExternalContext)
-   * @since 2.0
-   */
-  public static final boolean isResponseWritable(ExternalContext ec)
-  {
-    return getRequestType(ec).isResponseWritable();
-  }
-
-  /**
-   * Returns the value of {@link RequestType#isRequestFromClient()} for the
-   * current RequestType. This is a convenience function designed to perform a
-   * quick check of the current request. If more capabilities need to be tested
-   * for the given request, then it is more efficient to pull this information
-   * from the RequestType itself.
-   * 
-   * @param ec the current external context
-   * @return a boolean value of <code>true</code> if the current RequestType
-   *         represents a request from the client.
-   * 
-   * @see RequestType#isResponseWritable()
-   * @see #getRequestType(ExternalContext)
-   * @since 2.0
-   */
-  public static final boolean isRequestFromClient(ExternalContext ec)
-  {
-    return getRequestType(ec).isRequestFromClient();
-  }
-  
-  /**
-   * Returns wherther of not this external context represents a true HttpServletRequest or
-   * not.  Some portal containers implement the PortletRequest/Response objects as 
-   * HttpServletRequestWrappers, and those objects should not be treated as an
-   * HttpServlerRequest.  As such, this method first tests to see if the request is
-   * a portlet request and, if not, then tests to see if the request is an instanceof
-   * HttpServletRequest.
-   * 
-   * @param ec the current external context
-   * @return a boolean value of <code>true</code> if the current request is an
-   *         HttpServletRequest
-   * @since 1.1
-   */
-  public static boolean isHttpServletRequest(ExternalContext ec)
-  {
-    return (!isPortlet(ec) && (ec.getRequest() instanceof HttpServletRequest));
-  }
-  
-  /**
-   * Returns an HttpServletResponse if one exists on the externalContext or null
-   * if it does not.  Please note that some portal environments implement the
-   * PortletRequest and Response objects as HttpServletRequest/Response objects.
-   * This method handles these types of requests properly and will therefore
-   * return null in portal environments.
-   * 
-   * @param response
-   * @return an HttpServletResponse if we have one or null if we do not
-   * @since 4.0
-   */
-  public static HttpServletResponse getHttpServletResponse(ExternalContext ec)
-  {
-    if(isHttpServletRequest(ec))
+    /**
+     * Returns the requestURI of the HttpServletRequest or <code>null</code> for 
+     * portlet requests
+     *
+     * @param ec the current external context
+     * @return A string containing the current request uri
+     */
+    public static String getRequestURI(ExternalContext ec)
     {
-      return (HttpServletResponse)ec.getResponse();
+        if (!isPortlet(ec))
+        {
+            return ((HttpServletRequest) ec.getRequest()).getRequestURI();
+        }
+        else
+        {
+            return null;
+        }
     }
-    
-    return null;
-  }
 
-  /**
-   * Runs a method on an object and returns the result
-   * 
-   * @param obj the object to run the method on
-   * @param methodName the name of the method
-   * @return the results of the method run
-   */
-  private static Object _runMethod(Object obj, String methodName)
-  {
-    try
-    {
-      Method sessionIdMethod = obj.getClass().getMethod(methodName);
-      return sessionIdMethod.invoke(obj);
-    }
-    catch (Exception e)
-    {
-      return null;
-    }
-
-  }
-  
-  // prevent this from being instantiated
-  private ExternalContextUtils()
-  {}
-
-  private static final Logger _LOG = Logger.getLogger(ExternalContextUtils.class.getName());
-
-  // =-= Scott O'Bryan =-=
-  // Performance enhancement. These will be needed anyway, let's not get them every time.
-  private static final Class<?> _PORTLET_ACTION_REQUEST_CLASS;
-  private static final Class<?> _PORTLET_RENDER_REQUEST_CLASS;
-  private static final Class<?> _PORTLET_RESOURCE_REQUEST_CLASS;
-  private static final Class<?> _PORTLET_CONTEXT_CLASS;
-  private static final boolean _PORTLET_10_SUPPORTED;
-  private static final boolean _PORTLET_20_SUPPORTED;
-
-  static
-  {
-    Class<?> context;
-    Class<?> actionRequest;
-    Class<?> renderRequest;
-    Class<?> resourceRequest;
-    boolean portlet20Supported = false;
-    boolean portlet10Supported = false;
-
-    try
-    {
-      context = ClassLoaderUtils.loadClass("javax.portlet.PortletContext");
-      actionRequest = ClassLoaderUtils.loadClass("javax.portlet.ActionRequest");
-      renderRequest = ClassLoaderUtils.loadClass("javax.portlet.RenderRequest");
-
-      try
-      {
-        resourceRequest = ClassLoaderUtils.loadClass("javax.portlet.ResourceRequest"); 
-      }
-      catch (ClassNotFoundException e)
-      {
-        _LOG.fine("Portlet 2.0 API is not available on classpath.  Portlet 2.0 functionality is disabled");
-        resourceRequest = null;
-      }
-    }
-    catch (final ClassNotFoundException e)
-    {
-      _LOG
-          .fine("Portlet API is not available on the classpath.  Portlet configurations are disabled.");
-      context = null;
-      actionRequest = null;
-      renderRequest = null;
-      resourceRequest = null;
+    /**
+     * Returns the character encoding or <code>null</code> if there isn't any
+     *
+     * @param ec the current external context
+     * @return a string containing the request's character encoding
+     * @see ExternalContext#getRequestCharacterEncoding()
+     * 
+     * @deprecated replaced by an API in JSF.  Use ExternalContext.getRequestCharacterEncoding()
+     */
+    @Deprecated
+    public static String getCharacterEncoding(ExternalContext ec)
+    {
+        return ec.getRequestCharacterEncoding();
+    }
+
+    /**
+     * Returns the name of the underlying context or <code>null</code> if something
+     * went wrong in trying to retrieve the context.
+     * 
+     * @param ec the current external context
+     * @return a String containing the context name
+     */
+    public static String getContextName(ExternalContext ec)
+    {
+        try
+        {
+            if (isPortlet(ec))
+            {
+                return (String) _runMethod(ec.getContext(),
+                        "getPortletContextName");
+            }
+            else
+            {
+                return ((ServletContext) ec.getContext())
+                        .getServletContextName();
+            }
+        }
+        catch (final ClassCastException e)
+        {
+            _LOG.severe(e.getMessage());
+        }
+        return null;
     }
-    
-    //Find bridge to tell if portal is supported
-    if(context != null) 
+
+    /**
+     * Returns the name and version of the underlying servlet container or <code>null</code> if something
+     * went wrong in trying to retrieve the context.
+     *
+     * @param ec the current external context
+     * @return a String containing the name and version of the underlying servlet container
+     */
+    public static String getServerInfo(ExternalContext ec)
     {
-      // Portlet 1.0 API found. In this case we have to consider that exists alternate
-      // bridge implementations like in WebSphere and others.
-      portlet10Supported = true;
-
-      try
-      {
-        Class<?> bridge = ClassLoaderUtils.loadClass("javax.portlet.faces.Bridge");
-        
-        if(bridge != null)
+        try
         {
-          //Standard bridge defines a spec name which can be used to 
-          //determine Portlet 2.0 Support.
-          String specName = bridge.getPackage().getSpecificationTitle();
-          _LOG.fine("Found Bridge: " + specName);
-          if(specName != null && specName.startsWith("Portlet 2"))
-          {
-            portlet20Supported = true;
-          }
-          
-          if(_LOG.isLoggable(Level.INFO))
-          {
-            String ver = (portlet20Supported)?"2.0":"1.0";
-            _LOG.info("Portlet Environment Detected: " + ver);            
-          }
-        }
-      }
-      catch (ClassNotFoundException e)
-      {
-        _LOG.fine("Portlet API is present but Standard Apache Portlet Bridge is not. " +
-                " This could happen if you are using an alternate Portlet Bridge solution.");
-        
-        if (resourceRequest != null)
+            if (isPortlet(ec))
+            {
+                return (String) _runMethod(ec.getContext(), "getServerInfo");
+            }
+            else
+            {
+                return ((ServletContext) ec.getContext()).getServerInfo();
+            }
+        }
+        catch (final ClassCastException e)
+        {
+            _LOG.severe(e.getMessage());
+        }
+        return null;
+    }
+
+    /**
+     * Returns the content length or -1 if the unknown.
+     *
+     * @param ec the current external context
+     * @return the length or -1 if the length is unknown
+     */
+    public static int getContentLength(ExternalContext ec)
+    {
+        if (isRequestFromClient(ec))
+        {
+            return (Integer) _runMethod(ec.getRequest(), "getContentLength");
+        }
+
+        return -1;
+    }
+
+    /**
+     * Returns the content type from the current externalContext or
+     * <code>null</code> if unknown.
+     *
+     * @param ec the current external context
+     * @return a String contining the the content type or <code>null</code>
+     * @see ExternalContext#getRequestContentType()
+     *
+     * @deprecated use ExternalContext.getRequestContentType()
+     */
+    @Deprecated
+    public static String getContentType(ExternalContext ec)
+    {
+        return ec.getRequestContentType();
+    }
+
+    /**
+     * Returns the request input stream if one is available
+     *
+     * @param ec the current external context
+     * @return the request's input stream
+     * @throws IOException if there was a problem getting the input stream
+     */
+    public static InputStream getRequestInputStream(ExternalContext ec)
+            throws IOException
+    {
+        RequestType type = getRequestType(ec);
+        if (type.isRequestFromClient())
+        {
+            Object req = ec.getRequest();
+            if (type.isPortlet())
+            {
+                return (InputStream) _runMethod(req, "getPortletInputStream");
+            }
+            else
+            {
+                return ((ServletRequest) ec.getRequest()).getInputStream();
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Returns <code>true</code> if this externalContext represents an "action". 
+     * An action request is any ServletRequest or a portlet ActionRequest or 
+     * ResourceRequest.
+     *
+     * @param ec the current external context
+     * @return a boolean of <code>true</code> if this request is an action-type
+     *         request.
+     * @see #isRequestFromClient(ExternalContext)
+     *         
+     * @deprecated replaced with {@link #isRequestFromClient(ExternalContext)}
+     */
+    @Deprecated
+    public static boolean isAction(ExternalContext ec)
+    {
+        return isRequestFromClient(ec);
+    }
+
+    /**
+     * Returns the value of {@link RequestType#isPortlet()} for the current
+     * RequestType. This is a convenience function designed to perform a quick
+     * check of the current request. If more capabilities need to be tested for
+     * the given request, then it is more efficient to pull this information from
+     * the RequestType itself.
+     * 
+     * @param ec the current external context
+     * @return a boolean value of <code>true</code> if the current RequestType
+     *         is a portlet request.
+     * 
+     * @see RequestType#isPortlet()
+     * @see #getRequestType(ExternalContext)
+     */
+    public static boolean isPortlet(ExternalContext ec)
+    {
+        return getRequestType(ec).isPortlet();
+    }
+
+    /**
+     * Returns the value of {@link RequestType#isResponseWritable()} for the
+     * current RequestType. This is a convenience function designed to perform a
+     * quick check of the current request. If more capabilities need to be tested
+     * for the given request, then it is more efficient to pull this information
+     * from the RequestType itself.
+     * 
+     * @param ec the current external context
+     * @return a boolean value of <code>true</code> if the current RequestType
+     *         is a "render" type response.
+     * 
+     * @see RequestType#isResponseWritable()
+     * @see #getRequestType(ExternalContext)
+     * @since 2.0
+     */
+    public static final boolean isResponseWritable(ExternalContext ec)
+    {
+        return getRequestType(ec).isResponseWritable();
+    }
+
+    /**
+     * Returns the value of {@link RequestType#isRequestFromClient()} for the
+     * current RequestType. This is a convenience function designed to perform a
+     * quick check of the current request. If more capabilities need to be tested
+     * for the given request, then it is more efficient to pull this information
+     * from the RequestType itself.
+     * 
+     * @param ec the current external context
+     * @return a boolean value of <code>true</code> if the current RequestType
+     *         represents a request from the client.
+     * 
+     * @see RequestType#isResponseWritable()
+     * @see #getRequestType(ExternalContext)
+     * @since 2.0
+     */
+    public static final boolean isRequestFromClient(ExternalContext ec)
+    {
+        return getRequestType(ec).isRequestFromClient();
+    }
+
+    /**
+     * Returns wherther of not this external context represents a true HttpServletRequest or
+     * not.  Some portal containers implement the PortletRequest/Response objects as 
+     * HttpServletRequestWrappers, and those objects should not be treated as an
+     * HttpServlerRequest.  As such, this method first tests to see if the request is
+     * a portlet request and, if not, then tests to see if the request is an instanceof
+     * HttpServletRequest.
+     * 
+     * @param ec the current external context
+     * @return a boolean value of <code>true</code> if the current request is an
+     *         HttpServletRequest
+     * @since 1.1
+     */
+    public static boolean isHttpServletRequest(ExternalContext ec)
+    {
+        return (!isPortlet(ec) && (ec.getRequest() instanceof HttpServletRequest));
+    }
+
+    /**
+     * Returns an HttpServletResponse if one exists on the externalContext or null
+     * if it does not.  Please note that some portal environments implement the
+     * PortletRequest and Response objects as HttpServletRequest/Response objects.
+     * This method handles these types of requests properly and will therefore
+     * return null in portal environments.
+     * 
+     * @param response
+     * @return an HttpServletResponse if we have one or null if we do not
+     * @since 4.0
+     */
+    public static HttpServletResponse getHttpServletResponse(ExternalContext ec)
+    {
+        if (isHttpServletRequest(ec))
+        {
+            return (HttpServletResponse) ec.getResponse();
+        }
+
+        return null;
+    }
+
+    /**
+     * Runs a method on an object and returns the result
+     * 
+     * @param obj the object to run the method on
+     * @param methodName the name of the method
+     * @return the results of the method run
+     */
+    private static Object _runMethod(Object obj, String methodName)
+    {
+        try
+        {
+            Method sessionIdMethod = obj.getClass().getMethod(methodName);
+            return sessionIdMethod.invoke(obj);
+        }
+        catch (Exception e)
+        {
+            return null;
+        }
+
+    }
+
+    // prevent this from being instantiated
+    private ExternalContextUtils()
+    {
+    }
+
+    private static final Logger _LOG = Logger
+            .getLogger(ExternalContextUtils.class.getName());
+
+    // =-= Scott O'Bryan =-=
+    // Performance enhancement. These will be needed anyway, let's not get them every time.
+    private static final Class<?> _PORTLET_ACTION_REQUEST_CLASS;
+    private static final Class<?> _PORTLET_RENDER_REQUEST_CLASS;
+    private static final Class<?> _PORTLET_RESOURCE_REQUEST_CLASS;
+    private static final Class<?> _PORTLET_CONTEXT_CLASS;
+    private static final boolean _PORTLET_10_SUPPORTED;
+    private static final boolean _PORTLET_20_SUPPORTED;
+    private static final Class<?> _PORTLET_CONFIG_CLASS;
+
+    static
+    {
+        Class<?> context;
+        Class<?> config;
+        Class<?> actionRequest;
+        Class<?> renderRequest;
+        Class<?> resourceRequest;
+        boolean portlet20Supported = false;
+        boolean portlet10Supported = false;
+
+        try
+        {
+            context = ClassLoaderUtils
+                    .loadClass("javax.portlet.PortletContext");
+            config = ClassLoaderUtils.loadClass("javax.portlet.PortletConfig");
+            actionRequest = ClassLoaderUtils
+                    .loadClass("javax.portlet.ActionRequest");
+            renderRequest = ClassLoaderUtils
+                    .loadClass("javax.portlet.RenderRequest");
+
+            try
+            {
+                resourceRequest = ClassLoaderUtils
+                        .loadClass("javax.portlet.ResourceRequest");
+            }
+            catch (ClassNotFoundException e)
+            {
+                _LOG.fine("Portlet 2.0 API is not available on classpath.  Portlet 2.0 functionality is disabled");
+                resourceRequest = null;
+            }
+        }
+        catch (final ClassNotFoundException e)
+        {
+            _LOG.fine("Portlet API is not available on the classpath.  Portlet configurations are disabled.");
+            context = null;
+            config = null;
+            actionRequest = null;
+            renderRequest = null;
+            resourceRequest = null;
+        }
+
+        //Find bridge to tell if portal is supported
+        if (context != null)
+        {
+            // Portlet 1.0 API found. In this case we have to consider that exists alternate
+            // bridge implementations like in WebSphere and others.
+            portlet10Supported = true;
+
+            try
+            {
+                Class<?> bridge = ClassLoaderUtils
+                        .loadClass("javax.portlet.faces.Bridge");
+
+                if (bridge != null)
+                {
+                    //Standard bridge defines a spec name which can be used to 
+                    //determine Portlet 2.0 Support.
+                    String specName = bridge.getPackage()
+                            .getSpecificationTitle();
+                    _LOG.fine("Found Bridge: " + specName);
+                    if (specName != null && specName.startsWith("Portlet 2"))
+                    {
+                        portlet20Supported = true;
+                    }
+
+                    if (_LOG.isLoggable(Level.INFO))
+                    {
+                        String ver = (portlet20Supported) ? "2.0" : "1.0";
+                        _LOG.info("Portlet Environment Detected: " + ver);
+                    }
+                }
+            }
+            catch (ClassNotFoundException e)
+            {
+                _LOG.fine("Portlet API is present but Standard Apache Portlet Bridge is not. "
+                        + " This could happen if you are using an alternate Portlet Bridge solution.");
+
+                if (resourceRequest != null)
+                {
+                    portlet20Supported = true;
+                }
+            }
+        }
+
+        _PORTLET_CONTEXT_CLASS = context;
+        _PORTLET_CONFIG_CLASS = config;
+        _PORTLET_ACTION_REQUEST_CLASS = actionRequest;
+        _PORTLET_RENDER_REQUEST_CLASS = renderRequest;
+        _PORTLET_RESOURCE_REQUEST_CLASS = resourceRequest;
+        _PORTLET_10_SUPPORTED = portlet10Supported;
+        _PORTLET_20_SUPPORTED = portlet20Supported;
+    }
+
+    /**
+     * Trys to obtain a HttpServletResponse from the Response.
+     * Note that this method also trys to unwrap any ServletResponseWrapper
+     * in order to retrieve a valid HttpServletResponse.
+     * @param response
+     * @return if found, the HttpServletResponse, null otherwise
+     */
+    public static HttpServletResponse getHttpServletResponse(Object response)
+    {
+        // unwrap the response until we find a HttpServletResponse
+        while (response != null)
         {
-            portlet20Supported = true;
+            if (response instanceof HttpServletResponse)
+            {
+                // found
+                return (HttpServletResponse) response;
+            }
+            if (response instanceof ServletResponseWrapper)
+            {
+                // unwrap
+                response = ((ServletResponseWrapper) response).getResponse();
+            }
+            // no more possibilities to find a HttpServletResponse
+            break;
         }
-      }
+        return null; // not found
     }
 
-    _PORTLET_CONTEXT_CLASS = context;
-    _PORTLET_ACTION_REQUEST_CLASS = actionRequest;
-    _PORTLET_RENDER_REQUEST_CLASS = renderRequest;
-    _PORTLET_RESOURCE_REQUEST_CLASS = resourceRequest;
-    _PORTLET_10_SUPPORTED = portlet10Supported;
-    _PORTLET_20_SUPPORTED = portlet20Supported;
-  }
-  
-  /**
-   * Trys to obtain a HttpServletResponse from the Response.
-   * Note that this method also trys to unwrap any ServletResponseWrapper
-   * in order to retrieve a valid HttpServletResponse.
-   * @param response
-   * @return if found, the HttpServletResponse, null otherwise
-   */
-  public static HttpServletResponse getHttpServletResponse(Object response)
-  {
-      // unwrap the response until we find a HttpServletResponse
-      while (response != null)
-      {
-          if (response instanceof HttpServletResponse)
-          {
-              // found
-              return (HttpServletResponse) response;
-          }
-          if (response instanceof ServletResponseWrapper)
-          {
-              // unwrap
-              response = ((ServletResponseWrapper) response).getResponse();
-          }
-          // no more possibilities to find a HttpServletResponse
-          break; 
-      }
-      return null; // not found
-  }
-  
-  /**
-   * Trys to obtain a ResponseSwitch from the Response.
-   * @param response
-   * @return if found, the ResponseSwitch, null otherwise
-   */
-  public static ResponseSwitch getResponseSwitch(Object response)
-  {
-      // unwrap the response until we find a ResponseSwitch
-      while (response != null)
-      {
-          if (response instanceof ResponseSwitch)
-          {
-              // found
-              return (ResponseSwitch) response;
-          }
-          if (response instanceof ServletResponseWrapper)
-          {
-              // unwrap
-              response = ((ServletResponseWrapper) response).getResponse();
-          }
-          // no more possibilities to find a ResponseSwitch
-          break; 
-      }
-      return null; // not found
-  }
-  
-  /**
-   * Try to create a ResponseSwitch for this response.
-   * @param response
-   * @return the created ResponseSwitch, if there is a ResponseSwitch 
-   *         implementation for the given response, null otherwise
-   */
-  public static ResponseSwitch createResponseSwitch(Object response)
-  {
-      if (response instanceof HttpServletResponse)
-      {
-          return new HttpServletResponseSwitch((HttpServletResponse) response);
-      }
-      else if (response instanceof ServletResponse)
-      {
-          return new ServletResponseSwitch((ServletResponse) response);
-      }
-      return null;
-  }
-  
+    /**
+     * Trys to obtain a ResponseSwitch from the Response.
+     * @param response
+     * @return if found, the ResponseSwitch, null otherwise
+     */
+    /*
+    public static ResponseSwitch getResponseSwitch(Object response)
+    {
+        // unwrap the response until we find a ResponseSwitch
+        while (response != null)
+        {
+            if (response instanceof ResponseSwitch)
+            {
+                // found
+                return (ResponseSwitch) response;
+            }
+            if (response instanceof ServletResponseWrapper)
+            {
+                // unwrap
+                response = ((ServletResponseWrapper) response).getResponse();
+            }
+            // no more possibilities to find a ResponseSwitch
+            break; 
+        }
+        return null; // not found
+    }*/
+
+    /**
+     * Try to create a ResponseSwitch for this response.
+     * @param response
+     * @return the created ResponseSwitch, if there is a ResponseSwitch 
+     *         implementation for the given response, null otherwise
+     */
+    /*
+    public static ResponseSwitch createResponseSwitch(Object response)
+    {
+        if (response instanceof HttpServletResponse)
+        {
+            return new HttpServletResponseSwitch((HttpServletResponse) response);
+        }
+        else if (response instanceof ServletResponse)
+        {
+            return new ServletResponseSwitch((ServletResponse) response);
+        }
+        return null;
+    }*/
+
 }

Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/PriorityQueue.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/PriorityQueue.java?rev=1305670&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/PriorityQueue.java (added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/PriorityQueue.java Mon Mar 26 23:34:17 2012
@@ -0,0 +1,304 @@
+/*
+ * 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.myfaces.shared.util;
+
+/** A PriorityQueue maintains a partial ordering of its elements such that the
+ * least element can always be found in constant time.  Put()'s and pop()'s
+ * require log(size) time.
+ *
+ * <p><b>NOTE</b>: This class will pre-allocate a full array of
+ * length <code>maxSize+1</code> if instantiated via the
+ * {@link #PriorityQueue(int,boolean)} constructor with
+ * <code>prepopulate</code> set to <code>true</code>.
+ * 
+ * @lucene.internal
+ * @see org.apache.lucene.util.PriorityQueue
+*/
+public abstract class PriorityQueue<T>
+{
+    private int size;
+    private final int maxSize;
+    private final T[] heap;
+
+    public PriorityQueue(int maxSize)
+    {
+        this(maxSize, true);
+    }
+
+    @SuppressWarnings("unchecked")
+    public PriorityQueue(int maxSize, boolean prepopulate)
+    {
+        size = 0;
+        int heapSize;
+        if (0 == maxSize)
+        {
+            // We allocate 1 extra to avoid if statement in top()
+            heapSize = 2;
+        }
+        else
+        {
+            if (maxSize == Integer.MAX_VALUE)
+            {
+                // Don't wrap heapSize to -1, in this case, which
+                // causes a confusing NegativeArraySizeException.
+                // Note that very likely this will simply then hit
+                // an OOME, but at least that's more indicative to
+                // caller that this values is too big.  We don't +1
+                // in this case, but it's very unlikely in practice
+                // one will actually insert this many objects into
+                // the PQ:
+                heapSize = Integer.MAX_VALUE;
+            }
+            else
+            {
+                // NOTE: we add +1 because all access to heap is
+                // 1-based not 0-based.  heap[0] is unused.
+                heapSize = maxSize + 1;
+            }
+        }
+        heap = (T[]) new Object[heapSize]; // T is unbounded type, so this unchecked cast works always
+        this.maxSize = maxSize;
+
+        if (prepopulate)
+        {
+            // If sentinel objects are supported, populate the queue with them
+            T sentinel = getSentinelObject();
+            if (sentinel != null)
+            {
+                heap[1] = sentinel;
+                for (int i = 2; i < heap.length; i++)
+                {
+                    heap[i] = getSentinelObject();
+                }
+                size = maxSize;
+            }
+        }
+    }
+
+    /** Determines the ordering of objects in this priority queue.  Subclasses
+     *  must define this one method.
+     *  @return <code>true</code> iff parameter <tt>a</tt> is less than parameter <tt>b</tt>.
+     */
+    protected abstract boolean lessThan(T a, T b);
+
+    /**
+     * This method can be overridden by extending classes to return a sentinel
+     * object which will be used by the {@link PriorityQueue#PriorityQueue(int,boolean)} 
+     * constructor to fill the queue, so that the code which uses that queue can always
+     * assume it's full and only change the top without attempting to insert any new
+     * object.<br>
+     * 
+     * Those sentinel values should always compare worse than any non-sentinel
+     * value (i.e., {@link #lessThan} should always favor the
+     * non-sentinel values).<br>
+     * 
+     * By default, this method returns false, which means the queue will not be
+     * filled with sentinel values. Otherwise, the value returned will be used to
+     * pre-populate the queue. Adds sentinel values to the queue.<br>
+     * 
+     * If this method is extended to return a non-null value, then the following
+     * usage pattern is recommended:
+     * 
+     * <pre>
+     * // extends getSentinelObject() to return a non-null value.
+     * PriorityQueue<MyObject> pq = new MyQueue<MyObject>(numHits);
+     * // save the 'top' element, which is guaranteed to not be null.
+     * MyObject pqTop = pq.top();
+     * &lt;...&gt;
+     * // now in order to add a new element, which is 'better' than top (after 
+     * // you've verified it is better), it is as simple as:
+     * pqTop.change().
+     * pqTop = pq.updateTop();
+     * </pre>
+     * 
+     * <b>NOTE:</b> if this method returns a non-null value, it will be called by
+     * the {@link PriorityQueue#PriorityQueue(int,boolean)} constructor 
+     * {@link #size()} times, relying on a new object to be returned and will not
+     * check if it's null again. Therefore you should ensure any call to this
+     * method creates a new instance and behaves consistently, e.g., it cannot
+     * return null if it previously returned non-null.
+     * 
+     * @return the sentinel object to use to pre-populate the queue, or null if
+     *         sentinel objects are not supported.
+     */
+    protected T getSentinelObject()
+    {
+        return null;
+    }
+
+    /**
+     * Adds an Object to a PriorityQueue in log(size) time. If one tries to add
+     * more objects than maxSize from initialize an
+     * {@link ArrayIndexOutOfBoundsException} is thrown.
+     * 
+     * @return the new 'top' element in the queue.
+     */
+    public final T add(T element)
+    {
+        size++;
+        heap[size] = element;
+        upHeap();
+        return heap[1];
+    }
+
+    /**
+     * Adds an Object to a PriorityQueue in log(size) time.
+     * It returns the object (if any) that was
+     * dropped off the heap because it was full. This can be
+     * the given parameter (in case it is smaller than the
+     * full heap's minimum, and couldn't be added), or another
+     * object that was previously the smallest value in the
+     * heap and now has been replaced by a larger one, or null
+     * if the queue wasn't yet full with maxSize elements.
+     */
+    public T insertWithOverflow(T element)
+    {
+        if (size < maxSize)
+        {
+            add(element);
+            return null;
+        }
+        else if (size > 0 && !lessThan(element, heap[1]))
+        {
+            T ret = heap[1];
+            heap[1] = element;
+            updateTop();
+            return ret;
+        }
+        else
+        {
+            return element;
+        }
+    }
+
+    /** Returns the least element of the PriorityQueue in constant time. */
+    public final T top()
+    {
+        // We don't need to check size here: if maxSize is 0,
+        // then heap is length 2 array with both entries null.
+        // If size is 0 then heap[1] is already null.
+        return heap[1];
+    }
+
+    /** Removes and returns the least element of the PriorityQueue in log(size)
+      time. */
+    public final T pop()
+    {
+        if (size > 0)
+        {
+            T result = heap[1]; // save first value
+            heap[1] = heap[size]; // move last to first
+            heap[size] = null; // permit GC of objects
+            size--;
+            downHeap(); // adjust heap
+            return result;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     * Should be called when the Object at top changes values. Still log(n) worst
+     * case, but it's at least twice as fast to
+     * 
+     * <pre>
+     * pq.top().change();
+     * pq.updateTop();
+     * </pre>
+     * 
+     * instead of
+     * 
+     * <pre>
+     * o = pq.pop();
+     * o.change();
+     * pq.push(o);
+     * </pre>
+     * 
+     * @return the new 'top' element.
+     */
+    public final T updateTop()
+    {
+        downHeap();
+        return heap[1];
+    }
+
+    /** Returns the number of elements currently stored in the PriorityQueue. */
+    public final int size()
+    {
+        return size;
+    }
+
+    /** Removes all entries from the PriorityQueue. */
+    public final void clear()
+    {
+        for (int i = 0; i <= size; i++)
+        {
+            heap[i] = null;
+        }
+        size = 0;
+    }
+
+    private final void upHeap()
+    {
+        int i = size;
+        T node = heap[i]; // save bottom node
+        int j = i >>> 1;
+        while (j > 0 && lessThan(node, heap[j]))
+        {
+            heap[i] = heap[j]; // shift parents down
+            i = j;
+            j = j >>> 1;
+        }
+        heap[i] = node; // install saved node
+    }
+
+    private final void downHeap()
+    {
+        int i = 1;
+        T node = heap[i]; // save top node
+        int j = i << 1; // find smaller child
+        int k = j + 1;
+        if (k <= size && lessThan(heap[k], heap[j]))
+        {
+            j = k;
+        }
+        while (j <= size && lessThan(heap[j], node))
+        {
+            heap[i] = heap[j]; // shift up child
+            i = j;
+            j = i << 1;
+            k = j + 1;
+            if (k <= size && lessThan(heap[k], heap[j]))
+            {
+                j = k;
+            }
+        }
+        heap[i] = node; // install saved node
+    }
+
+    /** This method returns the internal heap array as Object[].
+     * @lucene.internal
+     */
+    protected final Object[] getHeapArray()
+    {
+        return (Object[]) heap;
+    }
+}

Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RendererUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RendererUtils.java?rev=1305670&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RendererUtils.java (added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/RendererUtils.java Mon Mar 26 23:34:17 2012
@@ -0,0 +1,69 @@
+/*
+ * 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.myfaces.shared.util;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * 
+ * @author Leonardo Uribe
+ * @since 1.0.1
+ */
+public class RendererUtils
+{
+
+    public static void renderChildren(FacesContext facesContext, UIComponent component)
+            throws IOException
+    {
+        if (component.getChildCount() > 0)
+        {
+            for (Iterator it = component.getChildren().iterator(); it.hasNext(); )
+            {
+                UIComponent child = (UIComponent)it.next();
+                renderChild(facesContext, child);
+            }
+        }
+    }
+
+
+    public static void renderChild(FacesContext facesContext, UIComponent child)
+            throws IOException
+    {
+        if (!child.isRendered())
+        {
+            return;
+        }
+
+        child.encodeBegin(facesContext);
+        if (child.getRendersChildren())
+        {
+            child.encodeChildren(facesContext);
+        }
+        else
+        {
+            renderChildren(facesContext, child);
+        }
+        child.encodeEnd(facesContext);
+    }
+
+}

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java?rev=1305670&r1=1305669&r2=1305670&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/SelectItemsIterator.java Mon Mar 26 23:34:17 2012
@@ -35,8 +35,7 @@ import javax.faces.component.UISelectIte
 import javax.faces.context.FacesContext;
 import javax.faces.model.SelectItem;
 
-import org.apache.myfaces.shared.renderkit.JSFAttr;
-import org.apache.myfaces.shared.renderkit.RendererUtils;
+import org.apache.myfaces.shared.util.renderkit.JsfProperties;
 
 // ATTENTION
 // This class is associated with javax.faces.component._SelectItemsIterator.
@@ -51,13 +50,13 @@ public class SelectItemsIterator impleme
 {
     private static final Logger log = Logger.getLogger(SelectItemsIterator.class.getName());
     
-    private static final String VAR_ATTR = JSFAttr.VAR_ATTR;
-    private static final String ITEM_VALUE_ATTR = JSFAttr.ITEM_VALUE_ATTR;
-    private static final String ITEM_LABEL_ATTR = JSFAttr.ITEM_LABEL_ATTR;
-    private static final String ITEM_DESCRIPTION_ATTR = JSFAttr.ITEM_DESCRIPTION_ATTR;
-    private static final String ITEM_DISABLED_ATTR = JSFAttr.ITEM_DISABLED_ATTR;
-    private static final String ITEM_LABEL_ESCAPED_ATTR = JSFAttr.ITEM_LABEL_ESCAPED_ATTR;
-    private static final String NO_SELECTION_VALUE_ATTR = JSFAttr.NO_SELECTION_VALUE_ATTR;
+    private static final String VAR_PROP = JsfProperties.VAR_PROP;
+    private static final String ITEM_VALUE_PROP = JsfProperties.ITEM_VALUE_PROP;
+    private static final String ITEM_LABEL_PROP = JsfProperties.ITEM_LABEL_PROP;
+    private static final String ITEM_DESCRIPTION_PROP = JsfProperties.ITEM_DESCRIPTION_PROP;
+    private static final String ITEM_DISABLED_PROP = JsfProperties.ITEM_DISABLED_PROP;
+    private static final String ITEM_LABEL_ESCAPED_PROP = JsfProperties.ITEM_LABEL_ESCAPED_PROP;
+    private static final String NO_SELECTION_VALUE_PROP = JsfProperties.NO_SELECTION_VALUE_PROP;
     
     private static final Iterator<UIComponent> _EMPTY_UICOMPONENT_ITERATOR = new _EmptyIterator<UIComponent>();
     
@@ -69,8 +68,9 @@ public class SelectItemsIterator impleme
 
     public SelectItemsIterator(UIComponent selectItemsParent, FacesContext facesContext)
     {
-        _children = selectItemsParent.getChildCount() > 0 ? 
-                selectItemsParent.getChildren().iterator() : _EMPTY_UICOMPONENT_ITERATOR; 
+        _children = selectItemsParent.getChildCount() > 0
+                ? selectItemsParent.getChildren().iterator()
+                : _EMPTY_UICOMPONENT_ITERATOR;
         _facesContext = facesContext;
     }
 
@@ -137,8 +137,8 @@ public class SelectItemsIterator impleme
                     ValueExpression expression = uiSelectItem.getValueExpression("value");
                     throw new IllegalArgumentException("ValueExpression '"
                             + (expression == null ? null : expression.getExpressionString()) + "' of UISelectItem : "
-                            + RendererUtils.getPathToComponent(child) + 
-                            " does not reference an Object of type SelectItem");
+                            + DebugUtils.getPathToComponent(child)
+                            + " does not reference an Object of type SelectItem");
                 }
                 _nextItem = (SelectItem) item;
                 return true;
@@ -200,7 +200,7 @@ public class SelectItemsIterator impleme
                                 + " array, Iterable or Map, but of type: {2}",
                                 new Object[] {
                                     (expression == null ? null : expression.getExpressionString()),
-                                    RendererUtils.getPathToComponent(child),
+                                    DebugUtils.getPathToComponent(child),
                                     (value == null ? null : value.getClass().getName()) 
                                 });
                     }
@@ -236,7 +236,7 @@ public class SelectItemsIterator impleme
                 // write the current item into the request map under the key listed in var, if available
                 boolean wroteRequestMapVarValue = false;
                 Object oldRequestMapVarValue = null;
-                final String var = (String) attributeMap.get(VAR_ATTR);
+                final String var = (String) attributeMap.get(VAR_PROP);
                 if(var != null && !"".equals(var))
                 {
                     // save the current value of the key listed in var from the request map
@@ -245,7 +245,7 @@ public class SelectItemsIterator impleme
                 }
                 
                 // check the itemValue attribute
-                Object itemValue = attributeMap.get(ITEM_VALUE_ATTR);
+                Object itemValue = attributeMap.get(ITEM_VALUE_PROP);
                 if (itemValue == null)
                 {
                     // the itemValue attribute was not provided
@@ -255,7 +255,7 @@ public class SelectItemsIterator impleme
                 
                 // Spec: When iterating over the select items, toString() 
                 // must be called on the string rendered attribute values
-                Object itemLabel = attributeMap.get(ITEM_LABEL_ATTR);
+                Object itemLabel = attributeMap.get(ITEM_LABEL_PROP);
                 if (itemLabel == null)
                 {
                     itemLabel = itemValue.toString();
@@ -264,14 +264,14 @@ public class SelectItemsIterator impleme
                 {
                     itemLabel = itemLabel.toString();
                 }
-                Object itemDescription = attributeMap.get(ITEM_DESCRIPTION_ATTR);
+                Object itemDescription = attributeMap.get(ITEM_DESCRIPTION_PROP);
                 if (itemDescription != null)
                 {
                     itemDescription = itemDescription.toString();
                 }
-                Boolean itemDisabled = getBooleanAttribute(_currentUISelectItems, ITEM_DISABLED_ATTR, false);
-                Boolean itemLabelEscaped = getBooleanAttribute(_currentUISelectItems, ITEM_LABEL_ESCAPED_ATTR, true);
-                Object noSelectionValue = attributeMap.get(NO_SELECTION_VALUE_ATTR);
+                Boolean itemDisabled = getBooleanAttribute(_currentUISelectItems, ITEM_DISABLED_PROP, false);
+                Boolean itemLabelEscaped = getBooleanAttribute(_currentUISelectItems, ITEM_LABEL_ESCAPED_PROP, true);
+                Object noSelectionValue = attributeMap.get(NO_SELECTION_VALUE_PROP);
                 item = new SelectItem(itemValue,
                         (String) itemLabel,
                         (String) itemDescription,

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/StringCharArrayAccessor.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/StringCharArrayAccessor.java?rev=1305670&r1=1305669&r2=1305670&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/StringCharArrayAccessor.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/StringCharArrayAccessor.java Mon Mar 26 23:34:17 2012
@@ -30,8 +30,8 @@ import java.lang.reflect.Field;
  *
  * java.lang.String creation reusing a char[] buffer requires Java 1.5+
  *
- * System property "stringchararrayaccessor.disabled" disables this hack.
- * -Dstringchararrayaccessor.disabled=true
+ * System property "oam.stringchararrayaccessor.enabled" enables this hack.
+ * -Doam.stringchararrayaccessor.enabled=true
  *
  * Read JSR-133, "9.1.1 Post-Construction Modification of Final Fields"
  * http://www.cs.umd.edu/~pugh/java/memoryModel/jsr133.pdf
@@ -44,8 +44,12 @@ import java.lang.reflect.Field;
 public class StringCharArrayAccessor
 {
 
-    static volatile boolean enabled = !Boolean
-            .getBoolean("oam.stringchararrayaccessor.disabled");
+    //static volatile boolean enabled = !Boolean
+    //        .getBoolean("oam.stringchararrayaccessor.disabled");
+    // In Google Application Engine this hack is not valid. We should
+    // set this one as default disabled.
+    static volatile boolean enabled = Boolean
+            .getBoolean("oam.stringchararrayaccessor.enabled");
 
     static Field valueField;
     static Field countField;

Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/TagUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/TagUtils.java?rev=1305670&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/TagUtils.java (added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/TagUtils.java Mon Mar 26 23:34:17 2012
@@ -0,0 +1,407 @@
+/*
+ * 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.myfaces.shared.util;
+
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Locale;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.el.ELContext;
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+/**
+ * Utility class for Tag classes
+ *
+ * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-impl/src/main/java/oracle/adfinternal/view/faces/taglib/util/TagUtils.java#1 $) $Date: 11-nov-2005.14:59:38 $
+ *
+ */
+public final class TagUtils
+{
+  //private static final Log LOG = LogFactory.getLog(TagUtils.class);
+  private static final Logger LOG = Logger.getLogger(TagUtils.class.getName());
+
+  private TagUtils()
+  {
+  }
+
+  public static ValueExpression getValueExpression(String valueExpression, Class<?> expectedType)
+  {
+    FacesContext context = FacesContext.getCurrentInstance();
+    ELContext elContext = context.getELContext();
+    ExpressionFactory fact = context.getApplication().getExpressionFactory();
+    
+    return fact.createValueExpression(elContext, valueExpression, expectedType);
+  }
+
+  public static void assertNotNull(Object object)
+  {
+    if (null == object)
+    {
+      throw new NullPointerException();
+    }
+  }
+
+  // Helpful with tag auto generation. Though this isn't really required.
+  /**
+   * Return the same string. It is there for convenience and makes life easy
+   * while auto generating tags.
+   * @param value
+   * @return
+   */
+  public static String getString(
+    Object value)
+  {
+    if (value == null)
+    {
+        return null;
+    }
+
+    return value.toString();
+  }
+
+  /**
+   * String --> boolean
+   * @param value
+   * @return
+   */
+  public static boolean getBoolean(
+    Object  value)
+  {
+    if (value == null)
+    {
+        return false;
+    }
+    
+    if (value instanceof Boolean)
+    {
+        return ((Boolean) value).booleanValue();
+    }
+
+    return Boolean.valueOf(value.toString()).booleanValue();
+  }
+
+  /**
+   * String --> int
+   * @param value
+   * @return
+   */
+  public static int getInteger(
+    Object  value)
+  {
+    if (value == null)
+    {
+        return 0;
+    }
+
+    if (value instanceof Number)
+    {
+        return ((Number) value).intValue();
+    }
+
+    return Integer.valueOf(value.toString()).intValue();
+
+  }
+
+  /**
+   * String --> long
+   * @param value
+   * @return
+   */
+  public static long getLong(
+    Object      value)
+  {
+    if (value == null)
+    {
+        return 0;
+    }
+
+    return Long.valueOf(value.toString()).longValue();
+  }
+
+  /**
+   * String --> long
+   * @param value
+   * @return
+   */
+  public static double getDouble(
+    Object      value)
+  {
+    if (value == null)
+    {
+        return 0;
+    }
+
+    return Double.valueOf(value.toString()).doubleValue();
+
+  }
+
+  /**
+   * String --> long
+   * @param value
+   * @return
+   */
+  public static float getFloat(
+    Object      value)
+  {
+    if (value == null)
+    {
+        return 0;
+    }
+
+    return Float.valueOf(value.toString()).floatValue();
+  }
+
+  /**
+   * These are normally NMTOKEN type in attributes
+   * String --> String[]
+   * @param value
+   * @return
+   */
+  /**
+   * These are normally NMTOKEN type in attributes
+   * String --> String[]
+   * @param value
+   * @return
+   */
+  public static String[] getStringArray(
+    Object  value) throws ParseException
+  {
+    if (value == null)
+    {
+        return null;
+    }
+
+    return getTokensArray(value.toString());
+  }
+
+  /**
+   *  ISO Date String --> Date
+   * @param value
+   * @return
+   */
+  public static Date getDate(
+    Object   value)
+  {
+    if (value == null)
+    {
+        return null;
+    }
+
+    if (value instanceof Date)
+    {
+        return ((Date) value);
+    }
+
+    return parseISODate(value.toString());
+  }
+
+  /**
+   * String --> Locale
+   * @param value
+   * @return
+   */
+  public static Locale getLocale(
+    Object      value)
+  {
+    if (value == null)
+    {
+        return null;
+    }
+
+    if (value instanceof Locale)
+    {
+        return ((Locale) value);
+    }
+
+    return getLocaleInternal(value.toString());
+  }
+
+  /**
+   * String --> TimeZone
+   * @param value
+   * @return
+
+  public static TimeZone getTimeZone(
+    String value)
+  {
+    return DateUtils.getSupportedTimeZone(value);
+  }
+   */
+
+  public static boolean isValueReference(String expression)
+  {
+    if (null != expression)
+    {
+      int start = expression.indexOf("#{");
+      if ((start >= 0) && (expression.indexOf('}', start + 1) >= 0))
+      {
+          return true;
+      }
+    }
+
+    return false;
+  }
+
+
+
+  /**
+   * Takes a string that is a composite of tokens, extracts tokens delimited
+   *  by any whitespace character sequence combination and returns a String
+   *  array of such tokens.
+   * @throws ParseException In case of invalid character in the specified
+   *           composite. The only invalid character is a comma (',').
+   */
+  private static String[] getTokensArray(String tokenComposite)
+    throws ParseException
+  {
+    if (tokenComposite == null || "".equals(tokenComposite))
+    {
+        return null;
+    }
+
+    return parseNameTokens(tokenComposite);
+  }
+
+  /**
+   * Parse a string into a java.util.Date object.  The
+   * string must be in ISO 9601 format (yyyy-MM-dd).
+   * @todo why not throw the exception in a different format?
+   *       why do we kill it here and return null?
+   */
+  static private final Date parseISODate(String stringValue)
+  {
+    try
+    {
+      return getDateFormat().parse(stringValue);
+    }
+    catch (ParseException pe)
+    {
+      if (LOG.isLoggable(Level.INFO))
+      {
+        LOG.log(Level.INFO, "CANNOT_PARSE_VALUE_INTO_DATE_WITH_YYYY_MM_DD_PATTERN "+ stringValue, pe);
+      }
+      return null;
+    }
+  }
+  
+  /**
+   * Parses a whitespace separated series of name tokens.
+   * @param stringValue the full string
+   * @return an array of each constituent value, or null
+   *  if there are no tokens (that is, the string is empty or
+   *  all whitespace)
+   */
+  static public String[] parseNameTokens(String stringValue)
+  {
+    if (stringValue == null)
+    {
+        return null;
+    }
+
+    ArrayList<String> list = new ArrayList<String>(5);
+
+    int     length = stringValue.length();
+    boolean inSpace = true;
+    int     start = 0;
+    for (int i = 0; i < length; i++)
+    {
+      char ch = stringValue.charAt(i);
+
+      // We're in whitespace;  if we've just departed
+      // a run of non-whitespace, append a string.
+      // Now, why do we use the supposedly deprecated "Character.isSpace()"
+      // function instead of "isWhitespace"?  We're following XML rules
+      // here for the meaning of whitespace, which specifically
+      // EXCLUDES general Unicode spaces.
+      if (Character.isWhitespace(ch))
+      {
+        if (!inSpace)
+        {
+          list.add(stringValue.substring(start, i));
+          inSpace = true;
+        }
+      }
+      // We're out of whitespace;  if we've just departed
+      // a run of whitespace, start keeping track of this string
+      else
+      {
+        if (inSpace)
+        {
+          start = i;
+          inSpace = false;
+        }
+      }
+    }
+
+    if (!inSpace)
+    {
+        list.add(stringValue.substring(start));
+    }
+
+    if (list.isEmpty())
+    {
+        return null;
+    }
+
+    return list.toArray(new String[list.size()]);
+  }
+  
+
+  private static Locale getLocaleInternal(String locale)
+  {
+    String localeStr = locale.replace('-','_');
+    String[] tokens = localeStr.split("[_]", 3);
+    Locale locl = null;
+
+    if ( tokens.length == 1)
+    {
+      locl = new Locale(tokens[0]); //lang
+    }
+    else if (tokens.length == 2)
+    {
+      locl = new Locale(tokens[0], tokens[1]); // lang + country
+    }
+    else if (tokens.length == 3 )
+    {
+      locl = new Locale(tokens[0], tokens[1], tokens[2]); // lang + country + variant
+    }
+    else
+    {
+      if(LOG.isLoggable(Level.WARNING))
+      {
+          LOG.log(Level.WARNING, "tokens length should not be greater than 3.");
+      }
+    }
+    return locl;
+  }
+
+  // We rely strictly on ISO 8601 formats
+  private static DateFormat getDateFormat()
+  {
+    return new SimpleDateFormat("yyyy-MM-dd");
+  }
+}

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/WebConfigParamUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/WebConfigParamUtils.java?rev=1305670&r1=1305669&r2=1305670&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/WebConfigParamUtils.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/util/WebConfigParamUtils.java Mon Mar 26 23:34:17 2012
@@ -25,7 +25,7 @@ import javax.faces.context.ExternalConte
  * Utility class to handle web config parameters
  * 
  * @author Leonardo Uribe
- * @since 4.0.4
+ * @since 2.0.10 (4.0.4 in shared, 1.0.1 in commons)
  */
 public final class WebConfigParamUtils
 {

Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/view/JspViewDeclarationLanguageBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/view/JspViewDeclarationLanguageBase.java?rev=1305670&r1=1305669&r2=1305670&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/view/JspViewDeclarationLanguageBase.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/view/JspViewDeclarationLanguageBase.java Mon Mar 26 23:34:17 2012
@@ -38,12 +38,14 @@ import javax.faces.render.RenderKitFacto
 import javax.faces.view.StateManagementStrategy;
 import javax.faces.view.ViewDeclarationLanguage;
 import javax.faces.view.ViewMetadata;
+import javax.servlet.ServletResponse;
+import javax.servlet.ServletResponseWrapper;
+import javax.servlet.http.HttpServletResponse;
 
 import org.apache.myfaces.shared.application.DefaultViewHandlerSupport;
 import org.apache.myfaces.shared.application.ViewHandlerSupport;
 import org.apache.myfaces.shared.config.MyfacesConfig;
 import org.apache.myfaces.shared.renderkit.html.util.JavascriptUtils;
-import org.apache.myfaces.shared.util.ExternalContextUtils;
 
 
 public abstract class JspViewDeclarationLanguageBase extends ViewDeclarationLanguageBase
@@ -73,11 +75,11 @@ public abstract class JspViewDeclaration
       {
           // try to get (or create) a ResponseSwitch and turn off the output
           Object origResponse = context.getExternalContext().getResponse();
-          ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(origResponse);
+          ResponseSwitch responseSwitch = getResponseSwitch(origResponse);
           if (responseSwitch == null)
           {
               // no ResponseSwitch installed yet - create one 
-              responseSwitch = ExternalContextUtils.createResponseSwitch(origResponse);
+              responseSwitch = createResponseSwitch(origResponse);
               if (responseSwitch != null)
               {
                   // install the ResponseSwitch
@@ -170,7 +172,7 @@ public abstract class JspViewDeclaration
       
       // try to enable the ResponseSwitch again (disabled in buildView())
       Object response = context.getExternalContext().getResponse();
-      ResponseSwitch responseSwitch = ExternalContextUtils.getResponseSwitch(response);
+      ResponseSwitch responseSwitch = getResponseSwitch(response);
       if (responseSwitch != null)
       {
           responseSwitch.setEnabled(true);
@@ -416,6 +418,51 @@ public abstract class JspViewDeclaration
   }
 
   /**
+   * Trys to obtain a ResponseSwitch from the Response.
+   * @param response
+   * @return if found, the ResponseSwitch, null otherwise
+   */
+  private static ResponseSwitch getResponseSwitch(Object response)
+  {
+      // unwrap the response until we find a ResponseSwitch
+      while (response != null)
+      {
+          if (response instanceof ResponseSwitch)
+          {
+              // found
+              return (ResponseSwitch) response;
+          }
+          if (response instanceof ServletResponseWrapper)
+          {
+              // unwrap
+              response = ((ServletResponseWrapper) response).getResponse();
+          }
+          // no more possibilities to find a ResponseSwitch
+          break; 
+      }
+      return null; // not found
+  }
+  
+  /**
+   * Try to create a ResponseSwitch for this response.
+   * @param response
+   * @return the created ResponseSwitch, if there is a ResponseSwitch 
+   *         implementation for the given response, null otherwise
+   */
+  private static ResponseSwitch createResponseSwitch(Object response)
+  {
+      if (response instanceof HttpServletResponse)
+      {
+          return new HttpServletResponseSwitch((HttpServletResponse) response);
+      }
+      else if (response instanceof ServletResponse)
+      {
+          return new ServletResponseSwitch((ServletResponse) response);
+      }
+      return null;
+  }
+
+  /**
    * Writes the response and replaces the state marker tags with the state information for the current context
    */
 /*  private static class StateMarkerAwareWriter extends Writer

Modified: myfaces/shared/trunk/core/src/main/resources/META-INF/myfaces-metadata.xml
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/resources/META-INF/myfaces-metadata.xml?rev=1305670&r1=1305669&r2=1305670&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/resources/META-INF/myfaces-metadata.xml (original)
+++ myfaces/shared/trunk/core/src/main/resources/META-INF/myfaces-metadata.xml Mon Mar 26 23:34:17 2012
@@ -8203,6 +8203,48 @@ HTTP Accept Header.</longDesc>
       <group>render</group>
     </webConfigParam>
     <webConfigParam>
+      <name>org.apache.myfaces.VIEW_UNIQUE_IDS_CACHE_ENABLED</name>
+      <fieldName>INIT_PARAM_VIEW_UNIQUE_IDS_CACHE_ENABLED</fieldName>
+      <desc>Enable or disable a cache used to 'remember'  the generated facelets unique ids " + "and reduce the impact over memory usage.</desc>
+      <longDesc>Enable or disable a cache used to "remember" the generated facelets unique ids and reduce 
+the impact on memory usage, only active if javax.faces.FACELETS_REFRESH_PERIOD is -1 (no refresh).</longDesc>
+      <defaultValue>false</defaultValue>
+      <expectedValues>true, false</expectedValues>
+      <sourceClassName>org.apache.myfaces.shared.config.MyfacesConfig</sourceClassName>
+      <since>2.0.13, 2.1.7</since>
+      <group>viewhandler</group>
+      <tags>performance</tags>
+    </webConfigParam>
+    <webConfigParam>
+      <name>org.apache.myfaces.COMPONENT_UNIQUE_IDS_CACHE_SIZE</name>
+      <fieldName>INIT_PARAM_COMPONENT_UNIQUE_IDS_CACHE_SIZE</fieldName>
+      <desc>Set the size of the cache used to store strings generated using SectionUniqueIdCounter
+for component ids</desc>
+      <longDesc>Set the size of the cache used to store strings generated using SectionUniqueIdCounter
+for component ids. If this is set to 0, no cache is used. By default is set to 100.</longDesc>
+      <defaultValue>100</defaultValue>
+      <sourceClassName>org.apache.myfaces.shared.config.MyfacesConfig</sourceClassName>
+      <since>2.0.13, 2.1.7</since>
+      <group>viewhandler</group>
+      <tags>performance</tags>
+    </webConfigParam>
+    <webConfigParam>
+      <name>org.apache.myfaces.SUPPORT_JSP_AND_FACES_EL</name>
+      <fieldName>INIT_PARAM_SUPPORT_JSP_AND_FACES_EL</fieldName>
+      <desc>If set false, myfaces won't support JSP and javax.faces.el. JSP are deprecated in " + "JSF 2.X, javax.faces.el in in JSF 1.2. Default value is true.</desc>
+      <longDesc>If set false, myfaces won't support JSP and javax.faces.el. JSP are deprecated in JSF 2.X, javax.faces.el in 
+in JSF 1.2. Default value is true. 
+
+If this property is set is false, JSF 1.1 VariableResolver and PropertyResolver config (replaced in JSF 1.2 by
+ELResolver) and all related logic for JSP is skipped, making EL evaluation faster.</longDesc>
+      <defaultValue>true</defaultValue>
+      <expectedValues>true,false</expectedValues>
+      <sourceClassName>org.apache.myfaces.shared.config.MyfacesConfig</sourceClassName>
+      <since>2.0.13,2.1.7</since>
+      <group>EL</group>
+      <tags>performance</tags>
+    </webConfigParam>
+    <webConfigParam>
       <name>org.apache.myfaces.FLASH_SCOPE_DISABLED</name>
       <fieldName>FLASH_SCOPE_DISABLED_PARAM</fieldName>
       <desc>Defines whether flash scope is disabled, preventing add the Flash cookie to the response</desc>