1 package fr.improve.struts.taglib.layout.sort; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 import org.apache.struts.action.ActionForm; 9 import org.apache.struts.action.ActionForward; 10 import org.apache.struts.action.ActionMapping; 11 15 public class SortAction extends org.apache.struts.action.Action { 16 19 private static final String SORT_ERROR_URL = "sortError"; 20 21 24 protected static Log log = LogFactory.getLog(SortAction.class); 25 26 29 protected SortUtil getSortUtil(HttpServletRequest in_request) { 30 return (SortUtil) in_request.getSession().getAttribute(SortUtil.SORTUTIL_KEY); 31 } 32 public ActionForward execute( 33 ActionMapping in_mapping, 34 ActionForm in_form, 35 HttpServletRequest in_request, 36 HttpServletResponse in_response) { 37 38 SortUtil lc_sortUtil = getSortUtil(in_request); 39 String lc_url = SORT_ERROR_URL; 40 41 if (lc_sortUtil!=null) { 43 try { 44 lc_url = lc_sortUtil.sort(in_request); 45 } catch (SortException e) { 46 log.error("Sort failed", e); 47 lc_url = SORT_ERROR_URL; 48 } 49 } else { 50 log.error("Unable to sort : SortUtil is null, maybe because there has been a session timeout"); 51 } 52 53 if (lc_url.startsWith(in_request.getContextPath() + '/')) { 54 lc_url = lc_url.substring(in_request.getContextPath().length()); 55 } 56 if (lc_url.indexOf('.')!=-1 && lc_url.indexOf('?')!=-1) { 57 lc_url = lc_url.substring(0, lc_url.indexOf('?')); 58 } 59 60 ActionForward lc_forward = null; 61 if (SORT_ERROR_URL.equals(lc_url)) { 62 lc_forward = in_mapping.findForward(SORT_ERROR_URL); 63 if (lc_forward==null) { 64 log.error("Sort failed, but forward sortError is not defined, so no error page can be displayed"); 65 } 66 } else { 67 lc_forward = new ActionForward(lc_url); 68 } 69 70 return lc_forward; 71 72 } 73 } 74 | Popular Tags |