KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > BasePageModel


1 /*
2  * Created on Mar 10, 2004
3  */

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 JavaDoc;
11 import java.text.SimpleDateFormat JavaDoc;
12
13 import javax.servlet.http.HttpServletRequest JavaDoc;
14 import javax.servlet.http.HttpServletResponse JavaDoc;
15
16 /**
17  * Re-usable base for page models.
18  * @author David M Johnson
19  */

20 public class BasePageModel
21 {
22     private HttpServletRequest JavaDoc request = null;
23     private HttpServletResponse JavaDoc response = null;
24     private ActionMapping mapping = null;
25     
26     public BasePageModel(
27             HttpServletRequest JavaDoc request,
28             HttpServletResponse JavaDoc response,
29             ActionMapping mapping)
30     {
31         this.request = request;
32         this.response = response;
33         this.mapping = mapping;
34     }
35
36     public String JavaDoc getBaseURL()
37     {
38         return request.getContextPath();
39     }
40
41     public String JavaDoc getShortDateFormat()
42     {
43         DateFormat JavaDoc sdf = DateFormat.getDateInstance(
44                 DateFormat.SHORT, request.getLocale());
45         if (sdf instanceof SimpleDateFormat JavaDoc)
46         {
47             return ((SimpleDateFormat JavaDoc)sdf).toLocalizedPattern();
48         }
49         return "yyyy/MM/dd";
50     }
51
52     public String JavaDoc getMediumDateFormat()
53     {
54         DateFormat JavaDoc sdf = DateFormat.getDateInstance(
55                 DateFormat.MEDIUM, request.getLocale());
56         if (sdf instanceof SimpleDateFormat JavaDoc)
57         {
58             return ((SimpleDateFormat JavaDoc)sdf).toLocalizedPattern();
59         }
60         return "MMM dd, yyyy";
61     }
62
63     public UserData getUser()
64     {
65         return RollerRequest.getRollerRequest(request).getUser();
66     }
67     
68     /**
69      * @return Returns the mapping.
70      */

71     public ActionMapping getMapping()
72     {
73         return mapping;
74     }
75     
76     /**
77      * @return Returns the request.
78      */

79     public HttpServletRequest JavaDoc getRequest()
80     {
81         return request;
82     }
83     
84     /**
85      * @return Returns the response.
86      */

87     public HttpServletResponse JavaDoc 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