From: <mb...@re...> - 2004-11-22 18:58:15
|
Author: mbooth Date: 2004-11-22 19:50:26 +0100 (Mon, 22 Nov 2004) New Revision: 121 Removed: ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/UserPrefsSessionListener.java Modified: ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/UserPrefs.java ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/ui/UserPrefsComponent.java Log: Remove lazy persistence entirely. Redirect user to non-action URL after changing a preference. Modified: ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/UserPrefs.java =================================================================== --- ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/UserPrefs.java 2004-11-22 18:49:30 UTC (rev 120) +++ ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/UserPrefs.java 2004-11-22 18:50:26 UTC (rev 121) @@ -82,7 +82,7 @@ // Matt <mb...@re...> -public class UserPrefs implements HttpSessionActivationListener { +public class UserPrefs { private static final Logger s_log = Logger.getLogger( UserPrefs.class ); private static final String COOKIE = "WAF_USER_PREFS"; @@ -209,49 +209,24 @@ } /** - * Set a preference. This will not cause the preference to be immediately - * persisted. + * Set a preference. * - * <p><strong>NB: Lazy persistence is not currently working, so this will - * persist immediately for the time being.</strong></p> - * * @param key The identifier of the preference to be stored * @param value The value of the preference to be stored */ public void set( String key, String value ) { m_prefs.put( key, value ); - - // XXX: remove the line below when lazy persistence works getPersistent().setValue( key, value ); } /** - * Set a preference. Optionally save the preference immediately. + * Remove a user preference. * - * <p><strong>NB: Lazy persistence is not currently working, so this will - * persist immediately for the time being.</strong></p> - * - * @param key The identifier of the preference to be stored - * @param value The value of the preference to be stored - * @param persist true if the value is to be immediately saved - */ - public void set( String key, String value, boolean persist ) { - set( key, value ); - - //if( persist ) { - getPersistent().setValue( key, value ); - //} - } - - /** - * Remove a user preference. This change will not be saved immediately. - * * @param key The identifier of the preference to be removed */ public void remove( String key ) { m_prefs.remove( key ); - // XXX: remove the line below when lazy persistence works if( !m_prefs.isEmpty() ) { getPersistent().removeValue( key ); } else { @@ -260,27 +235,6 @@ } /** - * Remove a user preference. Optionally save this change immediately. - * - * <p><strong>NB: Lazy persistence is not currently working, so this will - * persist immediately for the time being.</strong></p> - * - * @param key The identifier of the preference to be removed - * @param persist true if the change is to be immediately saved - */ - public void remove( String key, boolean persist ) { - remove( key ); - - //if( persist ) { - if( !m_prefs.isEmpty() ) { - getPersistent().removeValue( key ); - } else { - getPersistent().delete(); - } - //} - } - - /** * Save user preferences to the database */ public void persist() { @@ -293,16 +247,6 @@ s_log.debug( "Session persisted" ); } - public void sessionDidActivate(HttpSessionEvent event) { - // Not interested in this event - s_log.debug( "Session activated" ); - } - - public void sessionWillPassivate(HttpSessionEvent event) { - s_log.debug( "Session about to be passivated" ); - persist(); - } - /** * Get a PersistentUserPrefs object. Create one if necessary. */ Deleted: ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/UserPrefsSessionListener.java =================================================================== --- ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/UserPrefsSessionListener.java 2004-11-22 18:49:30 UTC (rev 120) +++ ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/UserPrefsSessionListener.java 2004-11-22 18:50:26 UTC (rev 121) @@ -1,46 +0,0 @@ -/* -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public License -as published by the Free Software Foundation; either version 2.1 of -the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -package com.arsdigita.london.userprefs; - -import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpSessionEvent; -import javax.servlet.http.HttpSessionListener; - -import org.apache.log4j.Logger; - -public class UserPrefsSessionListener implements HttpSessionListener { - private static final Logger s_log = - Logger.getLogger( UserPrefsSessionListener.class ); - - public void sessionCreated( HttpSessionEvent se ) { - s_log.debug( "Session created" ); - } - - public void sessionDestroyed( HttpSessionEvent se ) { - s_log.debug( "Session destroyed" ); - - HttpSession session = se.getSession(); - - try { - UserPrefs prefs = (UserPrefs) session.getAttribute - ( UserPrefs.SESSION_ATTRIBUTE ); - prefs.persist(); - } catch( Throwable t ) { - s_log.error( t ); - } - } -} Modified: ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/ui/UserPrefsComponent.java =================================================================== --- ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/ui/UserPrefsComponent.java 2004-11-22 18:49:30 UTC (rev 120) +++ ccm-user-preferences/trunk/src/com/arsdigita/london/userprefs/ui/UserPrefsComponent.java 2004-11-22 18:50:26 UTC (rev 121) @@ -25,8 +25,11 @@ import com.arsdigita.bebop.event.RequestListener; import com.arsdigita.bebop.parameters.BooleanParameter; import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.util.UncheckedWrapperException; +import com.arsdigita.web.RedirectSignal; import com.arsdigita.xml.Element; +import java.io.IOException; import java.util.Iterator; import java.util.Map; @@ -84,24 +87,31 @@ String setKey = (String) ps.getValue( m_setKey ); String setValue = (String) ps.getValue( m_setValue ); String remove = (String) ps.getValue( m_remove ); - Boolean immediate = (Boolean) ps.getValue( m_immediate ); UserPrefs prefs = UserPrefs.retrieve( ps.getRequest(), ps.getResponse() ); + boolean acted = false; + if( null != setKey ) { - if( Boolean.TRUE.equals( immediate ) ) { - prefs.set( setKey, setValue, true ); - } else { - prefs.set( setKey, setValue ); - } + prefs.set( setKey, setValue ); + acted = true; } if( null != remove ) { - if( Boolean.TRUE.equals( immediate ) ) { - prefs.remove( remove, true ); - } else { - prefs.remove( remove ); + prefs.remove( remove ); + acted = true; + } + + if( acted ) { + ps.setValue( m_setKey, null ); + ps.setValue( m_setValue, null ); + ps.setValue( m_remove, null ); + + try { + throw new RedirectSignal( ps.stateAsURL(), true ); + } catch( IOException ex ) { + throw new UncheckedWrapperException( ex ); } } } |