You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ga...@apache.org on 2011/03/11 10:56:15 UTC
svn commit: r1080499 - in
/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash:
FlashImpl.java FlashScopeDisabledException.java
Author: ganesh
Date: Fri Mar 11 09:56:14 2011
New Revision: 1080499
URL: http://svn.apache.org/viewvc?rev=1080499&view=rev
Log:
JIRA 3005: add config param org.apache.myfaces.FLASH_SCOPE_DISABLED, skip pre- and postPhaseActions if true and throw FlashScopeDisabledException if true and one of the public Map access methods is used.
Added:
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashScopeDisabledException.java (with props)
Modified:
myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java
Modified: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java?rev=1080499&r1=1080498&r2=1080499&view=diff
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java (original)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashImpl.java Fri Mar 11 09:56:14 2011
@@ -18,6 +18,7 @@
*/
package org.apache.myfaces.shared.context.flash;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
import org.apache.myfaces.shared.util.ExternalContextUtils;
import javax.faces.application.FacesMessage;
@@ -38,6 +39,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -55,6 +57,12 @@ public class FlashImpl extends Flash
private static final Logger logger = Logger.getLogger(FlashImpl.class.getName());
/**
+ * Defines whether flash scope is disabled.
+ */
+ @JSFWebConfigParam(defaultValue="false",since="2.05")
+ private static final String FLASH_SCOPE_DISABLED_PARAM = "org.apache.myfaces.FLASH_SCOPE_DISABLED";
+
+ /**
* Use this prefix instead of the whole class name, because
* this makes the Cookies and the SubKeyMap operations (actually
* every String based operation where this is used as a key) faster.
@@ -180,10 +188,26 @@ public class FlashImpl extends Flash
// the current token value
private final AtomicLong _count;
-
+ private boolean _flashScopeDisabled;
+
public FlashImpl()
{
_count = new AtomicLong(_getSeed());
+
+ // Read whether flash scope is disabled.
+ String value = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(FLASH_SCOPE_DISABLED_PARAM);
+ if (value != null)
+ {
+ try
+ {
+ _flashScopeDisabled = Boolean.parseBoolean(value);
+ }
+ catch (Throwable e)
+ {
+ logger.log(Level.SEVERE, "Error determining the value for " + FLASH_SCOPE_DISABLED_PARAM
+ + ", expected true/false, using default value (false): " + e.getMessage(), e);
+ }
+ }
}
// ~ methods from javax.faces.context.Flash -------------------------------
@@ -196,21 +220,24 @@ public class FlashImpl extends Flash
@Override
public void doPrePhaseActions(FacesContext facesContext)
{
- final PhaseId currentPhaseId = facesContext.getCurrentPhaseId();
-
- if (PhaseId.RESTORE_VIEW.equals(currentPhaseId))
+ if (!_flashScopeDisabled)
{
- // restore the redirect value
- // note that the result of this method is used in many places,
- // thus it has to be the first thing to do
- _restoreRedirectValue(facesContext);
+ final PhaseId currentPhaseId = facesContext.getCurrentPhaseId();
+
+ if (PhaseId.RESTORE_VIEW.equals(currentPhaseId))
+ {
+ // restore the redirect value
+ // note that the result of this method is used in many places,
+ // thus it has to be the first thing to do
+ _restoreRedirectValue(facesContext);
- // restore the FlashMap token from the previous request
- // and create a new token for this request
- _manageFlashMapTokens(facesContext);
+ // restore the FlashMap token from the previous request
+ // and create a new token for this request
+ _manageFlashMapTokens(facesContext);
- // try to restore any saved messages
- _restoreMessages(facesContext);
+ // try to restore any saved messages
+ _restoreMessages(facesContext);
+ }
}
}
@@ -222,33 +249,36 @@ public class FlashImpl extends Flash
@Override
public void doPostPhaseActions(FacesContext facesContext)
{
- // do the actions only if this is the last time
- // doPostPhaseActions() is called on this request
- if (_isLastPhaseInRequest(facesContext))
+ if (!_flashScopeDisabled)
{
- if (_isRedirectTrueOnThisRequest(facesContext))
+ // do the actions only if this is the last time
+ // doPostPhaseActions() is called on this request
+ if (_isLastPhaseInRequest(facesContext))
{
- // copy entries from executeMap to renderMap, if they do not exist
- Map<String, Object> renderMap = _getRenderFlashMap(facesContext);
-
- for (Map.Entry<String, Object> entry
- : _getExecuteFlashMap(facesContext).entrySet())
+ if (_isRedirectTrueOnThisRequest(facesContext))
{
- if (!renderMap.containsKey(entry.getKey()))
+ // copy entries from executeMap to renderMap, if they do not exist
+ Map<String, Object> renderMap = _getRenderFlashMap(facesContext);
+
+ for (Map.Entry<String, Object> entry
+ : _getExecuteFlashMap(facesContext).entrySet())
{
- renderMap.put(entry.getKey(), entry.getValue());
+ if (!renderMap.containsKey(entry.getKey()))
+ {
+ renderMap.put(entry.getKey(), entry.getValue());
+ }
}
}
- }
- // remove execute Map entries from session (--> "destroy" executeMap)
- _clearExecuteFlashMap(facesContext);
+ // remove execute Map entries from session (--> "destroy" executeMap)
+ _clearExecuteFlashMap(facesContext);
- // save the current FacesMessages in the renderMap, if wanted
- // Note that this also works on a redirect even though the redirect
- // was already performed and the response has already been committed,
- // because the renderMap is stored in the session.
- _saveMessages(facesContext);
+ // save the current FacesMessages in the renderMap, if wanted
+ // Note that this also works on a redirect even though the redirect
+ // was already performed and the response has already been committed,
+ // because the renderMap is stored in the session.
+ _saveMessages(facesContext);
+ }
}
}
@@ -321,6 +351,7 @@ public class FlashImpl extends Flash
@Override
public void keep(String key)
{
+ _checkFlashScopeDisabled();
FacesContext facesContext = FacesContext.getCurrentInstance();
Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap();
Object value = requestMap.get(key);
@@ -352,6 +383,7 @@ public class FlashImpl extends Flash
@Override
public void putNow(String key, Object value)
{
+ _checkFlashScopeDisabled();
FacesContext.getCurrentInstance().getExternalContext()
.getRequestMap().put(key, value);
}
@@ -397,26 +429,31 @@ public class FlashImpl extends Flash
public void clear()
{
+ _checkFlashScopeDisabled();
_getFlashMapForWriting().clear();
}
public boolean containsKey(Object key)
{
+ _checkFlashScopeDisabled();
return _getFlashMapForReading().containsKey(key);
}
public boolean containsValue(Object value)
{
+ _checkFlashScopeDisabled();
return _getFlashMapForReading().containsValue(value);
}
public Set<java.util.Map.Entry<String, Object>> entrySet()
{
+ _checkFlashScopeDisabled();
return _getFlashMapForReading().entrySet();
}
public Object get(Object key)
{
+ _checkFlashScopeDisabled();
if (key == null)
{
return null;
@@ -436,16 +473,19 @@ public class FlashImpl extends Flash
public boolean isEmpty()
{
+ _checkFlashScopeDisabled();
return _getFlashMapForReading().isEmpty();
}
public Set<String> keySet()
{
+ _checkFlashScopeDisabled();
return _getFlashMapForReading().keySet();
}
public Object put(String key, Object value)
{
+ _checkFlashScopeDisabled();
if (key == null)
{
return null;
@@ -471,21 +511,25 @@ public class FlashImpl extends Flash
public void putAll(Map<? extends String, ? extends Object> m)
{
+ _checkFlashScopeDisabled();
_getFlashMapForWriting().putAll(m);
}
public Object remove(Object key)
{
+ _checkFlashScopeDisabled();
return _getFlashMapForWriting().remove(key);
}
public int size()
{
+ _checkFlashScopeDisabled();
return _getFlashMapForReading().size();
}
public Collection<Object> values()
{
+ _checkFlashScopeDisabled();
return _getFlashMapForReading().values();
}
@@ -1007,6 +1051,18 @@ public class FlashImpl extends Flash
return booleanValue;
}
+ /**
+ * Checks whether flash scope is disabled.
+ * @throws FlashScopeDisabledException if flash scope is disabled
+ */
+ private void _checkFlashScopeDisabled()
+ {
+ if (_flashScopeDisabled) {
+ throw new FlashScopeDisabledException("Flash scope was disabled by context param "
+ + FLASH_SCOPE_DISABLED_PARAM + " but erroneously accessed");
+ }
+ }
+
// ~ Inner classes --------------------------------------------------------
/**
Added: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashScopeDisabledException.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashScopeDisabledException.java?rev=1080499&view=auto
==============================================================================
--- myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashScopeDisabledException.java (added)
+++ myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashScopeDisabledException.java Fri Mar 11 09:56:14 2011
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.shared.context.flash;
+
+/**
+ * @author Ganesh Jung (latest modification by $Author: $)
+ * @version $Revision: $ $Date: $
+ */
+public class FlashScopeDisabledException extends RuntimeException
+{
+
+ /**
+ *
+ */
+ public FlashScopeDisabledException()
+ {
+ }
+
+ /**
+ * @param message
+ */
+ public FlashScopeDisabledException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public FlashScopeDisabledException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public FlashScopeDisabledException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Propchange: myfaces/shared/trunk/core/src/main/java/org/apache/myfaces/shared/context/flash/FlashScopeDisabledException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain