1 18 package org.apache.beehive.netui.pageflow.interceptor.action; 19 20 import org.apache.beehive.netui.util.logging.Logger; 21 import org.apache.beehive.netui.pageflow.Forward; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import java.util.Enumeration ; 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.io.Serializable ; 29 30 class OriginalForward extends InterceptorForward 31 { 32 private Map _savedAttrs; 33 34 private static final Logger _log = Logger.getInstance( OriginalForward.class ); 35 36 37 OriginalForward( Forward fwd, HttpServletRequest request ) 38 { 39 super( fwd ); 40 saveRequestAttrs( request ); 41 } 42 43 OriginalForward( HttpServletRequest request ) 44 { 45 super( request ); 46 saveRequestAttrs( request ); 47 } 48 49 private void saveRequestAttrs( HttpServletRequest request ) 50 { 51 _savedAttrs = new HashMap (); 52 53 for ( Enumeration e = request.getAttributeNames(); e.hasMoreElements(); ) 54 { 55 String attrName = ( String ) e.nextElement(); 56 Object attrVal = request.getAttribute( attrName ); 57 58 if ( attrVal instanceof Serializable ) 59 { 60 _savedAttrs.put( attrName, attrVal ); 61 } 62 else 63 { 64 if ( _log.isWarnEnabled() ) 65 { 66 _log.warn( "Dropping non-serializable request attribute " + attrName + " (" + attrVal + ")." ); 67 } 68 } 69 } 70 } 71 72 public void rehydrateRequest( HttpServletRequest request ) 73 { 74 if ( _savedAttrs != null ) 75 { 76 for ( Iterator i = _savedAttrs.entrySet().iterator(); i.hasNext(); ) 77 { 78 Map.Entry entry = ( Map.Entry ) i.next(); 79 80 String attrName = ( String ) entry.getKey(); 81 if ( request.getAttribute( attrName ) == null ) 82 { 83 request.setAttribute( attrName, entry.getValue() ); 84 } 85 } 86 } 87 } 88 } 89 | Popular Tags |