1 18 21 package org.apache.roller.ui.core; 22 23 import java.text.DateFormat ; 24 import java.text.SimpleDateFormat ; 25 import java.util.List ; 26 import java.util.ResourceBundle ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import org.apache.roller.config.RollerRuntimeConfig; 31 32 import org.apache.struts.action.ActionMapping; 33 import org.apache.roller.pojos.WebsiteData; 34 import org.apache.roller.ui.core.util.StrutsUtil; 35 36 40 public class BasePageModel 41 { 42 protected static ResourceBundle bundle = 43 ResourceBundle.getBundle("ApplicationResources"); 44 45 protected String titleKey = null; 46 protected HttpServletRequest request = null; 47 protected HttpServletResponse response = null; 48 protected ActionMapping mapping = null; 49 protected WebsiteData website = null; 50 51 public BasePageModel( 52 String titleKey, 53 HttpServletRequest request, 54 HttpServletResponse response, 55 ActionMapping mapping) 56 { 57 this.request = request; 58 this.response = response; 59 this.mapping = mapping; 60 this.titleKey = titleKey; 61 request.setAttribute("locales", StrutsUtil.getLocaleBeans()); 62 request.setAttribute("timeZones", StrutsUtil.getTimeZoneBeans()); 63 RollerRequest rreq = RollerRequest.getRollerRequest(request); 64 website = rreq.getWebsite(); 65 } 66 67 public WebsiteData getWebsite() 68 { 69 return website; 70 } 71 72 public void setWebsite(WebsiteData website) 73 { 74 this.website = website; 75 } 76 77 public String getTitle() 78 { 79 return bundle.getString(titleKey); 80 } 81 82 public String getBaseURL() 83 { 84 return RollerRuntimeConfig.getRelativeContextURL(); 85 } 86 87 public String getShortDateFormat() 88 { 89 DateFormat sdf = DateFormat.getDateInstance( 90 DateFormat.SHORT, request.getLocale()); 91 if (sdf instanceof SimpleDateFormat ) 92 { 93 return ((SimpleDateFormat )sdf).toLocalizedPattern(); 94 } 95 return "yyyy/MM/dd"; 96 } 97 98 public String getMediumDateFormat() 99 { 100 DateFormat sdf = DateFormat.getDateInstance( 101 DateFormat.MEDIUM, request.getLocale()); 102 if (sdf instanceof SimpleDateFormat ) 103 { 104 return ((SimpleDateFormat )sdf).toLocalizedPattern(); 105 } 106 return "MMM dd, yyyy"; 107 } 108 109 112 public ActionMapping getMapping() 113 { 114 return mapping; 115 } 116 117 120 public HttpServletRequest getRequest() 121 { 122 return request; 123 } 124 125 128 public HttpServletResponse getResponse() 129 { 130 return response; 131 } 132 133 public RollerSession getRollerSession() 134 { 135 return RollerSession.getRollerSession(request); 136 } 137 138 public List getLocales() 139 { 140 return StrutsUtil.getLocaleBeans(); 141 } 142 143 public List getTimeZones() 144 { 145 return StrutsUtil.getTimeZoneBeans(); 146 } 147 148 } 149 | Popular Tags |