You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2006/09/18 11:56:26 UTC
svn commit: r447346 - in /myfaces/tomahawk/trunk/sandbox:
core/src/main/java/org/apache/myfaces/custom/redirectTracker/
core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/
examples/src/main/webapp/WEB-INF/
Author: imario
Date: Mon Sep 18 02:56:25 2006
New Revision: 447346
URL: http://svn.apache.org/viewvc?view=rev&rev=447346
Log:
fix for TOMAHAWK-672 and TOMAHAWK-503 - added policy configuration to customize the data being saved between redirects
New context configuration parameters:
org.apache.myfaces.redirectTracker.MAX_REDIRECTS - Default: 20
Number of redirects to track - required to allow the back-button to work.
org.apache.myfaces.redirectTracker.POLICY - Default: org.apache.myfaces.custom.redirectTracker.policy.NoopRedirectTrackPolicy
The policy used to describe which data to save between requests. This can be any FQN to a class implementing the RedirectTrackerPolicy.
Current implementations are:
* FullRedirectTrackPolicy
Captures request beans, local and messages
* MessagesRedirectTrackPolicy
Captures FacesMessages only
* NoopRedirectTrackPolicy
Captures nothing (the default for JSF backward compatiblity)
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerContext.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerPolicy.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/FullRedirectTrackPolicy.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/MessagesRedirectTrackPolicy.java (with props)
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/NoopRedirectTrackPolicy.java (with props)
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerManager.java
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerContext.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerContext.java?view=auto&rev=447346
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerContext.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerContext.java Mon Sep 18 02:56:25 2006
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.redirectTracker;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * Provides a context for the RedirectTrackerPolicy
+ */
+public class RedirectTrackerContext
+{
+ private final RedirectTrackerManager manager;
+ private final RedirectTrackerManager.Entry entry;
+ private final FacesContext context;
+
+ RedirectTrackerContext(RedirectTrackerManager manager, RedirectTrackerManager.Entry entry, FacesContext context)
+ {
+ this.entry = entry;
+ this.context = context;
+ this.manager = manager;
+ }
+
+ /**
+ * saves all request beans
+ */
+ public void saveBeans()
+ {
+ manager.saveBeans(entry);
+ }
+
+ /**
+ * saves the given object with the given name, after the redirect this value will be reinjected into the request.
+ */
+ public void saveBean(String name, Object value)
+ {
+ manager.saveBean(entry, name, value);
+ }
+
+ /**
+ * saves all messages
+ */
+ public void saveMessages()
+ {
+ manager.saveMessages(context, entry);
+ }
+
+ /**
+ * saves the locale information
+ */
+ public void saveLocale()
+ {
+ manager.saveLocale(context, entry);
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerContext.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerContext.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerManager.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerManager.java?view=diff&rev=447346&r1=447345&r2=447346
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerManager.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerManager.java Mon Sep 18 02:56:25 2006
@@ -17,10 +17,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.shared_tomahawk.util.ClassUtils;
+import org.apache.myfaces.custom.redirectTracker.policy.NoopRedirectTrackPolicy;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
+import javax.faces.FacesException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
@@ -35,24 +38,28 @@
*/
public class RedirectTrackerManager implements Serializable
{
+ private final static String INIT_POLICY = "org.apache.myfaces.redirectTracker.POLICY";
+ private final static String INIT_MAX_REDIRECTS = "org.apache.myfaces.redirectTracker.MAX_REDIRECTS";
+ public static final int TRACK_REDIRECTS = 20;
+
private final static Log log = LogFactory.getLog(RedirectTrackerManager.class);
public static final String SESSION_KEY = RedirectTrackerManager.class.getName();
public static final String REDIRECT_ARG = "_rtid";
- public static final int TRACK_REDIRECTS = 20; // TODO: make configureable
+ private final String redirectTrackerPolicy;
private final int redirects;
- private final Map redirectEntryMap;
- private final List redirectEntryList;
private final Map requestBeanMap = new TreeMap();
+ private transient Map redirectEntryMap;
+ private transient List redirectEntryList;
private long requests = 0;
- private static class Entry implements Serializable
+ static class Entry implements Serializable
{
private final String mapKey;
private List messages;
- private Map beanMap;
+ private Map beanMap = new TreeMap();
private Locale locale;
private Entry(String mapKey)
@@ -104,11 +111,19 @@
*
* @param redirects nuof redirects to track
*/
- public RedirectTrackerManager(int redirects)
+ public RedirectTrackerManager(final int redirects, final String redirectTrackerPolicy)
{
this.redirects = redirects;
- redirectEntryMap = new TreeMap();
- redirectEntryList = new ArrayList(redirects);
+ this.redirectTrackerPolicy = redirectTrackerPolicy;
+ }
+
+ protected void initRedirectEntryMap()
+ {
+ if (redirectEntryMap == null)
+ {
+ redirectEntryMap = new TreeMap();
+ redirectEntryList = new ArrayList(redirects);
+ }
}
/**
@@ -135,6 +150,7 @@
return false;
}
+ initRedirectEntryMap();
synchronized (redirectEntryMap)
{
return redirectEntryMap.containsKey(rtid);
@@ -154,7 +170,7 @@
RedirectTrackerManager redirectManager = (RedirectTrackerManager) sessionMap.get(SESSION_KEY);
if (redirectManager == null)
{
- redirectManager = createRedirectTrackerManager();
+ redirectManager = createRedirectTrackerManager(facesContext);
sessionMap.put(SESSION_KEY, redirectManager);
}
@@ -164,9 +180,34 @@
/**
* create a new redirect tracker
*/
- protected static RedirectTrackerManager createRedirectTrackerManager()
+ protected static RedirectTrackerManager createRedirectTrackerManager(FacesContext facesContext)
{
- return new RedirectTrackerManager(TRACK_REDIRECTS);
+ String initPolicy = (String) facesContext.getExternalContext().getInitParameter(INIT_POLICY);
+ if (initPolicy == null)
+ {
+ initPolicy = NoopRedirectTrackPolicy.class.getName();
+ if (log.isInfoEnabled())
+ {
+ log.info("No context init parameter '" + INIT_POLICY + "' found, using default value " + initPolicy);
+ }
+ }
+
+ String maxRedirects = (String) facesContext.getExternalContext().getInitParameter(INIT_MAX_REDIRECTS);
+ int numMaxRedirects;
+ if (maxRedirects == null)
+ {
+ numMaxRedirects = TRACK_REDIRECTS;
+ if (log.isInfoEnabled())
+ {
+ log.info("No context init parameter '" + INIT_MAX_REDIRECTS + "' found, using default value " + numMaxRedirects);
+ }
+ }
+ else
+ {
+ numMaxRedirects = Integer.parseInt(maxRedirects, 10);
+ }
+
+ return new RedirectTrackerManager(numMaxRedirects, initPolicy);
}
/**
@@ -180,8 +221,13 @@
Entry entry = new Entry(mapKey);
- saveBeans(entry);
- saveMessages(facesContext, entry);
+ RedirectTrackerContext context = new RedirectTrackerContext(this, entry, facesContext);
+
+ RedirectTrackerPolicy policy = getRedirectTrackerPolicy();
+ redirectPath = policy.trackRedirect(context, redirectPath);
+
+ // saveBeans(entry);
+ // saveMessages(facesContext, entry);
// prepare for next redirect
clearSaveStateBean();
@@ -192,6 +238,7 @@
return redirectPath;
}
+ initRedirectEntryMap();
synchronized (redirectEntryMap)
{
redirectEntryMap.put(mapKey, entry);
@@ -214,9 +261,34 @@
}
}
+ protected RedirectTrackerPolicy getRedirectTrackerPolicy()
+ {
+ try
+ {
+ return (RedirectTrackerPolicy) ClassUtils.classForName(redirectTrackerPolicy).newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new FacesException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new FacesException(e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new FacesException(e);
+ }
+ }
+
protected void saveBeans(Entry entry)
{
- entry.beanMap = new TreeMap(requestBeanMap);
+ entry.beanMap.putAll(requestBeanMap);
+ }
+
+ protected void saveBean(Entry entry, String name, Object value)
+ {
+ entry.beanMap.put(name, value);
}
/**
@@ -302,6 +374,7 @@
protected void setupFaces(FacesContext facesContext, Object rtid)
{
Entry entry;
+ initRedirectEntryMap();
synchronized (redirectEntryMap)
{
entry = (Entry) redirectEntryMap.get(rtid);
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerPolicy.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerPolicy.java?view=auto&rev=447346
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerPolicy.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerPolicy.java Mon Sep 18 02:56:25 2006
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.redirectTracker;
+
+/**
+ * The implementation used to save the request data
+ */
+public interface RedirectTrackerPolicy
+{
+ /**
+ * Tracks the redirect, return the new (or old, but not NULL) redirectPath used for the real redirection.
+ */
+ public String trackRedirect(RedirectTrackerContext redirectContext, String redirectPath);
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerPolicy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerPolicy.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/RedirectTrackerPolicy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/FullRedirectTrackPolicy.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/FullRedirectTrackPolicy.java?view=auto&rev=447346
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/FullRedirectTrackPolicy.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/FullRedirectTrackPolicy.java Mon Sep 18 02:56:25 2006
@@ -0,0 +1,19 @@
+package org.apache.myfaces.custom.redirectTracker.policy;
+
+import org.apache.myfaces.custom.redirectTracker.RedirectTrackerPolicy;
+import org.apache.myfaces.custom.redirectTracker.RedirectTrackerContext;
+
+/**
+ * This implementation tries to save the full request data
+ */
+public class FullRedirectTrackPolicy implements RedirectTrackerPolicy
+{
+ public String trackRedirect(RedirectTrackerContext redirectContext, String redirectPath)
+ {
+ redirectContext.saveLocale();
+ redirectContext.saveBeans();
+ redirectContext.saveMessages();
+
+ return redirectPath;
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/FullRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/FullRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/FullRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/MessagesRedirectTrackPolicy.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/MessagesRedirectTrackPolicy.java?view=auto&rev=447346
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/MessagesRedirectTrackPolicy.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/MessagesRedirectTrackPolicy.java Mon Sep 18 02:56:25 2006
@@ -0,0 +1,17 @@
+package org.apache.myfaces.custom.redirectTracker.policy;
+
+import org.apache.myfaces.custom.redirectTracker.RedirectTrackerPolicy;
+import org.apache.myfaces.custom.redirectTracker.RedirectTrackerContext;
+
+/**
+ * This implementation saves the messages only
+ */
+public class MessagesRedirectTrackPolicy implements RedirectTrackerPolicy
+{
+ public String trackRedirect(RedirectTrackerContext redirectContext, String redirectPath)
+ {
+ redirectContext.saveMessages();
+
+ return redirectPath;
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/MessagesRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/MessagesRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/MessagesRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/NoopRedirectTrackPolicy.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/NoopRedirectTrackPolicy.java?view=auto&rev=447346
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/NoopRedirectTrackPolicy.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/NoopRedirectTrackPolicy.java Mon Sep 18 02:56:25 2006
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.custom.redirectTracker.policy;
+
+import org.apache.myfaces.custom.redirectTracker.RedirectTrackerPolicy;
+import org.apache.myfaces.custom.redirectTracker.RedirectTrackerContext;
+
+/**
+ * This implementation does nothing (for backward compatibility with JSF) - the default
+ */
+public class NoopRedirectTrackPolicy implements RedirectTrackerPolicy
+{
+ public String trackRedirect(RedirectTrackerContext redirectContext, String redirectPath)
+ {
+ return redirectPath;
+ }
+}
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/NoopRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/NoopRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/redirectTracker/policy/NoopRedirectTrackPolicy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml?view=diff&rev=447346&r1=447345&r2=447346
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/WEB-INF/web.xml Mon Sep 18 02:56:25 2006
@@ -49,8 +49,15 @@
Default: "false"</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
- </context-param>
-
+ </context-param>
+ <context-param>
+ <description>Set the redirectTracker policy. You can use your own implementation by providing the
+ FQN of the class here.
+ </description>
+ <param-name>org.apache.myfaces.redirectTracker.POLICY</param-name>
+ <param-value>org.apache.myfaces.custom.redirectTracker.policy.FullRedirectTrackPolicy</param-value>
+ </context-param>
+
<filter>
<filter-name>requestParameterProviderFilter</filter-name>
<filter-class>org.apache.myfaces.custom.requestParameterProvider.RequestParameterServletFilter</filter-class>
@@ -100,7 +107,7 @@
<filter-name>conversationFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
-
+
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
@@ -111,7 +118,7 @@
<servlet-class>org.apache.myfaces.shared_tomahawk.util.servlet.SourceCodeServlet</servlet-class>
</servlet>
<!-- Spellchecker Servlet -->
-
+
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>