1 18 package org.apache.beehive.netui.pageflow; 19 20 import org.apache.struts.action.ActionForward; 21 import org.apache.struts.action.ActionForm; 22 import org.apache.struts.action.ActionMapping; 23 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.http.HttpSession ; 27 import javax.servlet.ServletContext ; 28 29 import org.apache.beehive.netui.pageflow.internal.AdapterManager; 30 import org.apache.beehive.netui.pageflow.internal.InternalConstants; 31 32 33 86 public abstract class SharedFlowController 87 extends FlowController 88 implements PageFlowConstants 89 { 90 private transient String _modulePath; 91 92 97 public String getModulePath() 98 { 99 if ( _modulePath == null ) 100 { 101 String className = getClass().getName(); 102 int lastDot = className.lastIndexOf( '.' ); 103 assert lastDot != -1 : className; 104 className = className.substring( 0, lastDot ); 105 _modulePath = "/-" + className.replace( '.', '/' ); 106 } 107 108 return _modulePath; 109 } 110 111 115 public void persistInSession( HttpServletRequest request, HttpServletResponse response ) 116 { 117 request.getSession().setAttribute( InternalConstants.SHARED_FLOW_ATTR_PREFIX + getClass().getName(), this ); 118 } 119 120 128 public void ensureFailover( HttpServletRequest request ) 129 { 130 ServletContainerAdapter servletContainerAdapter = AdapterManager.getServletContainerAdapter( getServletContext() ); 131 servletContainerAdapter.ensureFailover( InternalConstants.SHARED_FLOW_ATTR_PREFIX + getClass().getName(), this, request ); 132 } 133 134 138 public String getURI() 139 { 140 return "/"; 141 } 142 143 147 public String getDisplayName() 148 { 149 return getClass().getName(); 150 } 151 152 156 public PreviousPageInfo getPreviousPageInfoLegacy( PageFlowController curJpf, HttpServletRequest request ) 157 { 158 assert curJpf != null; 159 return curJpf.getCurrentPageInfo(); 160 } 161 162 166 public void savePreviousPageInfo( ActionForward forward, ActionForm form, ActionMapping mapping, 167 HttpServletRequest request, ServletContext servletContext, 168 boolean isSpecialForward ) 169 { 170 if ( ! isSpecialForward && forward != null ) { 176 PageFlowController currentJpf = PageFlowUtils.getCurrentPageFlow( request ); 177 178 if ( currentJpf != null ) 179 { 180 if ( forward.getContextRelative() && forward.getPath().startsWith( currentJpf.getModulePath() ) ) 181 { 182 currentJpf.savePreviousPageInfo( forward, form, mapping, request, servletContext, isSpecialForward ); 183 } 184 } 185 } 186 } 187 188 192 void savePreviousActionInfo( ActionForm form, HttpServletRequest request, ActionMapping mapping, 193 ServletContext servletContext ) 194 { 195 PageFlowController currentJpf = PageFlowUtils.getCurrentPageFlow( request ); 199 if ( currentJpf != null ) currentJpf.savePreviousActionInfo( form, request, mapping, servletContext ); 200 } 201 202 205 protected synchronized void removeFromSession( HttpServletRequest request ) 206 { 207 PageFlowUtils.removeSharedFlow( getClass().getName(), request ); 208 } 209 } 210 | Popular Tags |