KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > util > MessagesCalendarFormatProvider


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.war.util;
22
23 import java.text.DateFormat JavaDoc;
24 import java.text.SimpleDateFormat JavaDoc;
25 import java.util.Locale JavaDoc;
26
27 import org.springframework.context.MessageSource;
28 import org.springframework.context.i18n.LocaleContextHolder;
29
30 /**
31  * @author Lucian Chirita (lucianc@users.sourceforge.net)
32  * @version $Id: MessagesCalendarFormatProvider.java 4728 2006-09-25 09:09:53Z lucian $
33  */

34 public class MessagesCalendarFormatProvider implements CalendarFormatProvider {
35
36     private MessageSource messages;
37     private String JavaDoc datePatternKey;
38     private String JavaDoc calendarDatePatternKey;
39     private String JavaDoc datetimePatternKey;
40     private String JavaDoc calendarDatetimePatternKey;
41     
42     public String JavaDoc getCalendarDatePattern() {
43         return messages.getMessage(getCalendarDatePatternKey(), null, getLocale());
44     }
45
46     public String JavaDoc getCalendarDatetimePattern() {
47         return messages.getMessage(getCalendarDatetimePatternKey(), null, getLocale());
48     }
49
50     public DateFormat JavaDoc getDateFormat() {
51         String JavaDoc pattern = messages.getMessage(getDatePatternKey(), null, getLocale());
52         return new SimpleDateFormat JavaDoc(pattern);
53     }
54
55     public DateFormat JavaDoc getDatetimeFormat() {
56         String JavaDoc pattern = messages.getMessage(getDatetimePatternKey(), null, getLocale());
57         return new SimpleDateFormat JavaDoc(pattern);
58     }
59
60     public String JavaDoc getCalendarDatePatternKey() {
61         return calendarDatePatternKey;
62     }
63
64     public void setCalendarDatePatternKey(String JavaDoc calendarDatePatternKey) {
65         this.calendarDatePatternKey = calendarDatePatternKey;
66     }
67
68     public String JavaDoc getCalendarDatetimePatternKey() {
69         return calendarDatetimePatternKey;
70     }
71
72     public void setCalendarDatetimePatternKey(String JavaDoc calendarDatetimePatternKey) {
73         this.calendarDatetimePatternKey = calendarDatetimePatternKey;
74     }
75
76     public String JavaDoc getDatePatternKey() {
77         return datePatternKey;
78     }
79
80     public void setDatePatternKey(String JavaDoc datePatternKey) {
81         this.datePatternKey = datePatternKey;
82     }
83
84     public String JavaDoc getDatetimePatternKey() {
85         return datetimePatternKey;
86     }
87
88     public void setDatetimePatternKey(String JavaDoc datetimePatternKey) {
89         this.datetimePatternKey = datetimePatternKey;
90     }
91
92     public MessageSource getMessages() {
93         return messages;
94     }
95
96     public void setMessages(MessageSource messages) {
97         this.messages = messages;
98     }
99
100     protected Locale JavaDoc getLocale() {
101         return LocaleContextHolder.getLocale();
102     }
103
104 }
105
Popular Tags