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/11/16 07:01:53 UTC

svn commit: r1410205 [2/2] - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java?rev=1410205&r1=1410204&r2=1410205&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java Fri Nov 16 06:01:51 2012
@@ -25,29 +25,17 @@ import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
-import java.io.Serializable;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-import java.util.Random;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
-import javax.faces.application.ProjectStage;
 
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Hex;
-
-import org.apache.commons.collections.map.AbstractReferenceMap;
-import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.myfaces.application.StateCache;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
 import org.apache.myfaces.shared.renderkit.RendererUtils;
@@ -56,15 +44,15 @@ import org.apache.myfaces.shared.util.We
 
 class ServerSideStateCacheImpl extends StateCache<Object, Object>
 {
-    private static final Logger log = Logger.getLogger(ServerSideStateCacheImpl.class.getName());
+    public static final Logger log = Logger.getLogger(ServerSideStateCacheImpl.class.getName());
     
-    private static final String SERIALIZED_VIEW_SESSION_ATTR= 
+    public static final String SERIALIZED_VIEW_SESSION_ATTR= 
         ServerSideStateCacheImpl.class.getName() + ".SERIALIZED_VIEW";
     
-    private static final String RESTORED_SERIALIZED_VIEW_REQUEST_ATTR = 
+    public static final String RESTORED_SERIALIZED_VIEW_REQUEST_ATTR = 
         ServerSideStateCacheImpl.class.getName() + ".RESTORED_SERIALIZED_VIEW";
 
-    private static final String RESTORED_VIEW_KEY_REQUEST_ATTR = 
+    public static final String RESTORED_VIEW_KEY_REQUEST_ATTR = 
         ServerSideStateCacheImpl.class.getName() + ".RESTORED_VIEW_KEY";
     
     /**
@@ -75,7 +63,7 @@ class ServerSideStateCacheImpl extends S
      * 
      */
     @JSFWebConfigParam(defaultValue="20",since="1.1", classType="java.lang.Integer", group="state", tags="performance")
-    private static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM = "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
+    public static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM = "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
 
     /**
      * Indicates the amount of views (default is not active) that should be stored in session between sequential
@@ -91,13 +79,13 @@ class ServerSideStateCacheImpl extends S
      * the other ones will throw ViewExpiredException.</p>
      */
     @JSFWebConfigParam(since="2.0.6", classType="java.lang.Integer", group="state", tags="performance")
-    private static final String NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM
+    public static final String NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM
             = "org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION";
     
     /**
      * Default value for <code>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</code> context parameter.
      */
-    private static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
+    public static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
 
     /**
      * Indicate if the state should be serialized before save it on the session. 
@@ -108,7 +96,7 @@ class ServerSideStateCacheImpl extends S
      * </p>
      */
     @JSFWebConfigParam(defaultValue="true",since="1.1", expectedValues="true,false", group="state", tags="performance")
-    private static final String SERIALIZE_STATE_IN_SESSION_PARAM = "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
+    public static final String SERIALIZE_STATE_IN_SESSION_PARAM = "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
 
     /**
      * Indicates that the serialized state will be compressed before it is written to the session. By default true.
@@ -119,17 +107,17 @@ class ServerSideStateCacheImpl extends S
      * If <code>false</code> the state will not be compressed.
      */
     @JSFWebConfigParam(defaultValue="true",since="1.1", expectedValues="true,false", group="state", tags="performance")
-    private static final String COMPRESS_SERVER_STATE_PARAM = "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
+    public static final String COMPRESS_SERVER_STATE_PARAM = "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
 
     /**
      * Default value for <code>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</code> context parameter.
      */
-    private static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = true;
+    public static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = true;
 
     /**
      * Default value for <code>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</code> context parameter.
      */
-    private static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = true;
+    public static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = true;
 
     /**
      * Define the way of handle old view references(views removed from session), making possible to
@@ -156,22 +144,22 @@ class ServerSideStateCacheImpl extends S
      */
     @JSFWebConfigParam(defaultValue="off", expectedValues="off, no, hard-soft, soft, soft-weak, weak",
                        since="1.2.5", group="state", tags="performance")
-    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE = "org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE";
+    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE = "org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE";
     
     /**
      * This option uses an hard-soft ReferenceMap, but it could cause a 
      * memory leak, because the keys are not removed by any method
      * (MYFACES-1660). So use with caution.
      */
-    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT = "hard-soft";
+    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT = "hard-soft";
     
-    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT = "soft";
+    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT = "soft";
     
-    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK = "soft-weak";
+    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK = "soft-weak";
     
-    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK = "weak";
+    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK = "weak";
     
-    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF = "off";
+    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF = "off";
 
     /**
      * Allow use flash scope to keep track of the views used in session and the previous ones,
@@ -182,21 +170,21 @@ class ServerSideStateCacheImpl extends S
      * The default value is false.</p>
      */
     @JSFWebConfigParam(since="2.0.6", defaultValue="false", expectedValues="true, false", group="state")
-    private static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
+    public static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
             = "org.apache.myfaces.USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION";
 
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE = "none";
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = "secureRandom";
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM = "random";
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE = "none";
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = "secureRandom";
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM = "random";
     
     /**
      * Adds a random key to the generated view state session token.
      */
     @JSFWebConfigParam(since="2.1.9, 2.0.15", expectedValues="secureRandom, random, none", 
             defaultValue="none", group="state")
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
             = "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN";
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT = 
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT = 
             RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE;
 
     /**
@@ -204,23 +192,23 @@ class ServerSideStateCacheImpl extends S
      * By default is 8. 
      */
     @JSFWebConfigParam(since="2.1.9, 2.0.15", defaultValue="8", group="state")
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM 
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM 
             = "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH";
-    private static final int RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT = 8;
+    public static final int RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT = 8;
 
     /**
      * Sets the random class to initialize the secure random id generator. 
      * By default it uses java.security.SecureRandom
      */
     @JSFWebConfigParam(since="2.1.9, 2.0.15", group="state")
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM
             = "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS";
     
     /**
      * Sets the random provider to initialize the secure random id generator.
      */
     @JSFWebConfigParam(since="2.1.9, 2.0.15", group="state")
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM
             = "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER";
     
     /**
@@ -228,14 +216,14 @@ class ServerSideStateCacheImpl extends S
      * By default is SHA1PRNG
      */
     @JSFWebConfigParam(since="2.1.9, 2.0.15", defaultValue="SHA1PRNG", group="state")
-    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM 
+    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM 
             = "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM";
     
     
-    private static final int UNCOMPRESSED_FLAG = 0;
-    private static final int COMPRESSED_FLAG = 1;
+    public static final int UNCOMPRESSED_FLAG = 0;
+    public static final int COMPRESSED_FLAG = 1;
     
-    private static final Object[] EMPTY_STATES = new Object[]{null, null};
+    public static final Object[] EMPTY_STATES = new Object[]{null, null};
 
     //private static final int JSF_SEQUENCE_INDEX = 0;
     
@@ -589,440 +577,6 @@ class ServerSideStateCacheImpl extends S
         }
     }
     
