KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > BasePageModel


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 /*
19  * Created on Mar 10, 2004
20  */

21 package org.apache.roller.ui.core;
22
23 import java.text.DateFormat JavaDoc;
24 import java.text.SimpleDateFormat JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
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 /**
37  * Re-usable base for page models.
38  * @author David M Johnson
39  */

40 public class BasePageModel
41 {
42     protected static ResourceBundle JavaDoc bundle =
43         ResourceBundle.getBundle("ApplicationResources");
44     
45     protected String JavaDoc titleKey = null;
46     protected HttpServletRequest JavaDoc request = null;
47     protected HttpServletResponse JavaDoc response = null;
48     protected ActionMapping mapping = null;
49     protected WebsiteData website = null;
50     
51     public BasePageModel(
52             String JavaDoc titleKey,
53             HttpServletRequest JavaDoc request,
54             HttpServletResponse JavaDoc 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 JavaDoc getTitle()
78     {
79         return bundle.getString(titleKey);
80     }
81     
82     public String JavaDoc getBaseURL()
83     {
84         return RollerRuntimeConfig.getRelativeContextURL();
85     }
86
87     public String JavaDoc getShortDateFormat()
88     {
89         DateFormat JavaDoc sdf = DateFormat.getDateInstance(
90                 DateFormat.SHORT, request.getLocale());
91         if (sdf instanceof SimpleDateFormat JavaDoc)
92         {
93             return ((SimpleDateFormat JavaDoc)sdf).toLocalizedPattern();
94         }
95         return "yyyy/MM/dd";
96     }
97
98     public String JavaDoc getMediumDateFormat()
99     {
100         DateFormat JavaDoc sdf = DateFormat.getDateInstance(
101                 DateFormat.MEDIUM, request.getLocale());
102         if (sdf instanceof SimpleDateFormat JavaDoc)
103         {
104             return ((SimpleDateFormat JavaDoc)sdf).toLocalizedPattern();
105         }
106         return "MMM dd, yyyy";
107     }
108
109     /**
110      * @return Returns the mapping.
111      */

112     public ActionMapping getMapping()
113     {
114         return mapping;
115     }
116     
117     /**
118      * @return Returns the request.
119      */

120     public HttpServletRequest JavaDoc getRequest()
121     {
122         return request;
123     }
124     
125     /**
126      * @return Returns the response.
127      */

128     public HttpServletResponse JavaDoc getResponse()
129     {
130         return response;
131     }
132     
133     public RollerSession getRollerSession()
134     {
135         return RollerSession.getRollerSession(request);
136     }
137
138     public List JavaDoc getLocales()
139     {
140         return StrutsUtil.getLocaleBeans();
141     }
142
143     public List JavaDoc getTimeZones()
144     {
145         return StrutsUtil.getTimeZoneBeans();
146     }
147
148 }
149
Popular Tags