1 4 package org.roller.presentation; 5 6 import org.apache.struts.action.ActionMapping; 7 import org.roller.RollerException; 8 import org.roller.pojos.UserData; 9 10 import java.text.DateFormat ; 11 import java.text.SimpleDateFormat ; 12 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpServletResponse ; 15 16 20 public class BasePageModel 21 { 22 private HttpServletRequest request = null; 23 private HttpServletResponse response = null; 24 private ActionMapping mapping = null; 25 26 public BasePageModel( 27 HttpServletRequest request, 28 HttpServletResponse response, 29 ActionMapping mapping) 30 { 31 this.request = request; 32 this.response = response; 33 this.mapping = mapping; 34 } 35 36 public String getBaseURL() 37 { 38 return request.getContextPath(); 39 } 40 41 public String getShortDateFormat() 42 { 43 DateFormat sdf = DateFormat.getDateInstance( 44 DateFormat.SHORT, request.getLocale()); 45 if (sdf instanceof SimpleDateFormat ) 46 { 47 return ((SimpleDateFormat )sdf).toLocalizedPattern(); 48 } 49 return "yyyy/MM/dd"; 50 } 51 52 public String getMediumDateFormat() 53 { 54 DateFormat sdf = DateFormat.getDateInstance( 55 DateFormat.MEDIUM, request.getLocale()); 56 if (sdf instanceof SimpleDateFormat ) 57 { 58 return ((SimpleDateFormat )sdf).toLocalizedPattern(); 59 } 60 return "MMM dd, yyyy"; 61 } 62 63 public UserData getUser() 64 { 65 return RollerRequest.getRollerRequest(request).getUser(); 66 } 67 68 71 public ActionMapping getMapping() 72 { 73 return mapping; 74 } 75 76 79 public HttpServletRequest getRequest() 80 { 81 return request; 82 } 83 84 87 public HttpServletResponse getResponse() 88 { 89 return response; 90 } 91 92 public boolean getIsAdmin() throws RollerException 93 { 94 return RollerRequest.getRollerRequest(request).isAdminUser(); 95 } 96 } 97 | Popular Tags |