-    protected static class SerializedViewCollection implements Serializable
-    {
-        private static final long serialVersionUID = -3734849062185115847L;
-
-        private final List<SerializedViewKey> _keys
-                = new ArrayList<SerializedViewKey>(DEFAULT_NUMBER_OF_VIEWS_IN_SESSION);
-        private final Map<SerializedViewKey, Object> _serializedViews = new HashMap<SerializedViewKey, Object>();
-        
-        private final Map<SerializedViewKey, SerializedViewKey> _precedence = 
-            new HashMap<SerializedViewKey, SerializedViewKey>();
-
-        // old views will be hold as soft references which will be removed by
-        // the garbage collector if free memory is low
-        private transient Map<Object, Object> _oldSerializedViews = null;
-
-        public synchronized void add(FacesContext context, Object state, SerializedViewKey key,
-                                     SerializedViewKey previousRestoredKey)
-        {
-            if (state == null)
-            {
-                state = EMPTY_STATES;
-            }
-            else if (state instanceof Object[] &&
-                ((Object[])state).length == 2 &&
-                ((Object[])state)[0] == null &&
-                ((Object[])state)[1] == null)
-            {
-                // The generated state can be considered zero, set it as null
-                // into the map.
-                state = null;
-            }
-            
-            Integer maxCount = getNumberOfSequentialViewsInSession(context);
-            if (maxCount != null)
-            {
-                if (previousRestoredKey != null)
-                {
-                    if (!_serializedViews.isEmpty())
-                    {
-                        _precedence.put((SerializedViewKey) key, previousRestoredKey);
-                    }
-                    else
-                    {
-                        // Note when the session is invalidated, _serializedViews map is empty,
-                        // but we could have a not null previousRestoredKey (the last one before
-                        // invalidate the session), so we need to check that condition before
-                        // set the precence. In that way, we ensure the precedence map will always
-                        // have valid keys.
-                        previousRestoredKey = null;
-                    }
-                }
-            }
-            _serializedViews.put(key, state);
-
-            while (_keys.remove(key))
-            {
-                // do nothing
-            }
-            _keys.add(key);
-
-            if (previousRestoredKey != null && maxCount != null && maxCount > 0)
-            {
-                int count = 0;
-                SerializedViewKey previousKey = (SerializedViewKey) key;
-                do
-                {
-                  previousKey = _precedence.get(previousKey);
-                  count++;
-                } while (previousKey != null && count < maxCount);
-                
-                if (previousKey != null)
-                {
-                    SerializedViewKey keyToRemove = (SerializedViewKey) previousKey;
-                    // In theory it should be only one key but just to be sure
-                    // do it in a loop, but in this case if cache old views is on,
-                    // put on that map.
-                    do
-                    {
-                        while (_keys.remove(keyToRemove))
-                        {
-                            // do nothing
-                        }
-
-                        if (_serializedViews.containsKey(keyToRemove) &&
-                                !CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF.equals(getCacheOldViewsInSessionMode(context)))
-                        {
-                            getOldSerializedViewsMap().put(keyToRemove, _serializedViews.remove(keyToRemove));
-                        }
-                        else
-                        {
-                            _serializedViews.remove(keyToRemove);
-                        }
-                    
-                        keyToRemove = _precedence.remove(keyToRemove);
-                    }  while(keyToRemove != null);
-                }
-            }
-
-            int views = getNumberOfViewsInSession(context);
-            while (_keys.size() > views)
-            {
-                key = _keys.remove(0);
-                
-                if (maxCount != null && maxCount > 0)
-                {
-                    SerializedViewKey keyToRemove = (SerializedViewKey) key;
-                    // Note in this case the key to delete is the oldest one, 
-                    // so it could be at least one precedence, but to be safe
-                    // do it with a loop.
-                    do
-                    {
-                        keyToRemove = _precedence.remove(keyToRemove);
-                    } while (keyToRemove != null);
-                }
-
-                if (_serializedViews.containsKey(key) &&
-                    !CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF.equals(getCacheOldViewsInSessionMode(context)))
-                {
-                    
-                    getOldSerializedViewsMap().put(key, _serializedViews.remove(key));
-                }
-                else
-                {
-                    _serializedViews.remove(key);
-                }
-            }
-        }
-
-        protected Integer getNumberOfSequentialViewsInSession(FacesContext context)
-        {
-            return WebConfigParamUtils.getIntegerInitParameter(context.getExternalContext(), 
-                    NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM);
-        }
-        
-        /**
-         * Reads the amount (default = 20) of views to be stored in session.
-         * @see #NUMBER_OF_VIEWS_IN_SESSION_PARAM
-         * @param context FacesContext for the current request, we are processing
-         * @return Number vf views stored in the session
-         */
-        protected int getNumberOfViewsInSession(FacesContext context)
-        {
-            String value = context.getExternalContext().getInitParameter(
-                    NUMBER_OF_VIEWS_IN_SESSION_PARAM);
-            int views = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
-            if (value != null)
-            {
-                try
-                {
-                    views = Integer.parseInt(value);
-                    if (views <= 0)
-                    {
-                        log.severe("Configured value for " + NUMBER_OF_VIEWS_IN_SESSION_PARAM
-                                  + " is not valid, must be an value > 0, using default value ("
-                                  + DEFAULT_NUMBER_OF_VIEWS_IN_SESSION);
-                        views = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
-                    }
-                }
-                catch (Throwable e)
-                {
-                    log.log(Level.SEVERE, "Error determining the value for " + NUMBER_OF_VIEWS_IN_SESSION_PARAM
-                              + ", expected an integer value > 0, using default value ("
-                              + DEFAULT_NUMBER_OF_VIEWS_IN_SESSION + "): " + e.getMessage(), e);
-                }
-            }
-            return views;
-        }
-
-        /**
-         * @return old serialized views map
-         */
-        @SuppressWarnings("unchecked")
-        protected Map<Object, Object> getOldSerializedViewsMap()
-        {
-            FacesContext context = FacesContext.getCurrentInstance();
-            if (_oldSerializedViews == null && context != null)
-            {
-                String cacheMode = getCacheOldViewsInSessionMode(context); 
-                if (CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK.equals(cacheMode))
-                {
-                    _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true);
-                }
-                else if (CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK.equals(cacheMode))
-                {
-                    _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK, true);
-                }
-                else if (CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT.equals(cacheMode))
-                {
-                    _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT, true);
-                }
-                else if (CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT.equals(cacheMode))
-                {
-                    _oldSerializedViews = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
-                }
-            }
-            
-            return _oldSerializedViews;
-        }
-        
-        /**
-         * Reads the value of the <code>org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE</code> context parameter.
-         * 
-         * @since 1.2.5
-         * @param context
-         * @return constant indicating caching mode
-         * @see #CACHE_OLD_VIEWS_IN_SESSION_MODE
-         */
-        protected String getCacheOldViewsInSessionMode(FacesContext context)
-        {
-            String value = context.getExternalContext().getInitParameter(
-                    CACHE_OLD_VIEWS_IN_SESSION_MODE);
-            if (value == null)
-            {
-                return CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF;
-            }
-            else if (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT))
-            {
-                return CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT;
-            }
-            else if (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK))
-            {
-                return CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK;
-            }            
-            else if (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK))
-            {
-                return CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK;
-            }
-            else if (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT))
-            {
-                return CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT;
-            }
-            else
-            {
-                return CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF;
-            }
-        }
-        
-        public Object get(SerializedViewKey key)
-        {
-            Object value = _serializedViews.get(key);
-            if (value == null)
-            {
-                if (_serializedViews.containsKey(key))
-                {
-                    return EMPTY_STATES;
-                }
-                Map<Object,Object> oldSerializedViewMap = getOldSerializedViewsMap();
-                if (oldSerializedViewMap != null)
-                {
-                    value = oldSerializedViewMap.get(key);
-                    if (value == null && oldSerializedViewMap.containsKey(key) )
-                    {
-                        return EMPTY_STATES;
-                    }
-                }
-            }
-            else if (value instanceof Object[] &&
-                ((Object[])value).length == 2 &&
-                ((Object[])value)[0] == null &&
-                ((Object[])value)[1] == null)
-            {
-                // Remember inside the state map null is stored as an empty array.
-                return null;
-            }
-            return value;
-        }
-    }
-
-    /**
-     * Base implementation where all keys used to identify the state of a view should
-     * extend.
-     */
-    protected abstract static class SerializedViewKey implements Serializable
-    {
-    }
-
-    /**
-     * Implementation of SerializedViewKey, where the hashCode of the viewId is used
-     * and the sequenceId is a numeric value.
-     */
-    private static class IntIntSerializedViewKey extends SerializedViewKey 
-        implements Serializable
-    {
-        private static final long serialVersionUID = -1170697124386063642L;
-        
-        private final int _viewId;
-        private final int _sequenceId;
-        
-        public IntIntSerializedViewKey(int viewId, int sequence)
-        {
-            _sequenceId = sequence;
-            _viewId = viewId;
-        }
-
-        @Override
-        public boolean equals(Object obj)
-        {
-            if (obj == null)
-            {
-                return false;
-            }
-            if (getClass() != obj.getClass())
-            {
-                return false;
-            }
-            final IntIntSerializedViewKey other = (IntIntSerializedViewKey) obj;
-            if (this._viewId != other._viewId)
-            {
-                return false;
-            }
-            if (this._sequenceId != other._sequenceId)
-            {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public int hashCode()
-        {
-            int hash = 7;
-            hash = 83 * hash + this._viewId;
-            hash = 83 * hash + this._sequenceId;
-            return hash;
-        }
-    }
-
-    /**
-     * Implementation of SerializedViewKey, where the hashCode of the viewId is used
-     * and the sequenceId is a string value.
-     */
-    private static class IntByteArraySerializedViewKey extends SerializedViewKey
-        implements Serializable
-    {
-        private final int _viewId;
-        private final byte[] _sequenceId;
-        
-        public IntByteArraySerializedViewKey(int viewId, byte[] sequence)
-        {
-            _sequenceId = sequence;
-            _viewId = viewId;
-        }
-
-        @Override
-        public boolean equals(Object obj)
-        {
-            if (obj == null)
-            {
-                return false;
-            }
-            if (getClass() != obj.getClass())
-            {
-                return false;
-            }
-            final IntByteArraySerializedViewKey other = (IntByteArraySerializedViewKey) obj;
-            if (this._viewId != other._viewId)
-            {
-                return false;
-            }
-            if (!Arrays.equals(this._sequenceId, other._sequenceId))
-            {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public int hashCode()
-        {
-            int hash = 5;
-            hash = 37 * hash + this._viewId;
-            hash = 37 * hash + Arrays.hashCode(this._sequenceId);
-            return hash;
-        }
-    }
-    
-    
-    /**
-     * Implementation of SerializedViewKey, where the viewId and the sequenceId can be
-     * anything.
-     */
-    private static class ReferenceSerializedViewKey<I,K> extends SerializedViewKey
-        implements Serializable
-    {
-        private static final long serialVersionUID = -1170697124386063642L;
-
-        private final I _viewId;
-        private final K _sequenceId;
-
-        public ReferenceSerializedViewKey()
-        {
-            _sequenceId = null;
-            _viewId = null;
-        }
-        public ReferenceSerializedViewKey(I viewId, K sequence)
-        {
-            _sequenceId = sequence;
-            _viewId = viewId;
-        }
-
-        @Override
-        public boolean equals(Object obj)
-        {
-            if (obj == null)
-            {
-                return false;
-            }
-            if (getClass() != obj.getClass())
-            {
-                return false;
-            }
-            final ReferenceSerializedViewKey<I, K> other = (ReferenceSerializedViewKey<I, K>) obj;
-            if (this._viewId != other._viewId && (this._viewId == null || !this._viewId.equals(other._viewId)))
-            {
-                return false;
-            }
-            if (this._sequenceId != other._sequenceId && 
-                (this._sequenceId == null || !this._sequenceId.equals(other._sequenceId)))
-            {
-                return false;
-            }
-            return true;
-        }
-
-        @Override
-        public int hashCode()
-        {
-            int hash = 7;
-            hash = 83 * hash + (this._viewId != null ? this._viewId.hashCode() : 0);
-            hash = 83 * hash + (this._sequenceId != null ? this._sequenceId.hashCode() : 0);
-            return hash;
-        }
-    }
-    
     //------------------------------------- METHOD FROM StateCache ------------------------------------------------
 
     @Override
@@ -1103,349 +657,4 @@ class ServerSideStateCacheImpl extends S
     {
         return sessionViewStorageFactory;
     }
-            
-
-    protected abstract static class KeyFactory<K, V>
-    {
-        
-        /**
-         * Generates a unique key per session 
-         * 
-         * @param facesContext
-         * @return 
-         */
-        public abstract K generateKey(FacesContext facesContext);
-        
-        /**
-         * Encode a Key into a value that will be used as view state session token
-         * 
-         * @param key
-         * @return 
-         */
-        public abstract V encode(K key);
-
-        /**
-         * Decode a view state session token into a key
-         * 
-         * @param value
-         * @return 
-         */
-        public abstract K decode(V value);
-
-    }
-
-    private static class CounterKeyFactory extends KeyFactory<Integer, String>
-    {
-        /**
-         * Take the counter from session scope and increment
-         * 
-         * @param facesContext
-         * @return 
-         */
-        @Override
-        public Integer generateKey(FacesContext facesContext)
-        {
-            ExternalContext externalContext = facesContext.getExternalContext();
-            Object sessionObj = externalContext.getSession(true);
-            Integer sequence = null;
-            synchronized(sessionObj) // synchronized to increase sequence if multiple requests
-                                    // are handled at the same time for the session
-            {
-                Map<String, Object> map = externalContext.getSessionMap();
-                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
-                if(sequence == null || sequence.intValue() == Integer.MAX_VALUE)
-                {
-                    sequence = Integer.valueOf(1);
-                }
-                else
-                {
-                    sequence = Integer.valueOf(sequence.intValue() + 1);
-                }
-                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
-            }
-            return sequence;
-        }
-        
-        public String encode(Integer sequence)
-        {
-            return Integer.toString(sequence, Character.MAX_RADIX);
-        }
-                
-        public Integer decode(String serverStateId)
-        {
-             return Integer.valueOf((String) serverStateId, Character.MAX_RADIX);
-        }
-    }
-    
-    /**
-     * This factory generate a key composed by a counter and a random number. The
-     * counter ensures uniqueness, and the random number prevents guess the next
-     * session token.
-     */
-    private static class SecureRandomKeyFactory extends KeyFactory<byte[], String>
-    {
-        private final SessionIdGenerator sessionIdGenerator;
-        private final int length;
-
-        public SecureRandomKeyFactory(FacesContext facesContext)
-        {
-            length = WebConfigParamUtils.getIntegerInitParameter(facesContext.getExternalContext(),
-                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM, 
-                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT);
-            sessionIdGenerator = new SessionIdGenerator();
-            sessionIdGenerator.setSessionIdLength(length);
-            String secureRandomClass = WebConfigParamUtils.getStringInitParameter(
-                    facesContext.getExternalContext(),
-                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM);
-            if (secureRandomClass != null)
-            {
-                sessionIdGenerator.setSecureRandomClass(secureRandomClass);
-            }
-            String secureRandomProvider = WebConfigParamUtils.getStringInitParameter(
-                    facesContext.getExternalContext(),
-                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM);
-            if (secureRandomProvider != null)
-            {
-                sessionIdGenerator.setSecureRandomProvider(secureRandomProvider);
-            }
-            String secureRandomAlgorithm = WebConfigParamUtils.getStringInitParameter(
-                    facesContext.getExternalContext(), 
-                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM);
-            if (secureRandomAlgorithm != null)
-            {
-                sessionIdGenerator.setSecureRandomAlgorithm(secureRandomAlgorithm);
-            }
-        }
-        
-        public Integer generateCounterKey(FacesContext facesContext)
-        {
-            ExternalContext externalContext = facesContext.getExternalContext();
-            Object sessionObj = externalContext.getSession(true);
-            Integer sequence = null;
-            synchronized(sessionObj) // synchronized to increase sequence if multiple requests
-                                    // are handled at the same time for the session
-            {
-                Map<String, Object> map = externalContext.getSessionMap();
-                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
-                if(sequence == null || sequence.intValue() == Integer.MAX_VALUE)
-                {
-                    sequence = Integer.valueOf(1);
-                }
-                else
-                {
-                    sequence = Integer.valueOf(sequence.intValue() + 1);
-                }
-                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
-            }
-            return sequence;
-        }
-
-        @Override
-        public byte[] generateKey(FacesContext facesContext)
-        {
-            byte[] array = new byte[length];
-            byte[] key = new byte[length+4];
-            
-            sessionIdGenerator.getRandomBytes(array);
-            for (int i = 0; i < array.length; i++)
-            {
-                key[i] = array[i];
-            }
-            int value = generateCounterKey(facesContext);
-            key[array.length] =  (byte) (value >>> 24);
-            key[array.length+1] =  (byte) (value >>> 16);
-            key[array.length+2] =  (byte) (value >>> 8);
-            key[array.length+3] =  (byte) (value);
-            
-            return key;
-        }
-
-        @Override
-        public String encode(byte[] key)
-        {
-            return new String(Hex.encodeHex(key));
-        }
-        
-        @Override
-        public byte[] decode(String value)
-        {
-            try
-            {
-                return Hex.decodeHex(value.toCharArray());
-            }
-            catch (DecoderException ex)
-            {
-                // Cannot decode, ignore silently, later it will be handled as
-                // ViewExpiredException
-            }
-            return null;
-        }
-    }
-    
-    private static class RandomKeyFactory extends KeyFactory<byte[], String>
-    {
-        private final Random random;
-        private final int length;
-        
-        public RandomKeyFactory(FacesContext facesContext)
-        {
-            length = WebConfigParamUtils.getIntegerInitParameter(facesContext.getExternalContext(),
-                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM, 
-                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT);
-            random = new Random(((int)System.nanoTime())+this.hashCode());
-        }
-        
-        public Integer generateCounterKey(FacesContext facesContext)
-        {
-            ExternalContext externalContext = facesContext.getExternalContext();
-            Object sessionObj = externalContext.getSession(true);
-            Integer sequence = null;
-            synchronized(sessionObj) // synchronized to increase sequence if multiple requests
-                                    // are handled at the same time for the session
-            {
-                Map<String, Object> map = externalContext.getSessionMap();
-                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
-                if(sequence == null || sequence.intValue() == Integer.MAX_VALUE)
-                {
-                    sequence = Integer.valueOf(1);
-                }
-                else
-                {
-                    sequence = Integer.valueOf(sequence.intValue() + 1);
-                }
-                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
-            }
-            return sequence;
-        }
-
-        @Override
-        public byte[] generateKey(FacesContext facesContext)
-        {
-            byte[] array = new byte[length];
-            byte[] key = new byte[length+4];
-            
-            //sessionIdGenerator.getRandomBytes(array);
-            random.nextBytes(array);
-            for (int i = 0; i < array.length; i++)
-            {
-                key[i] = array[i];
-            }
-            int value = generateCounterKey(facesContext);
-            key[array.length] =  (byte) (value >>> 24);
-            key[array.length+1] =  (byte) (value >>> 16);
-            key[array.length+2] =  (byte) (value >>> 8);
-            key[array.length+3] =  (byte) (value);
-
-            return key;
-        }
-
-        @Override
-        public String encode(byte[] key)
-        {
-            return new String(Hex.encodeHex(key));
-        }
-        
-        @Override
-        public byte[] decode(String value)
-        {
-            try
-            {
-                return Hex.decodeHex(value.toCharArray());
-            }
-            catch (DecoderException ex)
-            {
-                // Cannot decode, ignore silently, later it will be handled as
-                // ViewExpiredException
-            }
-            return null;
-        }
-    }
-    
-    /**
-     * 
-     * @param <T>
-     * @param <K>
-     * @param <V> 
-     */
-    protected abstract static class SessionViewStorageFactory <T extends KeyFactory<K,V>, K, V >
-    {
-        private KeyFactory<K, V> keyFactory;
-        
-        public SessionViewStorageFactory(KeyFactory<K, V> keyFactory)
-        {
-            this.keyFactory = keyFactory;
-        }
-        
-        public KeyFactory<K, V> getKeyFactory()
-        {
-            return keyFactory;
-        }
-        
-        public abstract SerializedViewCollection createSerializedViewCollection(
-                FacesContext context);
-        
-        public abstract SerializedViewKey createSerializedViewKey(
-                FacesContext facesContext, String viewId, K key);
-        
-    }
-    
-    private static class CounterSessionViewStorageFactory 
-        extends SessionViewStorageFactory <KeyFactory <Integer,String>, Integer, String>
-    {
-        public CounterSessionViewStorageFactory(KeyFactory<Integer, String> keyFactory)
-        {
-            super(keyFactory);
-        }
-
-        @Override
-        public SerializedViewCollection createSerializedViewCollection(
-                FacesContext context)
-        {
-            return new SerializedViewCollection();
-        }
-
-        @Override
-        public SerializedViewKey createSerializedViewKey(
-                FacesContext context, String viewId, Integer key)
-        {
-            if (context.isProjectStage(ProjectStage.Production))
-            {
-                return new IntIntSerializedViewKey(viewId == null ? 0 : viewId.hashCode(), key);
-            }
-            else
-            {
-                return new ReferenceSerializedViewKey(viewId, key);
-            }
-        }
-    }
-    
-    private static class RandomSessionViewStorageFactory
-        extends SessionViewStorageFactory <KeyFactory <byte[],String>, byte[], String>
-    {
-        public RandomSessionViewStorageFactory(KeyFactory<byte[], String> keyFactory)
-        {
-            super(keyFactory);
-        }
-
-        @Override
-        public SerializedViewCollection createSerializedViewCollection(
-                FacesContext context)
-        {
-            return new SerializedViewCollection();
-        }
-
-        @Override
-        public SerializedViewKey createSerializedViewKey(
-                FacesContext context, String viewId, byte[] key)
-        {
-            if (context.isProjectStage(ProjectStage.Production))
-            {
-                return new IntByteArraySerializedViewKey(viewId == null ? 0 : viewId.hashCode(), key);
-            }
-            else
-            {
-                return new ReferenceSerializedViewKey(viewId, key);
-            }
-        }
-    }
 }

Added: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java?rev=1410205&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java (added)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java Fri Nov 16 06:01:51 2012
@@ -0,0 +1,48 @@
+/*
+ * 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.application.viewstate;
+
+import javax.faces.context.FacesContext;
+
+/**
+ *
+ * @param <T>
+ * @param <K>
+ * @param <V>
+ */
+abstract class SessionViewStorageFactory<T extends KeyFactory<K, V>, K, V>
+{
+    private KeyFactory<K, V> keyFactory;
+
+    public SessionViewStorageFactory(KeyFactory<K, V> keyFactory)
+    {
+        this.keyFactory = keyFactory;
+    }
+
+    public KeyFactory<K, V> getKeyFactory()
+    {
+        return keyFactory;
+    }
+
+    public abstract SerializedViewCollection createSerializedViewCollection(FacesContext context);
+
+    public abstract SerializedViewKey createSerializedViewKey(
+        FacesContext facesContext, String viewId, K key);
+    
+}

Propchange: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Re: svn commit: r1410205 [2/2] - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/

Posted by Mark Struberg <st...@yahoo.de>.
It makes it more complicated to maintain and it introduces errors. 

Really, if we decide we switch 2.0.x to maintenance, then we must only backport blockers and security vulnerabilities!

LieGrue,
strub




----- Original Message -----
> From: Leonardo Uribe <lu...@gmail.com>
> To: MyFaces Development <de...@myfaces.apache.org>; Mark Struberg <st...@yahoo.de>
> Cc: 
> Sent: Friday, November 16, 2012 4:06 PM
> Subject: Re: svn commit: r1410205 [2/2] - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/
> 
> 2012/11/16 Mark Struberg <st...@yahoo.de>:
>>  Leo, why do you backport all this stuff to 2.0.x? That makes no sense to 
> me.
>> 
>> 
> 
> Yes, I have to maintain all 4 branches, and it is easier if I backport
> everything to 2.0.x, because if the code has less differences, that
> simplifies maintenance in the long term. Really 2.0.x and 2.1.x are
> very similar.
> 
>> 
>> 
>> 
>>  ----- Original Message -----
>>>  From: "lu4242@apache.org" <lu...@apache.org>
>>>  To: commits@myfaces.apache.org
>>>  Cc:
>>>  Sent: Friday, November 16, 2012 7:01 AM
>>>  Subject: svn commit: r1410205 [2/2] - 
> /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/
>>> 
>>>  Modified:
>>> 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
>>>  URL:
>>> 
> http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java?rev=1410205&r1=1410204&r2=1410205&view=diff
>>> 
> ==============================================================================
>>>  ---
>>> 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
>>>  (original)
>>>  +++
>>> 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
>>>  Fri Nov 16 06:01:51 2012
>>>  @@ -25,29 +25,17 @@ import java.io.InputStream;
>>>  import java.io.ObjectInputStream;
>>>  import java.io.ObjectOutputStream;
>>>  import java.io.OutputStream;
>>>  -import java.io.Serializable;
>>>  import java.security.AccessController;
>>>  import java.security.PrivilegedActionException;
>>>  import java.security.PrivilegedExceptionAction;
>>>  -import java.util.ArrayList;
>>>  -import java.util.Arrays;
>>>  -import java.util.HashMap;
>>>  -import java.util.List;
>>>  import java.util.Map;
>>>  -import java.util.Random;
>>>  import java.util.logging.Level;
>>>  import java.util.logging.Logger;
>>>  import java.util.zip.GZIPInputStream;
>>>  import java.util.zip.GZIPOutputStream;
>>>  -import javax.faces.application.ProjectStage;
>>> 
>>>  import javax.faces.context.ExternalContext;
>>>  import javax.faces.context.FacesContext;
>>>  -import org.apache.commons.codec.DecoderException;
>>>  -import org.apache.commons.codec.binary.Hex;
>>>  -
>>>  -import org.apache.commons.collections.map.AbstractReferenceMap;
>>>  -import org.apache.commons.collections.map.ReferenceMap;
>>>  import org.apache.myfaces.application.StateCache;
>>>  import
>>> 
> org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
>>>  import org.apache.myfaces.shared.renderkit.RendererUtils;
>>>  @@ -56,15 +44,15 @@ import org.apache.myfaces.shared.util.We
>>> 
>>>  class ServerSideStateCacheImpl extends StateCache<Object, Object>
>>>  {
>>>  -    private static final Logger log =
>>>  Logger.getLogger(ServerSideStateCacheImpl.class.getName());
>>>  +    public static final Logger log =
>>>  Logger.getLogger(ServerSideStateCacheImpl.class.getName());
>>> 
>>>  -    private static final String SERIALIZED_VIEW_SESSION_ATTR=
>>>  +    public static final String SERIALIZED_VIEW_SESSION_ATTR=
>>>           ServerSideStateCacheImpl.class.getName() +
>>>  ".SERIALIZED_VIEW";
>>> 
>>>  -    private static final String RESTORED_SERIALIZED_VIEW_REQUEST_ATTR 
> =
>>>  +    public static final String RESTORED_SERIALIZED_VIEW_REQUEST_ATTR =
>>>           ServerSideStateCacheImpl.class.getName() +
>>>  ".RESTORED_SERIALIZED_VIEW";
>>> 
>>>  -    private static final String RESTORED_VIEW_KEY_REQUEST_ATTR =
>>>  +    public static final String RESTORED_VIEW_KEY_REQUEST_ATTR =
>>>           ServerSideStateCacheImpl.class.getName() +
>>>  ".RESTORED_VIEW_KEY";
>>> 
>>>       /**
>>>  @@ -75,7 +63,7 @@ class ServerSideStateCacheImpl extends S
>>>        *
>>>        */
>>>       
> @JSFWebConfigParam(defaultValue="20",since="1.1",
>>>  classType="java.lang.Integer", group="state",
>>>  tags="performance")
>>>  -    private static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM =
>>>  "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
>>>  +    public static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM =
>>>  "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
>>> 
>>>       /**
>>>        * Indicates the amount of views (default is not active) that 
> should be
>>>  stored in session between sequential
>>>  @@ -91,13 +79,13 @@ class ServerSideStateCacheImpl extends S
>>>        * the other ones will throw ViewExpiredException.</p>
>>>        */
>>>       @JSFWebConfigParam(since="2.0.6",
>>>  classType="java.lang.Integer", group="state",
>>>  tags="performance")
>>>  -    private static final String 
> NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM
>>>  +    public static final String 
> NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM
>>>               =
>>>  "org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION";
>>> 
>>>       /**
>>>        * Default value for
>>>  <code>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</code> 
> context
>>>  parameter.
>>>        */
>>>  -    private static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
>>>  +    public static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
>>> 
>>>       /**
>>>        * Indicate if the state should be serialized before save it on 
> the
>>>  session.
>>>  @@ -108,7 +96,7 @@ class ServerSideStateCacheImpl extends S
>>>        * </p>
>>>        */
>>>       
> @JSFWebConfigParam(defaultValue="true",since="1.1",
>>>  expectedValues="true,false", group="state",
>>>  tags="performance")
>>>  -    private static final String SERIALIZE_STATE_IN_SESSION_PARAM =
>>>  "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
>>>  +    public static final String SERIALIZE_STATE_IN_SESSION_PARAM =
>>>  "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
>>> 
>>>       /**
>>>        * Indicates that the serialized state will be compressed before 
> it is
>>>  written to the session. By default true.
>>>  @@ -119,17 +107,17 @@ class ServerSideStateCacheImpl extends S
>>>        * If <code>false</code> the state will not be 
> compressed.
>>>        */
>>>       
> @JSFWebConfigParam(defaultValue="true",since="1.1",
>>>  expectedValues="true,false", group="state",
>>>  tags="performance")
>>>  -    private static final String COMPRESS_SERVER_STATE_PARAM =
>>>  "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
>>>  +    public static final String COMPRESS_SERVER_STATE_PARAM =
>>>  "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
>>> 
>>>       /**
>>>        * Default value for
>>>  <code>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</code> 
> context
>>>  parameter.
>>>        */
>>>  -    private static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = 
> true;
>>>  +    public static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = 
> true;
>>> 
>>>       /**
>>>        * Default value for
>>>  <code>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</code> 
> context
>>>  parameter.
>>>        */
>>>  -    private static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = 
> true;
>>>  +    public static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = 
> true;
>>> 
>>>       /**
>>>        * Define the way of handle old view references(views removed from
>>>  session), making possible to
>>>  @@ -156,22 +144,22 @@ class ServerSideStateCacheImpl extends S
>>>        */
>>>       @JSFWebConfigParam(defaultValue="off", 
> expectedValues="off,
>>>  no, hard-soft, soft, soft-weak, weak",
>>>                          since="1.2.5", 
> group="state",
>>>  tags="performance")
>>>  -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE =
>>>  "org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE";
>>>  +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE =
>>>  "org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE";
>>> 
>>>       /**
>>>        * This option uses an hard-soft ReferenceMap, but it could cause 
> a
>>>        * memory leak, because the keys are not removed by any method
>>>        * (MYFACES-1660). So use with caution.
>>>        */
>>>  -    private static final String 
> CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT =
>>>  "hard-soft";
>>>  +    public static final String 
> CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT =
>>>  "hard-soft";
>>> 
>>>  -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT =
>>>  "soft";
>>>  +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT =
>>>  "soft";
>>> 
>>>  -    private static final String 
> CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK =
>>>  "soft-weak";
>>>  +    public static final String 
> CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK =
>>>  "soft-weak";
>>> 
>>>  -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK =
>>>  "weak";
>>>  +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK =
>>>  "weak";
>>> 
>>>  -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF =
>>>  "off";
>>>  +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF =
>>>  "off";
>>> 
>>>       /**
>>>        * Allow use flash scope to keep track of the views used in 
> session and the
>>>  previous ones,
>>>  @@ -182,21 +170,21 @@ class ServerSideStateCacheImpl extends S
>>>        * The default value is false.</p>
>>>        */
>>>       @JSFWebConfigParam(since="2.0.6", 
> defaultValue="false",
>>>  expectedValues="true, false", group="state")
>>>  -    private static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
>>>  +    public static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
>>>               =
>>>  "org.apache.myfaces.USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION";
>>> 
>>>  -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE =
>>>  "none";
>>>  -    private static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = 
> "secureRandom";
>>>  -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM =
>>>  "random";
>>>  +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE =
>>>  "none";
>>>  +    public static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = 
> "secureRandom";
>>>  +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM =
>>>  "random";
>>> 
>>>       /**
>>>        * Adds a random key to the generated view state session token.
>>>        */
>>>       @JSFWebConfigParam(since="2.1.9, 2.0.15",
>>>  expectedValues="secureRandom, random, none",
>>>               defaultValue="none", group="state")
>>>  -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
>>>  +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
>>>               =
>>>  "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN";
>>>  -    private static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT =
>>>  +    public static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT =
>>>               RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE;
>>> 
>>>       /**
>>>  @@ -204,23 +192,23 @@ class ServerSideStateCacheImpl extends S
>>>        * By default is 8.
>>>        */
>>>       @JSFWebConfigParam(since="2.1.9, 2.0.15",
>>>  defaultValue="8", group="state")
>>>  -    private static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM
>>>  +    public static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM
>>>               =
>>> 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH";
>>>  -    private static final int
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT = 8;
>>>  +    public static final int
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT = 8;
>>> 
>>>       /**
>>>        * Sets the random class to initialize the secure random id 
> generator.
>>>        * By default it uses java.security.SecureRandom
>>>        */
>>>       @JSFWebConfigParam(since="2.1.9, 2.0.15",
>>>  group="state")
>>>  -    private static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM
>>>  +    public static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM
>>>               =
>>> 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS";
>>> 
>>>       /**
>>>        * Sets the random provider to initialize the secure random id 
> generator.
>>>        */
>>>       @JSFWebConfigParam(since="2.1.9, 2.0.15",
>>>  group="state")
>>>  -    private static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM
>>>  +    public static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM
>>>               =
>>> 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER";
>>> 
>>>       /**
>>>  @@ -228,14 +216,14 @@ class ServerSideStateCacheImpl extends S
>>>        * By default is SHA1PRNG
>>>        */
>>>       @JSFWebConfigParam(since="2.1.9, 2.0.15",
>>>  defaultValue="SHA1PRNG", group="state")
>>>  -    private static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM
>>>  +    public static final String
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM
>>>               =
>>> 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM";
>>> 
>>> 
>>>  -    private static final int UNCOMPRESSED_FLAG = 0;
>>>  -    private static final int COMPRESSED_FLAG = 1;
>>>  +    public static final int UNCOMPRESSED_FLAG = 0;
>>>  +    public static final int COMPRESSED_FLAG = 1;
>>> 
>>>  -    private static final Object[] EMPTY_STATES = new Object[]{null, 
> null};
>>>  +    public static final Object[] EMPTY_STATES = new Object[]{null, 
> null};
>>> 
>>>       //private static final int JSF_SEQUENCE_INDEX = 0;
>>> 
>>>  @@ -589,440 +577,6 @@ class ServerSideStateCacheImpl extends S
>>>           }
>>>       }
>>> 
>>>  -    protected static class SerializedViewCollection implements 
> Serializable
>>>  -    {
>>>  -        private static final long serialVersionUID = 
> -3734849062185115847L;
>>>  -
>>>  -        private final List<SerializedViewKey> _keys
>>>  -                = new
>>>  ArrayList<SerializedViewKey>(DEFAULT_NUMBER_OF_VIEWS_IN_SESSION);
>>>  -        private final Map<SerializedViewKey, Object> 
> _serializedViews =
>>>  new HashMap<SerializedViewKey, Object>();
>>>  -
>>>  -        private final Map<SerializedViewKey, SerializedViewKey>
>>>  _precedence =
>>>  -            new HashMap<SerializedViewKey, SerializedViewKey>();
>>>  -
>>>  -        // old views will be hold as soft references which will be 
> removed by
>>>  -        // the garbage collector if free memory is low
>>>  -        private transient Map<Object, Object> 
> _oldSerializedViews = null;
>>>  -
>>>  -        public synchronized void add(FacesContext context, Object 
> state,
>>>  SerializedViewKey key,
>>>  -                                     SerializedViewKey 
> previousRestoredKey)
>>>  -        {
>>>  -            if (state == null)
>>>  -            {
>>>  -                state = EMPTY_STATES;
>>>  -            }
>>>  -            else if (state instanceof Object[] &&
>>>  -                ((Object[])state).length == 2 &&
>>>  -                ((Object[])state)[0] == null &&
>>>  -                ((Object[])state)[1] == null)
>>>  -            {
>>>  -                // The generated state can be considered zero, set it 
> as null
>>>  -                // into the map.
>>>  -                state = null;
>>>  -            }
>>>  -
>>>  -            Integer maxCount = 
> getNumberOfSequentialViewsInSession(context);
>>>  -            if (maxCount != null)
>>>  -            {
>>>  -                if (previousRestoredKey != null)
>>>  -                {
>>>  -                    if (!_serializedViews.isEmpty())
>>>  -                    {
>>>  -                        _precedence.put((SerializedViewKey) key,
>>>  previousRestoredKey);
>>>  -                    }
>>>  -                    else
>>>  -                    {
>>>  -                        // Note when the session is invalidated,
>>>  _serializedViews map is empty,
>>>  -                        // but we could have a not null 
> previousRestoredKey
>>>  (the last one before
>>>  -                        // invalidate the session), so we need to 
> check that
>>>  condition before
>>>  -                        // set the precence. In that way, we ensure 
> the
>>>  precedence map will always
>>>  -                        // have valid keys.
>>>  -                        previousRestoredKey = null;
>>>  -                    }
>>>  -                }
>>>  -            }
>>>  -            _serializedViews.put(key, state);
>>>  -
>>>  -            while (_keys.remove(key))
>>>  -            {
>>>  -                // do nothing
>>>  -            }
>>>  -            _keys.add(key);
>>>  -
>>>  -            if (previousRestoredKey != null && maxCount != 
> null
>>>  && maxCount > 0)
>>>  -            {
>>>  -                int count = 0;
>>>  -                SerializedViewKey previousKey = (SerializedViewKey) 
> key;
>>>  -                do
>>>  -                {
>>>  -                  previousKey = _precedence.get(previousKey);
>>>  -                  count++;
>>>  -                } while (previousKey != null && count < 
> maxCount);
>>>  -
>>>  -                if (previousKey != null)
>>>  -                {
>>>  -                    SerializedViewKey keyToRemove = 
> (SerializedViewKey)
>>>  previousKey;
>>>  -                    // In theory it should be only one key but just to 
> be sure
>>>  -                    // do it in a loop, but in this case if cache old 
> views is
>>>  on,
>>>  -                    // put on that map.
>>>  -                    do
>>>  -                    {
>>>  -                        while (_keys.remove(keyToRemove))
>>>  -                        {
>>>  -                            // do nothing
>>>  -                        }
>>>  -
>>>  -                        if (_serializedViews.containsKey(keyToRemove)
>>>  &&
>>>  -
>>> 
> !CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF.equals(getCacheOldViewsInSessionMode(context)))
>>>  -                        {
>>>  -                            
> getOldSerializedViewsMap().put(keyToRemove,
>>>  _serializedViews.remove(keyToRemove));
>>>  -                        }
>>>  -                        else
>>>  -                        {
>>>  -                            _serializedViews.remove(keyToRemove);
>>>  -                        }
>>>  -
>>>  -                        keyToRemove = _precedence.remove(keyToRemove);
>>>  -                    }  while(keyToRemove != null);
>>>  -                }
>>>  -            }
>>>  -
>>>  -            int views = getNumberOfViewsInSession(context);
>>>  -            while (_keys.size() > views)
>>>  -            {
>>>  -                key = _keys.remove(0);
>>>  -
>>>  -                if (maxCount != null && maxCount > 0)
>>>  -                {
>>>  -                    SerializedViewKey keyToRemove = 
> (SerializedViewKey) key;
>>>  -                    // Note in this case the key to delete is the 
> oldest one,
>>>  -                    // so it could be at least one precedence, but to 
> be safe
>>>  -                    // do it with a loop.
>>>  -                    do
>>>  -                    {
>>>  -                        keyToRemove = _precedence.remove(keyToRemove);
>>>  -                    } while (keyToRemove != null);
>>>  -                }
>>>  -
>>>  -                if (_serializedViews.containsKey(key) &&
>>>  -
>>> 
> !CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF.equals(getCacheOldViewsInSessionMode(context)))
>>>  -                {
>>>  -
>>>  -                    getOldSerializedViewsMap().put(key,
>>>  _serializedViews.remove(key));
>>>  -                }
>>>  -                else
>>>  -                {
>>>  -                    _serializedViews.remove(key);
>>>  -                }
>>>  -            }
>>>  -        }
>>>  -
>>>  -        protected Integer 
> getNumberOfSequentialViewsInSession(FacesContext
>>>  context)
>>>  -        {
>>>  -            return
>>> 
> WebConfigParamUtils.getIntegerInitParameter(context.getExternalContext(),
>>>  -                    NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM);
>>>  -        }
>>>  -
>>>  -        /**
>>>  -         * Reads the amount (default = 20) of views to be stored in 
> session.
>>>  -         * @see #NUMBER_OF_VIEWS_IN_SESSION_PARAM
>>>  -         * @param context FacesContext for the current request, we are
>>>  processing
>>>  -         * @return Number vf views stored in the session
>>>  -         */
>>>  -        protected int getNumberOfViewsInSession(FacesContext context)
>>>  -        {
>>>  -            String value = 
> context.getExternalContext().getInitParameter(
>>>  -                    NUMBER_OF_VIEWS_IN_SESSION_PARAM);
>>>  -            int views = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
>>>  -            if (value != null)
>>>  -            {
>>>  -                try
>>>  -                {
>>>  -                    views = Integer.parseInt(value);
>>>  -                    if (views <= 0)
>>>  -                    {
>>>  -                        log.severe("Configured value for " +
>>>  NUMBER_OF_VIEWS_IN_SESSION_PARAM
>>>  -                                  + " is not valid, must be an 
> value >
>>>  0, using default value ("
>>>  -                                  + 
> DEFAULT_NUMBER_OF_VIEWS_IN_SESSION);
>>>  -                        views = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
>>>  -                    }
>>>  -                }
>>>  -                catch (Throwable e)
>>>  -                {
>>>  -                    log.log(Level.SEVERE, "Error determining the 
> value for
>>>  " + NUMBER_OF_VIEWS_IN_SESSION_PARAM
>>>  -                              + ", expected an integer value > 
> 0, using
>>>  default value ("
>>>  -                              + DEFAULT_NUMBER_OF_VIEWS_IN_SESSION + 
> "):
>>>  " + e.getMessage(), e);
>>>  -                }
>>>  -            }
>>>  -            return views;
>>>  -        }
>>>  -
>>>  -        /**
>>>  -         * @return old serialized views map
>>>  -         */
>>>  -        @SuppressWarnings("unchecked")
>>>  -        protected Map<Object, Object> getOldSerializedViewsMap()
>>>  -        {
>>>  -            FacesContext context = FacesContext.getCurrentInstance();
>>>  -            if (_oldSerializedViews == null && context != 
> null)
>>>  -            {
>>>  -                String cacheMode = 
> getCacheOldViewsInSessionMode(context);
>>>  -                if 
> (CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK.equals(cacheMode))
>>>  -                {
>>>  -                    _oldSerializedViews = new
>>>  ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, 
> true);
>>>  -                }
>>>  -                else if
>>>  (CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK.equals(cacheMode))
>>>  -                {
>>>  -                    _oldSerializedViews = new
>>>  ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK, 
> true);
>>>  -                }
>>>  -                else if
>>>  (CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT.equals(cacheMode))
>>>  -                {
>>>  -                    _oldSerializedViews = new
>>>  ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT, 
> true);
>>>  -                }
>>>  -                else if
>>>  (CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT.equals(cacheMode))
>>>  -                {
>>>  -                    _oldSerializedViews = new
>>>  ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
>>>  -                }
>>>  -            }
>>>  -
>>>  -            return _oldSerializedViews;
>>>  -        }
>>>  -
>>>  -        /**
>>>  -         * Reads the value of the
>>> 
> <code>org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE</code>
>>>  context parameter.
>>>  -         *
>>>  -         * @since 1.2.5
>>>  -         * @param context
>>>  -         * @return constant indicating caching mode
>>>  -         * @see #CACHE_OLD_VIEWS_IN_SESSION_MODE
>>>  -         */
>>>  -        protected String getCacheOldViewsInSessionMode(FacesContext 
> context)
>>>  -        {
>>>  -            String value = 
> context.getExternalContext().getInitParameter(
>>>  -                    CACHE_OLD_VIEWS_IN_SESSION_MODE);
>>>  -            if (value == null)
>>>  -            {
>>>  -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF;
>>>  -            }
>>>  -            else if
>>>  (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT))
>>>  -            {
>>>  -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT;
>>>  -            }
>>>  -            else if
>>>  (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK))
>>>  -            {
>>>  -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK;
>>>  -            }
>>>  -            else if
>>>  (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK))
>>>  -            {
>>>  -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK;
>>>  -            }
>>>  -            else if
>>>  (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT))
>>>  -            {
>>>  -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT;
>>>  -            }
>>>  -            else
>>>  -            {
>>>  -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF;
>>>  -            }
>>>  -        }
>>>  -
>>>  -        public Object get(SerializedViewKey key)
>>>  -        {
>>>  -            Object value = _serializedViews.get(key);
>>>  -            if (value == null)
>>>  -            {
>>>  -                if (_serializedViews.containsKey(key))
>>>  -                {
>>>  -                    return EMPTY_STATES;
>>>  -                }
>>>  -                Map<Object,Object> oldSerializedViewMap =
>>>  getOldSerializedViewsMap();
>>>  -                if (oldSerializedViewMap != null)
>>>  -                {
>>>  -                    value = oldSerializedViewMap.get(key);
>>>  -                    if (value == null &&
>>>  oldSerializedViewMap.containsKey(key) )
>>>  -                    {
>>>  -                        return EMPTY_STATES;
>>>  -                    }
>>>  -                }
>>>  -            }
>>>  -            else if (value instanceof Object[] &&
>>>  -                ((Object[])value).length == 2 &&
>>>  -                ((Object[])value)[0] == null &&
>>>  -                ((Object[])value)[1] == null)
>>>  -            {
>>>  -                // Remember inside the state map null is stored as an 
> empty
>>>  array.
>>>  -                return null;
>>>  -            }
>>>  -            return value;
>>>  -        }
>>>  -    }
>>>  -
>>>  -    /**
>>>  -     * Base implementation where all keys used to identify the state 
> of a view
>>>  should
>>>  -     * extend.
>>>  -     */
>>>  -    protected abstract static class SerializedViewKey implements 
> Serializable
>>>  -    {
>>>  -    }
>>>  -
>>>  -    /**
>>>  -     * Implementation of SerializedViewKey, where the hashCode of the 
> viewId is
>>>  used
>>>  -     * and the sequenceId is a numeric value.
>>>  -     */
>>>  -    private static class IntIntSerializedViewKey extends 
> SerializedViewKey
>>>  -        implements Serializable
>>>  -    {
>>>  -        private static final long serialVersionUID = 
> -1170697124386063642L;
>>>  -
>>>  -        private final int _viewId;
>>>  -        private final int _sequenceId;
>>>  -
>>>  -        public IntIntSerializedViewKey(int viewId, int sequence)
>>>  -        {
>>>  -            _sequenceId = sequence;
>>>  -            _viewId = viewId;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public boolean equals(Object obj)
>>>  -        {
>>>  -            if (obj == null)
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            if (getClass() != obj.getClass())
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            final IntIntSerializedViewKey other = 
> (IntIntSerializedViewKey)
>>>  obj;
>>>  -            if (this._viewId != other._viewId)
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            if (this._sequenceId != other._sequenceId)
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            return true;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public int hashCode()
>>>  -        {
>>>  -            int hash = 7;
>>>  -            hash = 83 * hash + this._viewId;
>>>  -            hash = 83 * hash + this._sequenceId;
>>>  -            return hash;
>>>  -        }
>>>  -    }
>>>  -
>>>  -    /**
>>>  -     * Implementation of SerializedViewKey, where the hashCode of the 
> viewId is
>>>  used
>>>  -     * and the sequenceId is a string value.
>>>  -     */
>>>  -    private static class IntByteArraySerializedViewKey extends
>>>  SerializedViewKey
>>>  -        implements Serializable
>>>  -    {
>>>  -        private final int _viewId;
>>>  -        private final byte[] _sequenceId;
>>>  -
>>>  -        public IntByteArraySerializedViewKey(int viewId, byte[] 
> sequence)
>>>  -        {
>>>  -            _sequenceId = sequence;
>>>  -            _viewId = viewId;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public boolean equals(Object obj)
>>>  -        {
>>>  -            if (obj == null)
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            if (getClass() != obj.getClass())
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            final IntByteArraySerializedViewKey other =
>>>  (IntByteArraySerializedViewKey) obj;
>>>  -            if (this._viewId != other._viewId)
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            if (!Arrays.equals(this._sequenceId, other._sequenceId))
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            return true;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public int hashCode()
>>>  -        {
>>>  -            int hash = 5;
>>>  -            hash = 37 * hash + this._viewId;
>>>  -            hash = 37 * hash + Arrays.hashCode(this._sequenceId);
>>>  -            return hash;
>>>  -        }
>>>  -    }
>>>  -
>>>  -
>>>  -    /**
>>>  -     * Implementation of SerializedViewKey, where the viewId and the 
> sequenceId
>>>  can be
>>>  -     * anything.
>>>  -     */
>>>  -    private static class ReferenceSerializedViewKey<I,K> extends
>>>  SerializedViewKey
>>>  -        implements Serializable
>>>  -    {
>>>  -        private static final long serialVersionUID = 
> -1170697124386063642L;
>>>  -
>>>  -        private final I _viewId;
>>>  -        private final K _sequenceId;
>>>  -
>>>  -        public ReferenceSerializedViewKey()
>>>  -        {
>>>  -            _sequenceId = null;
>>>  -            _viewId = null;
>>>  -        }
>>>  -        public ReferenceSerializedViewKey(I viewId, K sequence)
>>>  -        {
>>>  -            _sequenceId = sequence;
>>>  -            _viewId = viewId;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public boolean equals(Object obj)
>>>  -        {
>>>  -            if (obj == null)
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            if (getClass() != obj.getClass())
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            final ReferenceSerializedViewKey<I, K> other =
>>>  (ReferenceSerializedViewKey<I, K>) obj;
>>>  -            if (this._viewId != other._viewId && (this._viewId 
> == null
>>>  || !this._viewId.equals(other._viewId)))
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            if (this._sequenceId != other._sequenceId &&
>>>  -                (this._sequenceId == null ||
>>>  !this._sequenceId.equals(other._sequenceId)))
>>>  -            {
>>>  -                return false;
>>>  -            }
>>>  -            return true;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public int hashCode()
>>>  -        {
>>>  -            int hash = 7;
>>>  -            hash = 83 * hash + (this._viewId != null ? 
> this._viewId.hashCode()
>>>  : 0);
>>>  -            hash = 83 * hash + (this._sequenceId != null ?
>>>  this._sequenceId.hashCode() : 0);
>>>  -            return hash;
>>>  -        }
>>>  -    }
>>>  -
>>>       //------------------------------------- METHOD FROM StateCache
>>>  ------------------------------------------------
>>> 
>>>       @Override
>>>  @@ -1103,349 +657,4 @@ class ServerSideStateCacheImpl extends S
>>>       {
>>>           return sessionViewStorageFactory;
>>>       }
>>>  -
>>>  -
>>>  -    protected abstract static class KeyFactory<K, V>
>>>  -    {
>>>  -
>>>  -        /**
>>>  -         * Generates a unique key per session
>>>  -         *
>>>  -         * @param facesContext
>>>  -         * @return
>>>  -         */
>>>  -        public abstract K generateKey(FacesContext facesContext);
>>>  -
>>>  -        /**
>>>  -         * Encode a Key into a value that will be used as view state 
> session
>>>  token
>>>  -         *
>>>  -         * @param key
>>>  -         * @return
>>>  -         */
>>>  -        public abstract V encode(K key);
>>>  -
>>>  -        /**
>>>  -         * Decode a view state session token into a key
>>>  -         *
>>>  -         * @param value
>>>  -         * @return
>>>  -         */
>>>  -        public abstract K decode(V value);
>>>  -
>>>  -    }
>>>  -
>>>  -    private static class CounterKeyFactory extends 
> KeyFactory<Integer,
>>>  String>
>>>  -    {
>>>  -        /**
>>>  -         * Take the counter from session scope and increment
>>>  -         *
>>>  -         * @param facesContext
>>>  -         * @return
>>>  -         */
>>>  -        @Override
>>>  -        public Integer generateKey(FacesContext facesContext)
>>>  -        {
>>>  -            ExternalContext externalContext =
>>>  facesContext.getExternalContext();
>>>  -            Object sessionObj = externalContext.getSession(true);
>>>  -            Integer sequence = null;
>>>  -            synchronized(sessionObj) // synchronized to increase 
> sequence if
>>>  multiple requests
>>>  -                                    // are handled at the same time 
> for the
>>>  session
>>>  -            {
>>>  -                Map<String, Object> map =
>>>  externalContext.getSessionMap();
>>>  -                sequence = (Integer) 
> map.get(RendererUtils.SEQUENCE_PARAM);
>>>  -                if(sequence == null || sequence.intValue() ==
>>>  Integer.MAX_VALUE)
>>>  -                {
>>>  -                    sequence = Integer.valueOf(1);
>>>  -                }
>>>  -                else
>>>  -                {
>>>  -                    sequence = Integer.valueOf(sequence.intValue() + 
> 1);
>>>  -                }
>>>  -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
>>>  -            }
>>>  -            return sequence;
>>>  -        }
>>>  -
>>>  -        public String encode(Integer sequence)
>>>  -        {
>>>  -            return Integer.toString(sequence, Character.MAX_RADIX);
>>>  -        }
>>>  -
>>>  -        public Integer decode(String serverStateId)
>>>  -        {
>>>  -             return Integer.valueOf((String) serverStateId,
>>>  Character.MAX_RADIX);
>>>  -        }
>>>  -    }
>>>  -
>>>  -    /**
>>>  -     * This factory generate a key composed by a counter and a random 
> number.
>>>  The
>>>  -     * counter ensures uniqueness, and the random number prevents 
> guess the
>>>  next
>>>  -     * session token.
>>>  -     */
>>>  -    private static class SecureRandomKeyFactory extends 
> KeyFactory<byte[],
>>>  String>
>>>  -    {
>>>  -        private final SessionIdGenerator sessionIdGenerator;
>>>  -        private final int length;
>>>  -
>>>  -        public SecureRandomKeyFactory(FacesContext facesContext)
>>>  -        {
>>>  -            length =
>>> 
> WebConfigParamUtils.getIntegerInitParameter(facesContext.getExternalContext(),
>>>  -                    
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM,
>>>  -
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT);
>>>  -            sessionIdGenerator = new SessionIdGenerator();
>>>  -            sessionIdGenerator.setSessionIdLength(length);
>>>  -            String secureRandomClass =
>>>  WebConfigParamUtils.getStringInitParameter(
>>>  -                    facesContext.getExternalContext(),
>>>  -
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM);
>>>  -            if (secureRandomClass != null)
>>>  -            {
>>>  -                
> sessionIdGenerator.setSecureRandomClass(secureRandomClass);
>>>  -            }
>>>  -            String secureRandomProvider =
>>>  WebConfigParamUtils.getStringInitParameter(
>>>  -                    facesContext.getExternalContext(),
>>>  -
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM);
>>>  -            if (secureRandomProvider != null)
>>>  -            {
>>>  -
>>>  sessionIdGenerator.setSecureRandomProvider(secureRandomProvider);
>>>  -            }
>>>  -            String secureRandomAlgorithm =
>>>  WebConfigParamUtils.getStringInitParameter(
>>>  -                    facesContext.getExternalContext(),
>>>  -
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM);
>>>  -            if (secureRandomAlgorithm != null)
>>>  -            {
>>>  -
>>>  sessionIdGenerator.setSecureRandomAlgorithm(secureRandomAlgorithm);
>>>  -            }
>>>  -        }
>>>  -
>>>  -        public Integer generateCounterKey(FacesContext facesContext)
>>>  -        {
>>>  -            ExternalContext externalContext =
>>>  facesContext.getExternalContext();
>>>  -            Object sessionObj = externalContext.getSession(true);
>>>  -            Integer sequence = null;
>>>  -            synchronized(sessionObj) // synchronized to increase 
> sequence if
>>>  multiple requests
>>>  -                                    // are handled at the same time 
> for the
>>>  session
>>>  -            {
>>>  -                Map<String, Object> map =
>>>  externalContext.getSessionMap();
>>>  -                sequence = (Integer) 
> map.get(RendererUtils.SEQUENCE_PARAM);
>>>  -                if(sequence == null || sequence.intValue() ==
>>>  Integer.MAX_VALUE)
>>>  -                {
>>>  -                    sequence = Integer.valueOf(1);
>>>  -                }
>>>  -                else
>>>  -                {
>>>  -                    sequence = Integer.valueOf(sequence.intValue() + 
> 1);
>>>  -                }
>>>  -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
>>>  -            }
>>>  -            return sequence;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public byte[] generateKey(FacesContext facesContext)
>>>  -        {
>>>  -            byte[] array = new byte[length];
>>>  -            byte[] key = new byte[length+4];
>>>  -
>>>  -            sessionIdGenerator.getRandomBytes(array);
>>>  -            for (int i = 0; i < array.length; i++)
>>>  -            {
>>>  -                key[i] = array[i];
>>>  -            }
>>>  -            int value = generateCounterKey(facesContext);
>>>  -            key[array.length] =  (byte) (value >>> 24);
>>>  -            key[array.length+1] =  (byte) (value >>> 16);
>>>  -            key[array.length+2] =  (byte) (value >>> 8);
>>>  -            key[array.length+3] =  (byte) (value);
>>>  -
>>>  -            return key;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public String encode(byte[] key)
>>>  -        {
>>>  -            return new String(Hex.encodeHex(key));
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public byte[] decode(String value)
>>>  -        {
>>>  -            try
>>>  -            {
>>>  -                return Hex.decodeHex(value.toCharArray());
>>>  -            }
>>>  -            catch (DecoderException ex)
>>>  -            {
>>>  -                // Cannot decode, ignore silently, later it will be 
> handled as
>>>  -                // ViewExpiredException
>>>  -            }
>>>  -            return null;
>>>  -        }
>>>  -    }
>>>  -
>>>  -    private static class RandomKeyFactory extends 
> KeyFactory<byte[],
>>>  String>
>>>  -    {
>>>  -        private final Random random;
>>>  -        private final int length;
>>>  -
>>>  -        public RandomKeyFactory(FacesContext facesContext)
>>>  -        {
>>>  -            length =
>>> 
> WebConfigParamUtils.getIntegerInitParameter(facesContext.getExternalContext(),
>>>  -                    
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM,
>>>  -
>>>  RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT);
>>>  -            random = new 
> Random(((int)System.nanoTime())+this.hashCode());
>>>  -        }
>>>  -
>>>  -        public Integer generateCounterKey(FacesContext facesContext)
>>>  -        {
>>>  -            ExternalContext externalContext =
>>>  facesContext.getExternalContext();
>>>  -            Object sessionObj = externalContext.getSession(true);
>>>  -            Integer sequence = null;
>>>  -            synchronized(sessionObj) // synchronized to increase 
> sequence if
>>>  multiple requests
>>>  -                                    // are handled at the same time 
> for the
>>>  session
>>>  -            {
>>>  -                Map<String, Object> map =
>>>  externalContext.getSessionMap();
>>>  -                sequence = (Integer) 
> map.get(RendererUtils.SEQUENCE_PARAM);
>>>  -                if(sequence == null || sequence.intValue() ==
>>>  Integer.MAX_VALUE)
>>>  -                {
>>>  -                    sequence = Integer.valueOf(1);
>>>  -                }
>>>  -                else
>>>  -                {
>>>  -                    sequence = Integer.valueOf(sequence.intValue() + 
> 1);
>>>  -                }
>>>  -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
>>>  -            }
>>>  -            return sequence;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public byte[] generateKey(FacesContext facesContext)
>>>  -        {
>>>  -            byte[] array = new byte[length];
>>>  -            byte[] key = new byte[length+4];
>>>  -
>>>  -            //sessionIdGenerator.getRandomBytes(array);
>>>  -            random.nextBytes(array);
>>>  -            for (int i = 0; i < array.length; i++)
>>>  -            {
>>>  -                key[i] = array[i];
>>>  -            }
>>>  -            int value = generateCounterKey(facesContext);
>>>  -            key[array.length] =  (byte) (value >>> 24);
>>>  -            key[array.length+1] =  (byte) (value >>> 16);
>>>  -            key[array.length+2] =  (byte) (value >>> 8);
>>>  -            key[array.length+3] =  (byte) (value);
>>>  -
>>>  -            return key;
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public String encode(byte[] key)
>>>  -        {
>>>  -            return new String(Hex.encodeHex(key));
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public byte[] decode(String value)
>>>  -        {
>>>  -            try
>>>  -            {
>>>  -                return Hex.decodeHex(value.toCharArray());
>>>  -            }
>>>  -            catch (DecoderException ex)
>>>  -            {
>>>  -                // Cannot decode, ignore silently, later it will be 
> handled as
>>>  -                // ViewExpiredException
>>>  -            }
>>>  -            return null;
>>>  -        }
>>>  -    }
>>>  -
>>>  -    /**
>>>  -     *
>>>  -     * @param <T>
>>>  -     * @param <K>
>>>  -     * @param <V>
>>>  -     */
>>>  -    protected abstract static class SessionViewStorageFactory <T 
> extends
>>>  KeyFactory<K,V>, K, V >
>>>  -    {
>>>  -        private KeyFactory<K, V> keyFactory;
>>>  -
>>>  -        public SessionViewStorageFactory(KeyFactory<K, V> 
> keyFactory)
>>>  -        {
>>>  -            this.keyFactory = keyFactory;
>>>  -        }
>>>  -
>>>  -        public KeyFactory<K, V> getKeyFactory()
>>>  -        {
>>>  -            return keyFactory;
>>>  -        }
>>>  -
>>>  -        public abstract SerializedViewCollection
>>>  createSerializedViewCollection(
>>>  -                FacesContext context);
>>>  -
>>>  -        public abstract SerializedViewKey createSerializedViewKey(
>>>  -                FacesContext facesContext, String viewId, K key);
>>>  -
>>>  -    }
>>>  -
>>>  -    private static class CounterSessionViewStorageFactory
>>>  -        extends SessionViewStorageFactory <KeyFactory
>>>  <Integer,String>, Integer, String>
>>>  -    {
>>>  -        public CounterSessionViewStorageFactory(KeyFactory<Integer,
>>>  String> keyFactory)
>>>  -        {
>>>  -            super(keyFactory);
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public SerializedViewCollection 
> createSerializedViewCollection(
>>>  -                FacesContext context)
>>>  -        {
>>>  -            return new SerializedViewCollection();
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public SerializedViewKey createSerializedViewKey(
>>>  -                FacesContext context, String viewId, Integer key)
>>>  -        {
>>>  -            if (context.isProjectStage(ProjectStage.Production))
>>>  -            {
>>>  -                return new IntIntSerializedViewKey(viewId == null ? 0 
> :
>>>  viewId.hashCode(), key);
>>>  -            }
>>>  -            else
>>>  -            {
>>>  -                return new ReferenceSerializedViewKey(viewId, key);
>>>  -            }
>>>  -        }
>>>  -    }
>>>  -
>>>  -    private static class RandomSessionViewStorageFactory
>>>  -        extends SessionViewStorageFactory <KeyFactory 
> <byte[],String>,
>>>  byte[], String>
>>>  -    {
>>>  -        public RandomSessionViewStorageFactory(KeyFactory<byte[], 
> String>
>>>  keyFactory)
>>>  -        {
>>>  -            super(keyFactory);
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public SerializedViewCollection 
> createSerializedViewCollection(
>>>  -                FacesContext context)
>>>  -        {
>>>  -            return new SerializedViewCollection();
>>>  -        }
>>>  -
>>>  -        @Override
>>>  -        public SerializedViewKey createSerializedViewKey(
>>>  -                FacesContext context, String viewId, byte[] key)
>>>  -        {
>>>  -            if (context.isProjectStage(ProjectStage.Production))
>>>  -            {
>>>  -                return new IntByteArraySerializedViewKey(viewId == 
> null ? 0 :
>>>  viewId.hashCode(), key);
>>>  -            }
>>>  -            else
>>>  -            {
>>>  -                return new ReferenceSerializedViewKey(viewId, key);
>>>  -            }
>>>  -        }
>>>  -    }
>>>  }
>>> 
>>>  Added:
>>> 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
>>>  URL:
>>> 
> http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java?rev=1410205&view=auto
>>> 
> ==============================================================================
>>>  ---
>>> 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
>>>  (added)
>>>  +++
>>> 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
>>>  Fri Nov 16 06:01:51 2012
>>>  @@ -0,0 +1,48 @@
>>>  +/*
>>>  + * 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.application.viewstate;
>>>  +
>>>  +import javax.faces.context.FacesContext;
>>>  +
>>>  +/**
>>>  + *
>>>  + * @param <T>
>>>  + * @param <K>
>>>  + * @param <V>
>>>  + */
>>>  +abstract class SessionViewStorageFactory<T extends KeyFactory<K, 
> V>,
>>>  K, V>
>>>  +{
>>>  +    private KeyFactory<K, V> keyFactory;
>>>  +
>>>  +    public SessionViewStorageFactory(KeyFactory<K, V> 
> keyFactory)
>>>  +    {
>>>  +        this.keyFactory = keyFactory;
>>>  +    }
>>>  +
>>>  +    public KeyFactory<K, V> getKeyFactory()
>>>  +    {
>>>  +        return keyFactory;
>>>  +    }
>>>  +
>>>  +    public abstract SerializedViewCollection
>>>  createSerializedViewCollection(FacesContext context);
>>>  +
>>>  +    public abstract SerializedViewKey createSerializedViewKey(
>>>  +        FacesContext facesContext, String viewId, K key);
>>>  +
>>>  +}
>>> 
>>>  Propchange:
>>> 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
>>> 
> ------------------------------------------------------------------------------
>>>      svn:eol-style = native
>>> 
> 

Re: svn commit: r1410205 [2/2] - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/

Posted by Leonardo Uribe <lu...@gmail.com>.
2012/11/16 Mark Struberg <st...@yahoo.de>:
> Leo, why do you backport all this stuff to 2.0.x? That makes no sense to me.
>
>

Yes, I have to maintain all 4 branches, and it is easier if I backport
everything to 2.0.x, because if the code has less differences, that
simplifies maintenance in the long term. Really 2.0.x and 2.1.x are
very similar.

>
>
>
> ----- Original Message -----
>> From: "lu4242@apache.org" <lu...@apache.org>
>> To: commits@myfaces.apache.org
>> Cc:
>> Sent: Friday, November 16, 2012 7:01 AM
>> Subject: svn commit: r1410205 [2/2] - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/
>>
>> Modified:
>> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
>> URL:
>> http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java?rev=1410205&r1=1410204&r2=1410205&view=diff
>> ==============================================================================
>> ---
>> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
>> (original)
>> +++
>> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
>> Fri Nov 16 06:01:51 2012
>> @@ -25,29 +25,17 @@ import java.io.InputStream;
>> import java.io.ObjectInputStream;
>> import java.io.ObjectOutputStream;
>> import java.io.OutputStream;
>> -import java.io.Serializable;
>> import java.security.AccessController;
>> import java.security.PrivilegedActionException;
>> import java.security.PrivilegedExceptionAction;
>> -import java.util.ArrayList;
>> -import java.util.Arrays;
>> -import java.util.HashMap;
>> -import java.util.List;
>> import java.util.Map;
>> -import java.util.Random;
>> import java.util.logging.Level;
>> import java.util.logging.Logger;
>> import java.util.zip.GZIPInputStream;
>> import java.util.zip.GZIPOutputStream;
>> -import javax.faces.application.ProjectStage;
>>
>> import javax.faces.context.ExternalContext;
>> import javax.faces.context.FacesContext;
>> -import org.apache.commons.codec.DecoderException;
>> -import org.apache.commons.codec.binary.Hex;
>> -
>> -import org.apache.commons.collections.map.AbstractReferenceMap;
>> -import org.apache.commons.collections.map.ReferenceMap;
>> import org.apache.myfaces.application.StateCache;
>> import
>> org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
>> import org.apache.myfaces.shared.renderkit.RendererUtils;
>> @@ -56,15 +44,15 @@ import org.apache.myfaces.shared.util.We
>>
>> class ServerSideStateCacheImpl extends StateCache<Object, Object>
>> {
>> -    private static final Logger log =
>> Logger.getLogger(ServerSideStateCacheImpl.class.getName());
>> +    public static final Logger log =
>> Logger.getLogger(ServerSideStateCacheImpl.class.getName());
>>
>> -    private static final String SERIALIZED_VIEW_SESSION_ATTR=
>> +    public static final String SERIALIZED_VIEW_SESSION_ATTR=
>>          ServerSideStateCacheImpl.class.getName() +
>> ".SERIALIZED_VIEW";
>>
>> -    private static final String RESTORED_SERIALIZED_VIEW_REQUEST_ATTR =
>> +    public static final String RESTORED_SERIALIZED_VIEW_REQUEST_ATTR =
>>          ServerSideStateCacheImpl.class.getName() +
>> ".RESTORED_SERIALIZED_VIEW";
>>
>> -    private static final String RESTORED_VIEW_KEY_REQUEST_ATTR =
>> +    public static final String RESTORED_VIEW_KEY_REQUEST_ATTR =
>>          ServerSideStateCacheImpl.class.getName() +
>> ".RESTORED_VIEW_KEY";
>>
>>      /**
>> @@ -75,7 +63,7 @@ class ServerSideStateCacheImpl extends S
>>       *
>>       */
>>      @JSFWebConfigParam(defaultValue="20",since="1.1",
>> classType="java.lang.Integer", group="state",
>> tags="performance")
>> -    private static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM =
>> "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
>> +    public static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM =
>> "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
>>
>>      /**
>>       * Indicates the amount of views (default is not active) that should be
>> stored in session between sequential
>> @@ -91,13 +79,13 @@ class ServerSideStateCacheImpl extends S
>>       * the other ones will throw ViewExpiredException.</p>
>>       */
>>      @JSFWebConfigParam(since="2.0.6",
>> classType="java.lang.Integer", group="state",
>> tags="performance")
>> -    private static final String NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM
>> +    public static final String NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM
>>              =
>> "org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION";
>>
>>      /**
>>       * Default value for
>> <code>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</code> context
>> parameter.
>>       */
>> -    private static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
>> +    public static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
>>
>>      /**
>>       * Indicate if the state should be serialized before save it on the
>> session.
>> @@ -108,7 +96,7 @@ class ServerSideStateCacheImpl extends S
>>       * </p>
>>       */
>>      @JSFWebConfigParam(defaultValue="true",since="1.1",
>> expectedValues="true,false", group="state",
>> tags="performance")
>> -    private static final String SERIALIZE_STATE_IN_SESSION_PARAM =
>> "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
>> +    public static final String SERIALIZE_STATE_IN_SESSION_PARAM =
>> "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
>>
>>      /**
>>       * Indicates that the serialized state will be compressed before it is
>> written to the session. By default true.
>> @@ -119,17 +107,17 @@ class ServerSideStateCacheImpl extends S
>>       * If <code>false</code> the state will not be compressed.
>>       */
>>      @JSFWebConfigParam(defaultValue="true",since="1.1",
>> expectedValues="true,false", group="state",
>> tags="performance")
>> -    private static final String COMPRESS_SERVER_STATE_PARAM =
>> "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
>> +    public static final String COMPRESS_SERVER_STATE_PARAM =
>> "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
>>
>>      /**
>>       * Default value for
>> <code>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</code> context
>> parameter.
>>       */
>> -    private static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = true;
>> +    public static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = true;
>>
>>      /**
>>       * Default value for
>> <code>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</code> context
>> parameter.
>>       */
>> -    private static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = true;
>> +    public static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = true;
>>
>>      /**
>>       * Define the way of handle old view references(views removed from
>> session), making possible to
>> @@ -156,22 +144,22 @@ class ServerSideStateCacheImpl extends S
>>       */
>>      @JSFWebConfigParam(defaultValue="off", expectedValues="off,
>> no, hard-soft, soft, soft-weak, weak",
>>                         since="1.2.5", group="state",
>> tags="performance")
>> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE =
>> "org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE";
>> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE =
>> "org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE";
>>
>>      /**
>>       * This option uses an hard-soft ReferenceMap, but it could cause a
>>       * memory leak, because the keys are not removed by any method
>>       * (MYFACES-1660). So use with caution.
>>       */
>> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT =
>> "hard-soft";
>> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT =
>> "hard-soft";
>>
>> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT =
>> "soft";
>> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT =
>> "soft";
>>
>> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK =
>> "soft-weak";
>> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK =
>> "soft-weak";
>>
>> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK =
>> "weak";
>> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK =
>> "weak";
>>
>> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF =
>> "off";
>> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF =
>> "off";
>>
>>      /**
>>       * Allow use flash scope to keep track of the views used in session and the
>> previous ones,
>> @@ -182,21 +170,21 @@ class ServerSideStateCacheImpl extends S
>>       * The default value is false.</p>
>>       */
>>      @JSFWebConfigParam(since="2.0.6", defaultValue="false",
>> expectedValues="true, false", group="state")
>> -    private static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
>> +    public static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
>>              =
>> "org.apache.myfaces.USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION";
>>
>> -    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE =
>> "none";
>> -    private static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = "secureRandom";
>> -    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM =
>> "random";
>> +    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE =
>> "none";
>> +    public static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = "secureRandom";
>> +    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM =
>> "random";
>>
>>      /**
>>       * Adds a random key to the generated view state session token.
>>       */
>>      @JSFWebConfigParam(since="2.1.9, 2.0.15",
>> expectedValues="secureRandom, random, none",
>>              defaultValue="none", group="state")
>> -    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
>> +    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
>>              =
>> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN";
>> -    private static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT =
>> +    public static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT =
>>              RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE;
>>
>>      /**
>> @@ -204,23 +192,23 @@ class ServerSideStateCacheImpl extends S
>>       * By default is 8.
>>       */
>>      @JSFWebConfigParam(since="2.1.9, 2.0.15",
>> defaultValue="8", group="state")
>> -    private static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM
>> +    public static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM
>>              =
>> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH";
>> -    private static final int
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT = 8;
>> +    public static final int
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT = 8;
>>
>>      /**
>>       * Sets the random class to initialize the secure random id generator.
>>       * By default it uses java.security.SecureRandom
>>       */
>>      @JSFWebConfigParam(since="2.1.9, 2.0.15",
>> group="state")
>> -    private static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM
>> +    public static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM
>>              =
>> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS";
>>
>>      /**
>>       * Sets the random provider to initialize the secure random id generator.
>>       */
>>      @JSFWebConfigParam(since="2.1.9, 2.0.15",
>> group="state")
>> -    private static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM
>> +    public static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM
>>              =
>> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER";
>>
>>      /**
>> @@ -228,14 +216,14 @@ class ServerSideStateCacheImpl extends S
>>       * By default is SHA1PRNG
>>       */
>>      @JSFWebConfigParam(since="2.1.9, 2.0.15",
>> defaultValue="SHA1PRNG", group="state")
>> -    private static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM
>> +    public static final String
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM
>>              =
>> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM";
>>
>>
>> -    private static final int UNCOMPRESSED_FLAG = 0;
>> -    private static final int COMPRESSED_FLAG = 1;
>> +    public static final int UNCOMPRESSED_FLAG = 0;
>> +    public static final int COMPRESSED_FLAG = 1;
>>
>> -    private static final Object[] EMPTY_STATES = new Object[]{null, null};
>> +    public static final Object[] EMPTY_STATES = new Object[]{null, null};
>>
>>      //private static final int JSF_SEQUENCE_INDEX = 0;
>>
>> @@ -589,440 +577,6 @@ class ServerSideStateCacheImpl extends S
>>          }
>>      }
>>
>> -    protected static class SerializedViewCollection implements Serializable
>> -    {
>> -        private static final long serialVersionUID = -3734849062185115847L;
>> -
>> -        private final List<SerializedViewKey> _keys
>> -                = new
>> ArrayList<SerializedViewKey>(DEFAULT_NUMBER_OF_VIEWS_IN_SESSION);
>> -        private final Map<SerializedViewKey, Object> _serializedViews =
>> new HashMap<SerializedViewKey, Object>();
>> -
>> -        private final Map<SerializedViewKey, SerializedViewKey>
>> _precedence =
>> -            new HashMap<SerializedViewKey, SerializedViewKey>();
>> -
>> -        // old views will be hold as soft references which will be removed by
>> -        // the garbage collector if free memory is low
>> -        private transient Map<Object, Object> _oldSerializedViews = null;
>> -
>> -        public synchronized void add(FacesContext context, Object state,
>> SerializedViewKey key,
>> -                                     SerializedViewKey previousRestoredKey)
>> -        {
>> -            if (state == null)
>> -            {
>> -                state = EMPTY_STATES;
>> -            }
>> -            else if (state instanceof Object[] &&
>> -                ((Object[])state).length == 2 &&
>> -                ((Object[])state)[0] == null &&
>> -                ((Object[])state)[1] == null)
>> -            {
>> -                // The generated state can be considered zero, set it as null
>> -                // into the map.
>> -                state = null;
>> -            }
>> -
>> -            Integer maxCount = getNumberOfSequentialViewsInSession(context);
>> -            if (maxCount != null)
>> -            {
>> -                if (previousRestoredKey != null)
>> -                {
>> -                    if (!_serializedViews.isEmpty())
>> -                    {
>> -                        _precedence.put((SerializedViewKey) key,
>> previousRestoredKey);
>> -                    }
>> -                    else
>> -                    {
>> -                        // Note when the session is invalidated,
>> _serializedViews map is empty,
>> -                        // but we could have a not null previousRestoredKey
>> (the last one before
>> -                        // invalidate the session), so we need to check that
>> condition before
>> -                        // set the precence. In that way, we ensure the
>> precedence map will always
>> -                        // have valid keys.
>> -                        previousRestoredKey = null;
>> -                    }
>> -                }
>> -            }
>> -            _serializedViews.put(key, state);
>> -
>> -            while (_keys.remove(key))
>> -            {
>> -                // do nothing
>> -            }
>> -            _keys.add(key);
>> -
>> -            if (previousRestoredKey != null && maxCount != null
>> && maxCount > 0)
>> -            {
>> -                int count = 0;
>> -                SerializedViewKey previousKey = (SerializedViewKey) key;
>> -                do
>> -                {
>> -                  previousKey = _precedence.get(previousKey);
>> -                  count++;
>> -                } while (previousKey != null && count < maxCount);
>> -
>> -                if (previousKey != null)
>> -                {
>> -                    SerializedViewKey keyToRemove = (SerializedViewKey)
>> previousKey;
>> -                    // In theory it should be only one key but just to be sure
>> -                    // do it in a loop, but in this case if cache old views is
>> on,
>> -                    // put on that map.
>> -                    do
>> -                    {
>> -                        while (_keys.remove(keyToRemove))
>> -                        {
>> -                            // do nothing
>> -                        }
>> -
>> -                        if (_serializedViews.containsKey(keyToRemove)
>> &&
>> -
>> !CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF.equals(getCacheOldViewsInSessionMode(context)))
>> -                        {
>> -                            getOldSerializedViewsMap().put(keyToRemove,
>> _serializedViews.remove(keyToRemove));
>> -                        }
>> -                        else
>> -                        {
>> -                            _serializedViews.remove(keyToRemove);
>> -                        }
>> -
>> -                        keyToRemove = _precedence.remove(keyToRemove);
>> -                    }  while(keyToRemove != null);
>> -                }
>> -            }
>> -
>> -            int views = getNumberOfViewsInSession(context);
>> -            while (_keys.size() > views)
>> -            {
>> -                key = _keys.remove(0);
>> -
>> -                if (maxCount != null && maxCount > 0)
>> -                {
>> -                    SerializedViewKey keyToRemove = (SerializedViewKey) key;
>> -                    // Note in this case the key to delete is the oldest one,
>> -                    // so it could be at least one precedence, but to be safe
>> -                    // do it with a loop.
>> -                    do
>> -                    {
>> -                        keyToRemove = _precedence.remove(keyToRemove);
>> -                    } while (keyToRemove != null);
>> -                }
>> -
>> -                if (_serializedViews.containsKey(key) &&
>> -
>> !CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF.equals(getCacheOldViewsInSessionMode(context)))
>> -                {
>> -
>> -                    getOldSerializedViewsMap().put(key,
>> _serializedViews.remove(key));
>> -                }
>> -                else
>> -                {
>> -                    _serializedViews.remove(key);
>> -                }
>> -            }
>> -        }
>> -
>> -        protected Integer getNumberOfSequentialViewsInSession(FacesContext
>> context)
>> -        {
>> -            return
>> WebConfigParamUtils.getIntegerInitParameter(context.getExternalContext(),
>> -                    NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM);
>> -        }
>> -
>> -        /**
>> -         * Reads the amount (default = 20) of views to be stored in session.
>> -         * @see #NUMBER_OF_VIEWS_IN_SESSION_PARAM
>> -         * @param context FacesContext for the current request, we are
>> processing
>> -         * @return Number vf views stored in the session
>> -         */
>> -        protected int getNumberOfViewsInSession(FacesContext context)
>> -        {
>> -            String value = context.getExternalContext().getInitParameter(
>> -                    NUMBER_OF_VIEWS_IN_SESSION_PARAM);
>> -            int views = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
>> -            if (value != null)
>> -            {
>> -                try
>> -                {
>> -                    views = Integer.parseInt(value);
>> -                    if (views <= 0)
>> -                    {
>> -                        log.severe("Configured value for " +
>> NUMBER_OF_VIEWS_IN_SESSION_PARAM
>> -                                  + " is not valid, must be an value >
>> 0, using default value ("
>> -                                  + DEFAULT_NUMBER_OF_VIEWS_IN_SESSION);
>> -                        views = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
>> -                    }
>> -                }
>> -                catch (Throwable e)
>> -                {
>> -                    log.log(Level.SEVERE, "Error determining the value for
>> " + NUMBER_OF_VIEWS_IN_SESSION_PARAM
>> -                              + ", expected an integer value > 0, using
>> default value ("
>> -                              + DEFAULT_NUMBER_OF_VIEWS_IN_SESSION + "):
>> " + e.getMessage(), e);
>> -                }
>> -            }
>> -            return views;
>> -        }
>> -
>> -        /**
>> -         * @return old serialized views map
>> -         */
>> -        @SuppressWarnings("unchecked")
>> -        protected Map<Object, Object> getOldSerializedViewsMap()
>> -        {
>> -            FacesContext context = FacesContext.getCurrentInstance();
>> -            if (_oldSerializedViews == null && context != null)
>> -            {
>> -                String cacheMode = getCacheOldViewsInSessionMode(context);
>> -                if (CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK.equals(cacheMode))
>> -                {
>> -                    _oldSerializedViews = new
>> ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true);
>> -                }
>> -                else if
>> (CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK.equals(cacheMode))
>> -                {
>> -                    _oldSerializedViews = new
>> ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK, true);
>> -                }
>> -                else if
>> (CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT.equals(cacheMode))
>> -                {
>> -                    _oldSerializedViews = new
>> ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT, true);
>> -                }
>> -                else if
>> (CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT.equals(cacheMode))
>> -                {
>> -                    _oldSerializedViews = new
>> ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
>> -                }
>> -            }
>> -
>> -            return _oldSerializedViews;
>> -        }
>> -
>> -        /**
>> -         * Reads the value of the
>> <code>org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE</code>
>> context parameter.
>> -         *
>> -         * @since 1.2.5
>> -         * @param context
>> -         * @return constant indicating caching mode
>> -         * @see #CACHE_OLD_VIEWS_IN_SESSION_MODE
>> -         */
>> -        protected String getCacheOldViewsInSessionMode(FacesContext context)
>> -        {
>> -            String value = context.getExternalContext().getInitParameter(
>> -                    CACHE_OLD_VIEWS_IN_SESSION_MODE);
>> -            if (value == null)
>> -            {
>> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF;
>> -            }
>> -            else if
>> (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT))
>> -            {
>> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT;
>> -            }
>> -            else if
>> (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK))
>> -            {
>> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK;
>> -            }
>> -            else if
>> (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK))
>> -            {
>> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK;
>> -            }
>> -            else if
>> (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT))
>> -            {
>> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT;
>> -            }
>> -            else
>> -            {
>> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF;
>> -            }
>> -        }
>> -
>> -        public Object get(SerializedViewKey key)
>> -        {
>> -            Object value = _serializedViews.get(key);
>> -            if (value == null)
>> -            {
>> -                if (_serializedViews.containsKey(key))
>> -                {
>> -                    return EMPTY_STATES;
>> -                }
>> -                Map<Object,Object> oldSerializedViewMap =
>> getOldSerializedViewsMap();
>> -                if (oldSerializedViewMap != null)
>> -                {
>> -                    value = oldSerializedViewMap.get(key);
>> -                    if (value == null &&
>> oldSerializedViewMap.containsKey(key) )
>> -                    {
>> -                        return EMPTY_STATES;
>> -                    }
>> -                }
>> -            }
>> -            else if (value instanceof Object[] &&
>> -                ((Object[])value).length == 2 &&
>> -                ((Object[])value)[0] == null &&
>> -                ((Object[])value)[1] == null)
>> -            {
>> -                // Remember inside the state map null is stored as an empty
>> array.
>> -                return null;
>> -            }
>> -            return value;
>> -        }
>> -    }
>> -
>> -    /**
>> -     * Base implementation where all keys used to identify the state of a view
>> should
>> -     * extend.
>> -     */
>> -    protected abstract static class SerializedViewKey implements Serializable
>> -    {
>> -    }
>> -
>> -    /**
>> -     * Implementation of SerializedViewKey, where the hashCode of the viewId is
>> used
>> -     * and the sequenceId is a numeric value.
>> -     */
>> -    private static class IntIntSerializedViewKey extends SerializedViewKey
>> -        implements Serializable
>> -    {
>> -        private static final long serialVersionUID = -1170697124386063642L;
>> -
>> -        private final int _viewId;
>> -        private final int _sequenceId;
>> -
>> -        public IntIntSerializedViewKey(int viewId, int sequence)
>> -        {
>> -            _sequenceId = sequence;
>> -            _viewId = viewId;
>> -        }
>> -
>> -        @Override
>> -        public boolean equals(Object obj)
>> -        {
>> -            if (obj == null)
>> -            {
>> -                return false;
>> -            }
>> -            if (getClass() != obj.getClass())
>> -            {
>> -                return false;
>> -            }
>> -            final IntIntSerializedViewKey other = (IntIntSerializedViewKey)
>> obj;
>> -            if (this._viewId != other._viewId)
>> -            {
>> -                return false;
>> -            }
>> -            if (this._sequenceId != other._sequenceId)
>> -            {
>> -                return false;
>> -            }
>> -            return true;
>> -        }
>> -
>> -        @Override
>> -        public int hashCode()
>> -        {
>> -            int hash = 7;
>> -            hash = 83 * hash + this._viewId;
>> -            hash = 83 * hash + this._sequenceId;
>> -            return hash;
>> -        }
>> -    }
>> -
>> -    /**
>> -     * Implementation of SerializedViewKey, where the hashCode of the viewId is
>> used
>> -     * and the sequenceId is a string value.
>> -     */
>> -    private static class IntByteArraySerializedViewKey extends
>> SerializedViewKey
>> -        implements Serializable
>> -    {
>> -        private final int _viewId;
>> -        private final byte[] _sequenceId;
>> -
>> -        public IntByteArraySerializedViewKey(int viewId, byte[] sequence)
>> -        {
>> -            _sequenceId = sequence;
>> -            _viewId = viewId;
>> -        }
>> -
>> -        @Override
>> -        public boolean equals(Object obj)
>> -        {
>> -            if (obj == null)
>> -            {
>> -                return false;
>> -            }
>> -            if (getClass() != obj.getClass())
>> -            {
>> -                return false;
>> -            }
>> -            final IntByteArraySerializedViewKey other =
>> (IntByteArraySerializedViewKey) obj;
>> -            if (this._viewId != other._viewId)
>> -            {
>> -                return false;
>> -            }
>> -            if (!Arrays.equals(this._sequenceId, other._sequenceId))
>> -            {
>> -                return false;
>> -            }
>> -            return true;
>> -        }
>> -
>> -        @Override
>> -        public int hashCode()
>> -        {
>> -            int hash = 5;
>> -            hash = 37 * hash + this._viewId;
>> -            hash = 37 * hash + Arrays.hashCode(this._sequenceId);
>> -            return hash;
>> -        }
>> -    }
>> -
>> -
>> -    /**
>> -     * Implementation of SerializedViewKey, where the viewId and the sequenceId
>> can be
>> -     * anything.
>> -     */
>> -    private static class ReferenceSerializedViewKey<I,K> extends
>> SerializedViewKey
>> -        implements Serializable
>> -    {
>> -        private static final long serialVersionUID = -1170697124386063642L;
>> -
>> -        private final I _viewId;
>> -        private final K _sequenceId;
>> -
>> -        public ReferenceSerializedViewKey()
>> -        {
>> -            _sequenceId = null;
>> -            _viewId = null;
>> -        }
>> -        public ReferenceSerializedViewKey(I viewId, K sequence)
>> -        {
>> -            _sequenceId = sequence;
>> -            _viewId = viewId;
>> -        }
>> -
>> -        @Override
>> -        public boolean equals(Object obj)
>> -        {
>> -            if (obj == null)
>> -            {
>> -                return false;
>> -            }
>> -            if (getClass() != obj.getClass())
>> -            {
>> -                return false;
>> -            }
>> -            final ReferenceSerializedViewKey<I, K> other =
>> (ReferenceSerializedViewKey<I, K>) obj;
>> -            if (this._viewId != other._viewId && (this._viewId == null
>> || !this._viewId.equals(other._viewId)))
>> -            {
>> -                return false;
>> -            }
>> -            if (this._sequenceId != other._sequenceId &&
>> -                (this._sequenceId == null ||
>> !this._sequenceId.equals(other._sequenceId)))
>> -            {
>> -                return false;
>> -            }
>> -            return true;
>> -        }
>> -
>> -        @Override
>> -        public int hashCode()
>> -        {
>> -            int hash = 7;
>> -            hash = 83 * hash + (this._viewId != null ? this._viewId.hashCode()
>> : 0);
>> -            hash = 83 * hash + (this._sequenceId != null ?
>> this._sequenceId.hashCode() : 0);
>> -            return hash;
>> -        }
>> -    }
>> -
>>      //------------------------------------- METHOD FROM StateCache
>> ------------------------------------------------
>>
>>      @Override
>> @@ -1103,349 +657,4 @@ class ServerSideStateCacheImpl extends S
>>      {
>>          return sessionViewStorageFactory;
>>      }
>> -
>> -
>> -    protected abstract static class KeyFactory<K, V>
>> -    {
>> -
>> -        /**
>> -         * Generates a unique key per session
>> -         *
>> -         * @param facesContext
>> -         * @return
>> -         */
>> -        public abstract K generateKey(FacesContext facesContext);
>> -
>> -        /**
>> -         * Encode a Key into a value that will be used as view state session
>> token
>> -         *
>> -         * @param key
>> -         * @return
>> -         */
>> -        public abstract V encode(K key);
>> -
>> -        /**
>> -         * Decode a view state session token into a key
>> -         *
>> -         * @param value
>> -         * @return
>> -         */
>> -        public abstract K decode(V value);
>> -
>> -    }
>> -
>> -    private static class CounterKeyFactory extends KeyFactory<Integer,
>> String>
>> -    {
>> -        /**
>> -         * Take the counter from session scope and increment
>> -         *
>> -         * @param facesContext
>> -         * @return
>> -         */
>> -        @Override
>> -        public Integer generateKey(FacesContext facesContext)
>> -        {
>> -            ExternalContext externalContext =
>> facesContext.getExternalContext();
>> -            Object sessionObj = externalContext.getSession(true);
>> -            Integer sequence = null;
>> -            synchronized(sessionObj) // synchronized to increase sequence if
>> multiple requests
>> -                                    // are handled at the same time for the
>> session
>> -            {
>> -                Map<String, Object> map =
>> externalContext.getSessionMap();
>> -                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
>> -                if(sequence == null || sequence.intValue() ==
>> Integer.MAX_VALUE)
>> -                {
>> -                    sequence = Integer.valueOf(1);
>> -                }
>> -                else
>> -                {
>> -                    sequence = Integer.valueOf(sequence.intValue() + 1);
>> -                }
>> -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
>> -            }
>> -            return sequence;
>> -        }
>> -
>> -        public String encode(Integer sequence)
>> -        {
>> -            return Integer.toString(sequence, Character.MAX_RADIX);
>> -        }
>> -
>> -        public Integer decode(String serverStateId)
>> -        {
>> -             return Integer.valueOf((String) serverStateId,
>> Character.MAX_RADIX);
>> -        }
>> -    }
>> -
>> -    /**
>> -     * This factory generate a key composed by a counter and a random number.
>> The
>> -     * counter ensures uniqueness, and the random number prevents guess the
>> next
>> -     * session token.
>> -     */
>> -    private static class SecureRandomKeyFactory extends KeyFactory<byte[],
>> String>
>> -    {
>> -        private final SessionIdGenerator sessionIdGenerator;
>> -        private final int length;
>> -
>> -        public SecureRandomKeyFactory(FacesContext facesContext)
>> -        {
>> -            length =
>> WebConfigParamUtils.getIntegerInitParameter(facesContext.getExternalContext(),
>> -                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM,
>> -
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT);
>> -            sessionIdGenerator = new SessionIdGenerator();
>> -            sessionIdGenerator.setSessionIdLength(length);
>> -            String secureRandomClass =
>> WebConfigParamUtils.getStringInitParameter(
>> -                    facesContext.getExternalContext(),
>> -
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM);
>> -            if (secureRandomClass != null)
>> -            {
>> -                sessionIdGenerator.setSecureRandomClass(secureRandomClass);
>> -            }
>> -            String secureRandomProvider =
>> WebConfigParamUtils.getStringInitParameter(
>> -                    facesContext.getExternalContext(),
>> -
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM);
>> -            if (secureRandomProvider != null)
>> -            {
>> -
>> sessionIdGenerator.setSecureRandomProvider(secureRandomProvider);
>> -            }
>> -            String secureRandomAlgorithm =
>> WebConfigParamUtils.getStringInitParameter(
>> -                    facesContext.getExternalContext(),
>> -
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM);
>> -            if (secureRandomAlgorithm != null)
>> -            {
>> -
>> sessionIdGenerator.setSecureRandomAlgorithm(secureRandomAlgorithm);
>> -            }
>> -        }
>> -
>> -        public Integer generateCounterKey(FacesContext facesContext)
>> -        {
>> -            ExternalContext externalContext =
>> facesContext.getExternalContext();
>> -            Object sessionObj = externalContext.getSession(true);
>> -            Integer sequence = null;
>> -            synchronized(sessionObj) // synchronized to increase sequence if
>> multiple requests
>> -                                    // are handled at the same time for the
>> session
>> -            {
>> -                Map<String, Object> map =
>> externalContext.getSessionMap();
>> -                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
>> -                if(sequence == null || sequence.intValue() ==
>> Integer.MAX_VALUE)
>> -                {
>> -                    sequence = Integer.valueOf(1);
>> -                }
>> -                else
>> -                {
>> -                    sequence = Integer.valueOf(sequence.intValue() + 1);
>> -                }
>> -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
>> -            }
>> -            return sequence;
>> -        }
>> -
>> -        @Override
>> -        public byte[] generateKey(FacesContext facesContext)
>> -        {
>> -            byte[] array = new byte[length];
>> -            byte[] key = new byte[length+4];
>> -
>> -            sessionIdGenerator.getRandomBytes(array);
>> -            for (int i = 0; i < array.length; i++)
>> -            {
>> -                key[i] = array[i];
>> -            }
>> -            int value = generateCounterKey(facesContext);
>> -            key[array.length] =  (byte) (value >>> 24);
>> -            key[array.length+1] =  (byte) (value >>> 16);
>> -            key[array.length+2] =  (byte) (value >>> 8);
>> -            key[array.length+3] =  (byte) (value);
>> -
>> -            return key;
>> -        }
>> -
>> -        @Override
>> -        public String encode(byte[] key)
>> -        {
>> -            return new String(Hex.encodeHex(key));
>> -        }
>> -
>> -        @Override
>> -        public byte[] decode(String value)
>> -        {
>> -            try
>> -            {
>> -                return Hex.decodeHex(value.toCharArray());
>> -            }
>> -            catch (DecoderException ex)
>> -            {
>> -                // Cannot decode, ignore silently, later it will be handled as
>> -                // ViewExpiredException
>> -            }
>> -            return null;
>> -        }
>> -    }
>> -
>> -    private static class RandomKeyFactory extends KeyFactory<byte[],
>> String>
>> -    {
>> -        private final Random random;
>> -        private final int length;
>> -
>> -        public RandomKeyFactory(FacesContext facesContext)
>> -        {
>> -            length =
>> WebConfigParamUtils.getIntegerInitParameter(facesContext.getExternalContext(),
>> -                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM,
>> -
>> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT);
>> -            random = new Random(((int)System.nanoTime())+this.hashCode());
>> -        }
>> -
>> -        public Integer generateCounterKey(FacesContext facesContext)
>> -        {
>> -            ExternalContext externalContext =
>> facesContext.getExternalContext();
>> -            Object sessionObj = externalContext.getSession(true);
>> -            Integer sequence = null;
>> -            synchronized(sessionObj) // synchronized to increase sequence if
>> multiple requests
>> -                                    // are handled at the same time for the
>> session
>> -            {
>> -                Map<String, Object> map =
>> externalContext.getSessionMap();
>> -                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
>> -                if(sequence == null || sequence.intValue() ==
>> Integer.MAX_VALUE)
>> -                {
>> -                    sequence = Integer.valueOf(1);
>> -                }
>> -                else
>> -                {
>> -                    sequence = Integer.valueOf(sequence.intValue() + 1);
>> -                }
>> -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
>> -            }
>> -            return sequence;
>> -        }
>> -
>> -        @Override
>> -        public byte[] generateKey(FacesContext facesContext)
>> -        {
>> -            byte[] array = new byte[length];
>> -            byte[] key = new byte[length+4];
>> -
>> -            //sessionIdGenerator.getRandomBytes(array);
>> -            random.nextBytes(array);
>> -            for (int i = 0; i < array.length; i++)
>> -            {
>> -                key[i] = array[i];
>> -            }
>> -            int value = generateCounterKey(facesContext);
>> -            key[array.length] =  (byte) (value >>> 24);
>> -            key[array.length+1] =  (byte) (value >>> 16);
>> -            key[array.length+2] =  (byte) (value >>> 8);
>> -            key[array.length+3] =  (byte) (value);
>> -
>> -            return key;
>> -        }
>> -
>> -        @Override
>> -        public String encode(byte[] key)
>> -        {
>> -            return new String(Hex.encodeHex(key));
>> -        }
>> -
>> -        @Override
>> -        public byte[] decode(String value)
>> -        {
>> -            try
>> -            {
>> -                return Hex.decodeHex(value.toCharArray());
>> -            }
>> -            catch (DecoderException ex)
>> -            {
>> -                // Cannot decode, ignore silently, later it will be handled as
>> -                // ViewExpiredException
>> -            }
>> -            return null;
>> -        }
>> -    }
>> -
>> -    /**
>> -     *
>> -     * @param <T>
>> -     * @param <K>
>> -     * @param <V>
>> -     */
>> -    protected abstract static class SessionViewStorageFactory <T extends
>> KeyFactory<K,V>, K, V >
>> -    {
>> -        private KeyFactory<K, V> keyFactory;
>> -
>> -        public SessionViewStorageFactory(KeyFactory<K, V> keyFactory)
>> -        {
>> -            this.keyFactory = keyFactory;
>> -        }
>> -
>> -        public KeyFactory<K, V> getKeyFactory()
>> -        {
>> -            return keyFactory;
>> -        }
>> -
>> -        public abstract SerializedViewCollection
>> createSerializedViewCollection(
>> -                FacesContext context);
>> -
>> -        public abstract SerializedViewKey createSerializedViewKey(
>> -                FacesContext facesContext, String viewId, K key);
>> -
>> -    }
>> -
>> -    private static class CounterSessionViewStorageFactory
>> -        extends SessionViewStorageFactory <KeyFactory
>> <Integer,String>, Integer, String>
>> -    {
>> -        public CounterSessionViewStorageFactory(KeyFactory<Integer,
>> String> keyFactory)
>> -        {
>> -            super(keyFactory);
>> -        }
>> -
>> -        @Override
>> -        public SerializedViewCollection createSerializedViewCollection(
>> -                FacesContext context)
>> -        {
>> -            return new SerializedViewCollection();
>> -        }
>> -
>> -        @Override
>> -        public SerializedViewKey createSerializedViewKey(
>> -                FacesContext context, String viewId, Integer key)
>> -        {
>> -            if (context.isProjectStage(ProjectStage.Production))
>> -            {
>> -                return new IntIntSerializedViewKey(viewId == null ? 0 :
>> viewId.hashCode(), key);
>> -            }
>> -            else
>> -            {
>> -                return new ReferenceSerializedViewKey(viewId, key);
>> -            }
>> -        }
>> -    }
>> -
>> -    private static class RandomSessionViewStorageFactory
>> -        extends SessionViewStorageFactory <KeyFactory <byte[],String>,
>> byte[], String>
>> -    {
>> -        public RandomSessionViewStorageFactory(KeyFactory<byte[], String>
>> keyFactory)
>> -        {
>> -            super(keyFactory);
>> -        }
>> -
>> -        @Override
>> -        public SerializedViewCollection createSerializedViewCollection(
>> -                FacesContext context)
>> -        {
>> -            return new SerializedViewCollection();
>> -        }
>> -
>> -        @Override
>> -        public SerializedViewKey createSerializedViewKey(
>> -                FacesContext context, String viewId, byte[] key)
>> -        {
>> -            if (context.isProjectStage(ProjectStage.Production))
>> -            {
>> -                return new IntByteArraySerializedViewKey(viewId == null ? 0 :
>> viewId.hashCode(), key);
>> -            }
>> -            else
>> -            {
>> -                return new ReferenceSerializedViewKey(viewId, key);
>> -            }
>> -        }
>> -    }
>> }
>>
>> Added:
>> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
>> URL:
>> http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java?rev=1410205&view=auto
>> ==============================================================================
>> ---
>> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
>> (added)
>> +++
>> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
>> Fri Nov 16 06:01:51 2012
>> @@ -0,0 +1,48 @@
>> +/*
>> + * 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.application.viewstate;
>> +
>> +import javax.faces.context.FacesContext;
>> +
>> +/**
>> + *
>> + * @param <T>
>> + * @param <K>
>> + * @param <V>
>> + */
>> +abstract class SessionViewStorageFactory<T extends KeyFactory<K, V>,
>> K, V>
>> +{
>> +    private KeyFactory<K, V> keyFactory;
>> +
>> +    public SessionViewStorageFactory(KeyFactory<K, V> keyFactory)
>> +    {
>> +        this.keyFactory = keyFactory;
>> +    }
>> +
>> +    public KeyFactory<K, V> getKeyFactory()
>> +    {
>> +        return keyFactory;
>> +    }
>> +
>> +    public abstract SerializedViewCollection
>> createSerializedViewCollection(FacesContext context);
>> +
>> +    public abstract SerializedViewKey createSerializedViewKey(
>> +        FacesContext facesContext, String viewId, K key);
>> +
>> +}
>>
>> Propchange:
>> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
>> ------------------------------------------------------------------------------
>>     svn:eol-style = native
>>

Re: svn commit: r1410205 [2/2] - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/

Posted by Mark Struberg <st...@yahoo.de>.
Leo, why do you backport all this stuff to 2.0.x? That makes no sense to me.





----- Original Message -----
> From: "lu4242@apache.org" <lu...@apache.org>
> To: commits@myfaces.apache.org
> Cc: 
> Sent: Friday, November 16, 2012 7:01 AM
> Subject: svn commit: r1410205 [2/2] - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/
> 
> Modified: 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java
> URL: 
> http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java?rev=1410205&r1=1410204&r2=1410205&view=diff
> ==============================================================================
> --- 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java 
> (original)
> +++ 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/ServerSideStateCacheImpl.java 
> Fri Nov 16 06:01:51 2012
> @@ -25,29 +25,17 @@ import java.io.InputStream;
> import java.io.ObjectInputStream;
> import java.io.ObjectOutputStream;
> import java.io.OutputStream;
> -import java.io.Serializable;
> import java.security.AccessController;
> import java.security.PrivilegedActionException;
> import java.security.PrivilegedExceptionAction;
> -import java.util.ArrayList;
> -import java.util.Arrays;
> -import java.util.HashMap;
> -import java.util.List;
> import java.util.Map;
> -import java.util.Random;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> import java.util.zip.GZIPInputStream;
> import java.util.zip.GZIPOutputStream;
> -import javax.faces.application.ProjectStage;
> 
> import javax.faces.context.ExternalContext;
> import javax.faces.context.FacesContext;
> -import org.apache.commons.codec.DecoderException;
> -import org.apache.commons.codec.binary.Hex;
> -
> -import org.apache.commons.collections.map.AbstractReferenceMap;
> -import org.apache.commons.collections.map.ReferenceMap;
> import org.apache.myfaces.application.StateCache;
> import 
> org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
> import org.apache.myfaces.shared.renderkit.RendererUtils;
> @@ -56,15 +44,15 @@ import org.apache.myfaces.shared.util.We
> 
> class ServerSideStateCacheImpl extends StateCache<Object, Object>
> {
> -    private static final Logger log = 
> Logger.getLogger(ServerSideStateCacheImpl.class.getName());
> +    public static final Logger log = 
> Logger.getLogger(ServerSideStateCacheImpl.class.getName());
>     
> -    private static final String SERIALIZED_VIEW_SESSION_ATTR= 
> +    public static final String SERIALIZED_VIEW_SESSION_ATTR= 
>          ServerSideStateCacheImpl.class.getName() + 
> ".SERIALIZED_VIEW";
>     
> -    private static final String RESTORED_SERIALIZED_VIEW_REQUEST_ATTR = 
> +    public static final String RESTORED_SERIALIZED_VIEW_REQUEST_ATTR = 
>          ServerSideStateCacheImpl.class.getName() + 
> ".RESTORED_SERIALIZED_VIEW";
> 
> -    private static final String RESTORED_VIEW_KEY_REQUEST_ATTR = 
> +    public static final String RESTORED_VIEW_KEY_REQUEST_ATTR = 
>          ServerSideStateCacheImpl.class.getName() + 
> ".RESTORED_VIEW_KEY";
>     
>      /**
> @@ -75,7 +63,7 @@ class ServerSideStateCacheImpl extends S
>       * 
>       */
>      @JSFWebConfigParam(defaultValue="20",since="1.1", 
> classType="java.lang.Integer", group="state", 
> tags="performance")
> -    private static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM = 
> "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
> +    public static final String NUMBER_OF_VIEWS_IN_SESSION_PARAM = 
> "org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION";
> 
>      /**
>       * Indicates the amount of views (default is not active) that should be 
> stored in session between sequential
> @@ -91,13 +79,13 @@ class ServerSideStateCacheImpl extends S
>       * the other ones will throw ViewExpiredException.</p>
>       */
>      @JSFWebConfigParam(since="2.0.6", 
> classType="java.lang.Integer", group="state", 
> tags="performance")
> -    private static final String NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM
> +    public static final String NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM
>              = 
> "org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION";
>     
>      /**
>       * Default value for 
> <code>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</code> context 
> parameter.
>       */
> -    private static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
> +    public static final int DEFAULT_NUMBER_OF_VIEWS_IN_SESSION = 20;
> 
>      /**
>       * Indicate if the state should be serialized before save it on the 
> session. 
> @@ -108,7 +96,7 @@ class ServerSideStateCacheImpl extends S
>       * </p>
>       */
>      @JSFWebConfigParam(defaultValue="true",since="1.1", 
> expectedValues="true,false", group="state", 
> tags="performance")
> -    private static final String SERIALIZE_STATE_IN_SESSION_PARAM = 
> "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
> +    public static final String SERIALIZE_STATE_IN_SESSION_PARAM = 
> "org.apache.myfaces.SERIALIZE_STATE_IN_SESSION";
> 
>      /**
>       * Indicates that the serialized state will be compressed before it is 
> written to the session. By default true.
> @@ -119,17 +107,17 @@ class ServerSideStateCacheImpl extends S
>       * If <code>false</code> the state will not be compressed.
>       */
>      @JSFWebConfigParam(defaultValue="true",since="1.1", 
> expectedValues="true,false", group="state", 
> tags="performance")
> -    private static final String COMPRESS_SERVER_STATE_PARAM = 
> "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
> +    public static final String COMPRESS_SERVER_STATE_PARAM = 
> "org.apache.myfaces.COMPRESS_STATE_IN_SESSION";
> 
>      /**
>       * Default value for 
> <code>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</code> context 
> parameter.
>       */
> -    private static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = true;
> +    public static final boolean DEFAULT_COMPRESS_SERVER_STATE_PARAM = true;
> 
>      /**
>       * Default value for 
> <code>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</code> context 
> parameter.
>       */
> -    private static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = true;
> +    public static final boolean DEFAULT_SERIALIZE_STATE_IN_SESSION = true;
> 
>      /**
>       * Define the way of handle old view references(views removed from 
> session), making possible to
> @@ -156,22 +144,22 @@ class ServerSideStateCacheImpl extends S
>       */
>      @JSFWebConfigParam(defaultValue="off", expectedValues="off, 
> no, hard-soft, soft, soft-weak, weak",
>                         since="1.2.5", group="state", 
> tags="performance")
> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE = 
> "org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE";
> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE = 
> "org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE";
>     
>      /**
>       * This option uses an hard-soft ReferenceMap, but it could cause a 
>       * memory leak, because the keys are not removed by any method
>       * (MYFACES-1660). So use with caution.
>       */
> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT = 
> "hard-soft";
> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT = 
> "hard-soft";
>     
> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT = 
> "soft";
> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT = 
> "soft";
>     
> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK = 
> "soft-weak";
> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK = 
> "soft-weak";
>     
> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK = 
> "weak";
> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK = 
> "weak";
>     
> -    private static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF = 
> "off";
> +    public static final String CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF = 
> "off";
> 
>      /**
>       * Allow use flash scope to keep track of the views used in session and the 
> previous ones,
> @@ -182,21 +170,21 @@ class ServerSideStateCacheImpl extends S
>       * The default value is false.</p>
>       */
>      @JSFWebConfigParam(since="2.0.6", defaultValue="false", 
> expectedValues="true, false", group="state")
> -    private static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
> +    public static final String USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION
>              = 
> "org.apache.myfaces.USE_FLASH_SCOPE_PURGE_VIEWS_IN_SESSION";
> 
> -    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE = 
> "none";
> -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = "secureRandom";
> -    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM = 
> "random";
> +    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE = 
> "none";
> +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM = "secureRandom";
> +    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_RANDOM = 
> "random";
>     
>      /**
>       * Adds a random key to the generated view state session token.
>       */
>      @JSFWebConfigParam(since="2.1.9, 2.0.15", 
> expectedValues="secureRandom, random, none", 
>              defaultValue="none", group="state")
> -    private static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
> +    public static final String RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM
>              = 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN";
> -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT = 
> +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_PARAM_DEFAULT = 
>              RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_NONE;
> 
>      /**
> @@ -204,23 +192,23 @@ class ServerSideStateCacheImpl extends S
>       * By default is 8. 
>       */
>      @JSFWebConfigParam(since="2.1.9, 2.0.15", 
> defaultValue="8", group="state")
> -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM 
> +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM 
>              = 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH";
> -    private static final int 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT = 8;
> +    public static final int 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT = 8;
> 
>      /**
>       * Sets the random class to initialize the secure random id generator. 
>       * By default it uses java.security.SecureRandom
>       */
>      @JSFWebConfigParam(since="2.1.9, 2.0.15", 
> group="state")
> -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM
> +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM
>              = 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS";
>     
>      /**
>       * Sets the random provider to initialize the secure random id generator.
>       */
>      @JSFWebConfigParam(since="2.1.9, 2.0.15", 
> group="state")
> -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM
> +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM
>              = 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER";
>     
>      /**
> @@ -228,14 +216,14 @@ class ServerSideStateCacheImpl extends S
>       * By default is SHA1PRNG
>       */
>      @JSFWebConfigParam(since="2.1.9, 2.0.15", 
> defaultValue="SHA1PRNG", group="state")
> -    private static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM 
> +    public static final String 
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM 
>              = 
> "org.apache.myfaces.RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM";
>     
>     
> -    private static final int UNCOMPRESSED_FLAG = 0;
> -    private static final int COMPRESSED_FLAG = 1;
> +    public static final int UNCOMPRESSED_FLAG = 0;
> +    public static final int COMPRESSED_FLAG = 1;
>     
> -    private static final Object[] EMPTY_STATES = new Object[]{null, null};
> +    public static final Object[] EMPTY_STATES = new Object[]{null, null};
> 
>      //private static final int JSF_SEQUENCE_INDEX = 0;
>     
> @@ -589,440 +577,6 @@ class ServerSideStateCacheImpl extends S
>          }
>      }
>     
> -    protected static class SerializedViewCollection implements Serializable
> -    {
> -        private static final long serialVersionUID = -3734849062185115847L;
> -
> -        private final List<SerializedViewKey> _keys
> -                = new 
> ArrayList<SerializedViewKey>(DEFAULT_NUMBER_OF_VIEWS_IN_SESSION);
> -        private final Map<SerializedViewKey, Object> _serializedViews = 
> new HashMap<SerializedViewKey, Object>();
> -        
> -        private final Map<SerializedViewKey, SerializedViewKey> 
> _precedence = 
> -            new HashMap<SerializedViewKey, SerializedViewKey>();
> -
> -        // old views will be hold as soft references which will be removed by
> -        // the garbage collector if free memory is low
> -        private transient Map<Object, Object> _oldSerializedViews = null;
> -
> -        public synchronized void add(FacesContext context, Object state, 
> SerializedViewKey key,
> -                                     SerializedViewKey previousRestoredKey)
> -        {
> -            if (state == null)
> -            {
> -                state = EMPTY_STATES;
> -            }
> -            else if (state instanceof Object[] &&
> -                ((Object[])state).length == 2 &&
> -                ((Object[])state)[0] == null &&
> -                ((Object[])state)[1] == null)
> -            {
> -                // The generated state can be considered zero, set it as null
> -                // into the map.
> -                state = null;
> -            }
> -            
> -            Integer maxCount = getNumberOfSequentialViewsInSession(context);
> -            if (maxCount != null)
> -            {
> -                if (previousRestoredKey != null)
> -                {
> -                    if (!_serializedViews.isEmpty())
> -                    {
> -                        _precedence.put((SerializedViewKey) key, 
> previousRestoredKey);
> -                    }
> -                    else
> -                    {
> -                        // Note when the session is invalidated, 
> _serializedViews map is empty,
> -                        // but we could have a not null previousRestoredKey 
> (the last one before
> -                        // invalidate the session), so we need to check that 
> condition before
> -                        // set the precence. In that way, we ensure the 
> precedence map will always
> -                        // have valid keys.
> -                        previousRestoredKey = null;
> -                    }
> -                }
> -            }
> -            _serializedViews.put(key, state);
> -
> -            while (_keys.remove(key))
> -            {
> -                // do nothing
> -            }
> -            _keys.add(key);
> -
> -            if (previousRestoredKey != null && maxCount != null 
> && maxCount > 0)
> -            {
> -                int count = 0;
> -                SerializedViewKey previousKey = (SerializedViewKey) key;
> -                do
> -                {
> -                  previousKey = _precedence.get(previousKey);
> -                  count++;
> -                } while (previousKey != null && count < maxCount);
> -                
> -                if (previousKey != null)
> -                {
> -                    SerializedViewKey keyToRemove = (SerializedViewKey) 
> previousKey;
> -                    // In theory it should be only one key but just to be sure
> -                    // do it in a loop, but in this case if cache old views is 
> on,
> -                    // put on that map.
> -                    do
> -                    {
> -                        while (_keys.remove(keyToRemove))
> -                        {
> -                            // do nothing
> -                        }
> -
> -                        if (_serializedViews.containsKey(keyToRemove) 
> &&
> -                                
> !CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF.equals(getCacheOldViewsInSessionMode(context)))
> -                        {
> -                            getOldSerializedViewsMap().put(keyToRemove, 
> _serializedViews.remove(keyToRemove));
> -                        }
> -                        else
> -                        {
> -                            _serializedViews.remove(keyToRemove);
> -                        }
> -                    
> -                        keyToRemove = _precedence.remove(keyToRemove);
> -                    }  while(keyToRemove != null);
> -                }
> -            }
> -
> -            int views = getNumberOfViewsInSession(context);
> -            while (_keys.size() > views)
> -            {
> -                key = _keys.remove(0);
> -                
> -                if (maxCount != null && maxCount > 0)
> -                {
> -                    SerializedViewKey keyToRemove = (SerializedViewKey) key;
> -                    // Note in this case the key to delete is the oldest one, 
> -                    // so it could be at least one precedence, but to be safe
> -                    // do it with a loop.
> -                    do
> -                    {
> -                        keyToRemove = _precedence.remove(keyToRemove);
> -                    } while (keyToRemove != null);
> -                }
> -
> -                if (_serializedViews.containsKey(key) &&
> -                    
> !CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF.equals(getCacheOldViewsInSessionMode(context)))
> -                {
> -                    
> -                    getOldSerializedViewsMap().put(key, 
> _serializedViews.remove(key));
> -                }
> -                else
> -                {
> -                    _serializedViews.remove(key);
> -                }
> -            }
> -        }
> -
> -        protected Integer getNumberOfSequentialViewsInSession(FacesContext 
> context)
> -        {
> -            return 
> WebConfigParamUtils.getIntegerInitParameter(context.getExternalContext(), 
> -                    NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION_PARAM);
> -        }
> -        
> -        /**
> -         * Reads the amount (default = 20) of views to be stored in session.
> -         * @see #NUMBER_OF_VIEWS_IN_SESSION_PARAM
> -         * @param context FacesContext for the current request, we are 
> processing
> -         * @return Number vf views stored in the session
> -         */
> -        protected int getNumberOfViewsInSession(FacesContext context)
> -        {
> -            String value = context.getExternalContext().getInitParameter(
> -                    NUMBER_OF_VIEWS_IN_SESSION_PARAM);
> -            int views = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
> -            if (value != null)
> -            {
> -                try
> -                {
> -                    views = Integer.parseInt(value);
> -                    if (views <= 0)
> -                    {
> -                        log.severe("Configured value for " + 
> NUMBER_OF_VIEWS_IN_SESSION_PARAM
> -                                  + " is not valid, must be an value > 
> 0, using default value ("
> -                                  + DEFAULT_NUMBER_OF_VIEWS_IN_SESSION);
> -                        views = DEFAULT_NUMBER_OF_VIEWS_IN_SESSION;
> -                    }
> -                }
> -                catch (Throwable e)
> -                {
> -                    log.log(Level.SEVERE, "Error determining the value for 
> " + NUMBER_OF_VIEWS_IN_SESSION_PARAM
> -                              + ", expected an integer value > 0, using 
> default value ("
> -                              + DEFAULT_NUMBER_OF_VIEWS_IN_SESSION + "): 
> " + e.getMessage(), e);
> -                }
> -            }
> -            return views;
> -        }
> -
> -        /**
> -         * @return old serialized views map
> -         */
> -        @SuppressWarnings("unchecked")
> -        protected Map<Object, Object> getOldSerializedViewsMap()
> -        {
> -            FacesContext context = FacesContext.getCurrentInstance();
> -            if (_oldSerializedViews == null && context != null)
> -            {
> -                String cacheMode = getCacheOldViewsInSessionMode(context); 
> -                if (CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK.equals(cacheMode))
> -                {
> -                    _oldSerializedViews = new 
> ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK, true);
> -                }
> -                else if 
> (CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK.equals(cacheMode))
> -                {
> -                    _oldSerializedViews = new 
> ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.WEAK, true);
> -                }
> -                else if 
> (CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT.equals(cacheMode))
> -                {
> -                    _oldSerializedViews = new 
> ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT, true);
> -                }
> -                else if 
> (CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT.equals(cacheMode))
> -                {
> -                    _oldSerializedViews = new 
> ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
> -                }
> -            }
> -            
> -            return _oldSerializedViews;
> -        }
> -        
> -        /**
> -         * Reads the value of the 
> <code>org.apache.myfaces.CACHE_OLD_VIEWS_IN_SESSION_MODE</code> 
> context parameter.
> -         * 
> -         * @since 1.2.5
> -         * @param context
> -         * @return constant indicating caching mode
> -         * @see #CACHE_OLD_VIEWS_IN_SESSION_MODE
> -         */
> -        protected String getCacheOldViewsInSessionMode(FacesContext context)
> -        {
> -            String value = context.getExternalContext().getInitParameter(
> -                    CACHE_OLD_VIEWS_IN_SESSION_MODE);
> -            if (value == null)
> -            {
> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF;
> -            }
> -            else if 
> (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT))
> -            {
> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT;
> -            }
> -            else if 
> (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK))
> -            {
> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_SOFT_WEAK;
> -            }            
> -            else if 
> (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK))
> -            {
> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_WEAK;
> -            }
> -            else if 
> (value.equalsIgnoreCase(CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT))
> -            {
> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_HARD_SOFT;
> -            }
> -            else
> -            {
> -                return CACHE_OLD_VIEWS_IN_SESSION_MODE_OFF;
> -            }
> -        }
> -        
> -        public Object get(SerializedViewKey key)
> -        {
> -            Object value = _serializedViews.get(key);
> -            if (value == null)
> -            {
> -                if (_serializedViews.containsKey(key))
> -                {
> -                    return EMPTY_STATES;
> -                }
> -                Map<Object,Object> oldSerializedViewMap = 
> getOldSerializedViewsMap();
> -                if (oldSerializedViewMap != null)
> -                {
> -                    value = oldSerializedViewMap.get(key);
> -                    if (value == null && 
> oldSerializedViewMap.containsKey(key) )
> -                    {
> -                        return EMPTY_STATES;
> -                    }
> -                }
> -            }
> -            else if (value instanceof Object[] &&
> -                ((Object[])value).length == 2 &&
> -                ((Object[])value)[0] == null &&
> -                ((Object[])value)[1] == null)
> -            {
> -                // Remember inside the state map null is stored as an empty 
> array.
> -                return null;
> -            }
> -            return value;
> -        }
> -    }
> -
> -    /**
> -     * Base implementation where all keys used to identify the state of a view 
> should
> -     * extend.
> -     */
> -    protected abstract static class SerializedViewKey implements Serializable
> -    {
> -    }
> -
> -    /**
> -     * Implementation of SerializedViewKey, where the hashCode of the viewId is 
> used
> -     * and the sequenceId is a numeric value.
> -     */
> -    private static class IntIntSerializedViewKey extends SerializedViewKey 
> -        implements Serializable
> -    {
> -        private static final long serialVersionUID = -1170697124386063642L;
> -        
> -        private final int _viewId;
> -        private final int _sequenceId;
> -        
> -        public IntIntSerializedViewKey(int viewId, int sequence)
> -        {
> -            _sequenceId = sequence;
> -            _viewId = viewId;
> -        }
> -
> -        @Override
> -        public boolean equals(Object obj)
> -        {
> -            if (obj == null)
> -            {
> -                return false;
> -            }
> -            if (getClass() != obj.getClass())
> -            {
> -                return false;
> -            }
> -            final IntIntSerializedViewKey other = (IntIntSerializedViewKey) 
> obj;
> -            if (this._viewId != other._viewId)
> -            {
> -                return false;
> -            }
> -            if (this._sequenceId != other._sequenceId)
> -            {
> -                return false;
> -            }
> -            return true;
> -        }
> -
> -        @Override
> -        public int hashCode()
> -        {
> -            int hash = 7;
> -            hash = 83 * hash + this._viewId;
> -            hash = 83 * hash + this._sequenceId;
> -            return hash;
> -        }
> -    }
> -
> -    /**
> -     * Implementation of SerializedViewKey, where the hashCode of the viewId is 
> used
> -     * and the sequenceId is a string value.
> -     */
> -    private static class IntByteArraySerializedViewKey extends 
> SerializedViewKey
> -        implements Serializable
> -    {
> -        private final int _viewId;
> -        private final byte[] _sequenceId;
> -        
> -        public IntByteArraySerializedViewKey(int viewId, byte[] sequence)
> -        {
> -            _sequenceId = sequence;
> -            _viewId = viewId;
> -        }
> -
> -        @Override
> -        public boolean equals(Object obj)
> -        {
> -            if (obj == null)
> -            {
> -                return false;
> -            }
> -            if (getClass() != obj.getClass())
> -            {
> -                return false;
> -            }
> -            final IntByteArraySerializedViewKey other = 
> (IntByteArraySerializedViewKey) obj;
> -            if (this._viewId != other._viewId)
> -            {
> -                return false;
> -            }
> -            if (!Arrays.equals(this._sequenceId, other._sequenceId))
> -            {
> -                return false;
> -            }
> -            return true;
> -        }
> -
> -        @Override
> -        public int hashCode()
> -        {
> -            int hash = 5;
> -            hash = 37 * hash + this._viewId;
> -            hash = 37 * hash + Arrays.hashCode(this._sequenceId);
> -            return hash;
> -        }
> -    }
> -    
> -    
> -    /**
> -     * Implementation of SerializedViewKey, where the viewId and the sequenceId 
> can be
> -     * anything.
> -     */
> -    private static class ReferenceSerializedViewKey<I,K> extends 
> SerializedViewKey
> -        implements Serializable
> -    {
> -        private static final long serialVersionUID = -1170697124386063642L;
> -
> -        private final I _viewId;
> -        private final K _sequenceId;
> -
> -        public ReferenceSerializedViewKey()
> -        {
> -            _sequenceId = null;
> -            _viewId = null;
> -        }
> -        public ReferenceSerializedViewKey(I viewId, K sequence)
> -        {
> -            _sequenceId = sequence;
> -            _viewId = viewId;
> -        }
> -
> -        @Override
> -        public boolean equals(Object obj)
> -        {
> -            if (obj == null)
> -            {
> -                return false;
> -            }
> -            if (getClass() != obj.getClass())
> -            {
> -                return false;
> -            }
> -            final ReferenceSerializedViewKey<I, K> other = 
> (ReferenceSerializedViewKey<I, K>) obj;
> -            if (this._viewId != other._viewId && (this._viewId == null 
> || !this._viewId.equals(other._viewId)))
> -            {
> -                return false;
> -            }
> -            if (this._sequenceId != other._sequenceId && 
> -                (this._sequenceId == null || 
> !this._sequenceId.equals(other._sequenceId)))
> -            {
> -                return false;
> -            }
> -            return true;
> -        }
> -
> -        @Override
> -        public int hashCode()
> -        {
> -            int hash = 7;
> -            hash = 83 * hash + (this._viewId != null ? this._viewId.hashCode() 
> : 0);
> -            hash = 83 * hash + (this._sequenceId != null ? 
> this._sequenceId.hashCode() : 0);
> -            return hash;
> -        }
> -    }
> -    
>      //------------------------------------- METHOD FROM StateCache 
> ------------------------------------------------
> 
>      @Override
> @@ -1103,349 +657,4 @@ class ServerSideStateCacheImpl extends S
>      {
>          return sessionViewStorageFactory;
>      }
> -            
> -
> -    protected abstract static class KeyFactory<K, V>
> -    {
> -        
> -        /**
> -         * Generates a unique key per session 
> -         * 
> -         * @param facesContext
> -         * @return 
> -         */
> -        public abstract K generateKey(FacesContext facesContext);
> -        
> -        /**
> -         * Encode a Key into a value that will be used as view state session 
> token
> -         * 
> -         * @param key
> -         * @return 
> -         */
> -        public abstract V encode(K key);
> -
> -        /**
> -         * Decode a view state session token into a key
> -         * 
> -         * @param value
> -         * @return 
> -         */
> -        public abstract K decode(V value);
> -
> -    }
> -
> -    private static class CounterKeyFactory extends KeyFactory<Integer, 
> String>
> -    {
> -        /**
> -         * Take the counter from session scope and increment
> -         * 
> -         * @param facesContext
> -         * @return 
> -         */
> -        @Override
> -        public Integer generateKey(FacesContext facesContext)
> -        {
> -            ExternalContext externalContext = 
> facesContext.getExternalContext();
> -            Object sessionObj = externalContext.getSession(true);
> -            Integer sequence = null;
> -            synchronized(sessionObj) // synchronized to increase sequence if 
> multiple requests
> -                                    // are handled at the same time for the 
> session
> -            {
> -                Map<String, Object> map = 
> externalContext.getSessionMap();
> -                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
> -                if(sequence == null || sequence.intValue() == 
> Integer.MAX_VALUE)
> -                {
> -                    sequence = Integer.valueOf(1);
> -                }
> -                else
> -                {
> -                    sequence = Integer.valueOf(sequence.intValue() + 1);
> -                }
> -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
> -            }
> -            return sequence;
> -        }
> -        
> -        public String encode(Integer sequence)
> -        {
> -            return Integer.toString(sequence, Character.MAX_RADIX);
> -        }
> -                
> -        public Integer decode(String serverStateId)
> -        {
> -             return Integer.valueOf((String) serverStateId, 
> Character.MAX_RADIX);
> -        }
> -    }
> -    
> -    /**
> -     * This factory generate a key composed by a counter and a random number. 
> The
> -     * counter ensures uniqueness, and the random number prevents guess the 
> next
> -     * session token.
> -     */
> -    private static class SecureRandomKeyFactory extends KeyFactory<byte[], 
> String>
> -    {
> -        private final SessionIdGenerator sessionIdGenerator;
> -        private final int length;
> -
> -        public SecureRandomKeyFactory(FacesContext facesContext)
> -        {
> -            length = 
> WebConfigParamUtils.getIntegerInitParameter(facesContext.getExternalContext(),
> -                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM, 
> -                    
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT);
> -            sessionIdGenerator = new SessionIdGenerator();
> -            sessionIdGenerator.setSessionIdLength(length);
> -            String secureRandomClass = 
> WebConfigParamUtils.getStringInitParameter(
> -                    facesContext.getExternalContext(),
> -                    
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_CLASS_PARAM);
> -            if (secureRandomClass != null)
> -            {
> -                sessionIdGenerator.setSecureRandomClass(secureRandomClass);
> -            }
> -            String secureRandomProvider = 
> WebConfigParamUtils.getStringInitParameter(
> -                    facesContext.getExternalContext(),
> -                    
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_PROVIDER_PARAM);
> -            if (secureRandomProvider != null)
> -            {
> -                
> sessionIdGenerator.setSecureRandomProvider(secureRandomProvider);
> -            }
> -            String secureRandomAlgorithm = 
> WebConfigParamUtils.getStringInitParameter(
> -                    facesContext.getExternalContext(), 
> -                    
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_SECURE_RANDOM_ALGORITM_PARAM);
> -            if (secureRandomAlgorithm != null)
> -            {
> -                
> sessionIdGenerator.setSecureRandomAlgorithm(secureRandomAlgorithm);
> -            }
> -        }
> -        
> -        public Integer generateCounterKey(FacesContext facesContext)
> -        {
> -            ExternalContext externalContext = 
> facesContext.getExternalContext();
> -            Object sessionObj = externalContext.getSession(true);
> -            Integer sequence = null;
> -            synchronized(sessionObj) // synchronized to increase sequence if 
> multiple requests
> -                                    // are handled at the same time for the 
> session
> -            {
> -                Map<String, Object> map = 
> externalContext.getSessionMap();
> -                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
> -                if(sequence == null || sequence.intValue() == 
> Integer.MAX_VALUE)
> -                {
> -                    sequence = Integer.valueOf(1);
> -                }
> -                else
> -                {
> -                    sequence = Integer.valueOf(sequence.intValue() + 1);
> -                }
> -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
> -            }
> -            return sequence;
> -        }
> -
> -        @Override
> -        public byte[] generateKey(FacesContext facesContext)
> -        {
> -            byte[] array = new byte[length];
> -            byte[] key = new byte[length+4];
> -            
> -            sessionIdGenerator.getRandomBytes(array);
> -            for (int i = 0; i < array.length; i++)
> -            {
> -                key[i] = array[i];
> -            }
> -            int value = generateCounterKey(facesContext);
> -            key[array.length] =  (byte) (value >>> 24);
> -            key[array.length+1] =  (byte) (value >>> 16);
> -            key[array.length+2] =  (byte) (value >>> 8);
> -            key[array.length+3] =  (byte) (value);
> -            
> -            return key;
> -        }
> -
> -        @Override
> -        public String encode(byte[] key)
> -        {
> -            return new String(Hex.encodeHex(key));
> -        }
> -        
> -        @Override
> -        public byte[] decode(String value)
> -        {
> -            try
> -            {
> -                return Hex.decodeHex(value.toCharArray());
> -            }
> -            catch (DecoderException ex)
> -            {
> -                // Cannot decode, ignore silently, later it will be handled as
> -                // ViewExpiredException
> -            }
> -            return null;
> -        }
> -    }
> -    
> -    private static class RandomKeyFactory extends KeyFactory<byte[], 
> String>
> -    {
> -        private final Random random;
> -        private final int length;
> -        
> -        public RandomKeyFactory(FacesContext facesContext)
> -        {
> -            length = 
> WebConfigParamUtils.getIntegerInitParameter(facesContext.getExternalContext(),
> -                    RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM, 
> -                    
> RANDOM_KEY_IN_VIEW_STATE_SESSION_TOKEN_LENGTH_PARAM_DEFAULT);
> -            random = new Random(((int)System.nanoTime())+this.hashCode());
> -        }
> -        
> -        public Integer generateCounterKey(FacesContext facesContext)
> -        {
> -            ExternalContext externalContext = 
> facesContext.getExternalContext();
> -            Object sessionObj = externalContext.getSession(true);
> -            Integer sequence = null;
> -            synchronized(sessionObj) // synchronized to increase sequence if 
> multiple requests
> -                                    // are handled at the same time for the 
> session
> -            {
> -                Map<String, Object> map = 
> externalContext.getSessionMap();
> -                sequence = (Integer) map.get(RendererUtils.SEQUENCE_PARAM);
> -                if(sequence == null || sequence.intValue() == 
> Integer.MAX_VALUE)
> -                {
> -                    sequence = Integer.valueOf(1);
> -                }
> -                else
> -                {
> -                    sequence = Integer.valueOf(sequence.intValue() + 1);
> -                }
> -                map.put(RendererUtils.SEQUENCE_PARAM, sequence);
> -            }
> -            return sequence;
> -        }
> -
> -        @Override
> -        public byte[] generateKey(FacesContext facesContext)
> -        {
> -            byte[] array = new byte[length];
> -            byte[] key = new byte[length+4];
> -            
> -            //sessionIdGenerator.getRandomBytes(array);
> -            random.nextBytes(array);
> -            for (int i = 0; i < array.length; i++)
> -            {
> -                key[i] = array[i];
> -            }
> -            int value = generateCounterKey(facesContext);
> -            key[array.length] =  (byte) (value >>> 24);
> -            key[array.length+1] =  (byte) (value >>> 16);
> -            key[array.length+2] =  (byte) (value >>> 8);
> -            key[array.length+3] =  (byte) (value);
> -
> -            return key;
> -        }
> -
> -        @Override
> -        public String encode(byte[] key)
> -        {
> -            return new String(Hex.encodeHex(key));
> -        }
> -        
> -        @Override
> -        public byte[] decode(String value)
> -        {
> -            try
> -            {
> -                return Hex.decodeHex(value.toCharArray());
> -            }
> -            catch (DecoderException ex)
> -            {
> -                // Cannot decode, ignore silently, later it will be handled as
> -                // ViewExpiredException
> -            }
> -            return null;
> -        }
> -    }
> -    
> -    /**
> -     * 
> -     * @param <T>
> -     * @param <K>
> -     * @param <V> 
> -     */
> -    protected abstract static class SessionViewStorageFactory <T extends 
> KeyFactory<K,V>, K, V >
> -    {
> -        private KeyFactory<K, V> keyFactory;
> -        
> -        public SessionViewStorageFactory(KeyFactory<K, V> keyFactory)
> -        {
> -            this.keyFactory = keyFactory;
> -        }
> -        
> -        public KeyFactory<K, V> getKeyFactory()
> -        {
> -            return keyFactory;
> -        }
> -        
> -        public abstract SerializedViewCollection 
> createSerializedViewCollection(
> -                FacesContext context);
> -        
> -        public abstract SerializedViewKey createSerializedViewKey(
> -                FacesContext facesContext, String viewId, K key);
> -        
> -    }
> -    
> -    private static class CounterSessionViewStorageFactory 
> -        extends SessionViewStorageFactory <KeyFactory 
> <Integer,String>, Integer, String>
> -    {
> -        public CounterSessionViewStorageFactory(KeyFactory<Integer, 
> String> keyFactory)
> -        {
> -            super(keyFactory);
> -        }
> -
> -        @Override
> -        public SerializedViewCollection createSerializedViewCollection(
> -                FacesContext context)
> -        {
> -            return new SerializedViewCollection();
> -        }
> -
> -        @Override
> -        public SerializedViewKey createSerializedViewKey(
> -                FacesContext context, String viewId, Integer key)
> -        {
> -            if (context.isProjectStage(ProjectStage.Production))
> -            {
> -                return new IntIntSerializedViewKey(viewId == null ? 0 : 
> viewId.hashCode(), key);
> -            }
> -            else
> -            {
> -                return new ReferenceSerializedViewKey(viewId, key);
> -            }
> -        }
> -    }
> -    
> -    private static class RandomSessionViewStorageFactory
> -        extends SessionViewStorageFactory <KeyFactory <byte[],String>, 
> byte[], String>
> -    {
> -        public RandomSessionViewStorageFactory(KeyFactory<byte[], String> 
> keyFactory)
> -        {
> -            super(keyFactory);
> -        }
> -
> -        @Override
> -        public SerializedViewCollection createSerializedViewCollection(
> -                FacesContext context)
> -        {
> -            return new SerializedViewCollection();
> -        }
> -
> -        @Override
> -        public SerializedViewKey createSerializedViewKey(
> -                FacesContext context, String viewId, byte[] key)
> -        {
> -            if (context.isProjectStage(ProjectStage.Production))
> -            {
> -                return new IntByteArraySerializedViewKey(viewId == null ? 0 : 
> viewId.hashCode(), key);
> -            }
> -            else
> -            {
> -                return new ReferenceSerializedViewKey(viewId, key);
> -            }
> -        }
> -    }
> }
> 
> Added: 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
> URL: 
> http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java?rev=1410205&view=auto
> ==============================================================================
> --- 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java 
> (added)
> +++ 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java 
> Fri Nov 16 06:01:51 2012
> @@ -0,0 +1,48 @@
> +/*
> + * 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.application.viewstate;
> +
> +import javax.faces.context.FacesContext;
> +
> +/**
> + *
> + * @param <T>
> + * @param <K>
> + * @param <V>
> + */
> +abstract class SessionViewStorageFactory<T extends KeyFactory<K, V>, 
> K, V>
> +{
> +    private KeyFactory<K, V> keyFactory;
> +
> +    public SessionViewStorageFactory(KeyFactory<K, V> keyFactory)
> +    {
> +        this.keyFactory = keyFactory;
> +    }
> +
> +    public KeyFactory<K, V> getKeyFactory()
> +    {
> +        return keyFactory;
> +    }
> +
> +    public abstract SerializedViewCollection 
> createSerializedViewCollection(FacesContext context);
> +
> +    public abstract SerializedViewKey createSerializedViewKey(
> +        FacesContext facesContext, String viewId, K key);
> +    
> +}
> 
> Propchange: 
> myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/viewstate/SessionViewStorageFactory.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
>