001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: /*
019: * Created on Mar 10, 2004
020: */
021: package org.apache.roller.ui.core;
022:
023: import java.text.DateFormat;
024: import java.text.SimpleDateFormat;
025: import java.util.List;
026: import java.util.ResourceBundle;
027:
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030: import org.apache.roller.config.RollerRuntimeConfig;
031:
032: import org.apache.struts.action.ActionMapping;
033: import org.apache.roller.pojos.WebsiteData;
034: import org.apache.roller.ui.core.util.StrutsUtil;
035:
036: /**
037: * Re-usable base for page models.
038: * @author David M Johnson
039: */
040: public class BasePageModel {
041: protected static ResourceBundle bundle = ResourceBundle
042: .getBundle("ApplicationResources");
043:
044: protected String titleKey = null;
045: protected HttpServletRequest request = null;
046: protected HttpServletResponse response = null;
047: protected ActionMapping mapping = null;
048: protected WebsiteData website = null;
049:
050: public BasePageModel(String titleKey, HttpServletRequest request,
051: HttpServletResponse response, ActionMapping mapping) {
052: this .request = request;
053: this .response = response;
054: this .mapping = mapping;
055: this .titleKey = titleKey;
056: request.setAttribute("locales", StrutsUtil.getLocaleBeans());
057: request
058: .setAttribute("timeZones", StrutsUtil
059: .getTimeZoneBeans());
060: RollerRequest rreq = RollerRequest.getRollerRequest(request);
061: website = rreq.getWebsite();
062: }
063:
064: public WebsiteData getWebsite() {
065: return website;
066: }
067:
068: public void setWebsite(WebsiteData website) {
069: this .website = website;
070: }
071:
072: public String getTitle() {
073: return bundle.getString(titleKey);
074: }
075:
076: public String getBaseURL() {
077: return RollerRuntimeConfig.getRelativeContextURL();
078: }
079:
080: public String getShortDateFormat() {
081: DateFormat sdf = DateFormat.getDateInstance(DateFormat.SHORT,
082: request.getLocale());
083: if (sdf instanceof SimpleDateFormat) {
084: return ((SimpleDateFormat) sdf).toPattern();
085: }
086: return "yyyy/MM/dd";
087: }
088:
089: public String getMediumDateFormat() {
090: DateFormat sdf = DateFormat.getDateInstance(DateFormat.MEDIUM,
091: request.getLocale());
092: if (sdf instanceof SimpleDateFormat) {
093: return ((SimpleDateFormat) sdf).toPattern();
094: }
095: return "MMM dd, yyyy";
096: }
097:
098: /**
099: * @return Returns the mapping.
100: */
101: public ActionMapping getMapping() {
102: return mapping;
103: }
104:
105: /**
106: * @return Returns the request.
107: */
108: public HttpServletRequest getRequest() {
109: return request;
110: }
111:
112: /**
113: * @return Returns the response.
114: */
115: public HttpServletResponse getResponse() {
116: return response;
117: }
118:
119: public RollerSession getRollerSession() {
120: return RollerSession.getRollerSession(request);
121: }
122:
123: public List getLocales() {
124: return StrutsUtil.getLocaleBeans();
125: }
126:
127: public List getTimeZones() {
128: return StrutsUtil.getTimeZoneBeans();
129: }
130:
131: }
|