1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.shared_impl.taglib.core; |
20 | |
|
21 | |
import java.util.Locale; |
22 | |
import java.util.TimeZone; |
23 | |
|
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.convert.Converter; |
26 | |
import javax.faces.convert.DateTimeConverter; |
27 | |
import javax.faces.webapp.ConverterTag; |
28 | |
import javax.faces.webapp.UIComponentTag; |
29 | |
import javax.faces.el.ValueBinding; |
30 | |
import javax.servlet.jsp.JspException; |
31 | |
|
32 | |
import org.apache.myfaces.shared_impl.util.LocaleUtils; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class ConvertDateTimeTagBase |
39 | |
extends ConverterTag |
40 | |
{ |
41 | |
private static final long serialVersionUID = -757757296071312897L; |
42 | 0 | private String _dateStyle = "default"; |
43 | 0 | private String _locale = null; |
44 | 0 | private String _pattern = null; |
45 | 0 | private String _timeStyle = "default"; |
46 | 0 | private String _timeZone = null; |
47 | 0 | private String _type = null; |
48 | |
|
49 | |
public void setDateStyle(String dateStyle) |
50 | |
{ |
51 | 0 | _dateStyle = dateStyle; |
52 | 0 | } |
53 | |
|
54 | |
public void setLocale(String locale) |
55 | |
{ |
56 | 0 | _locale = locale; |
57 | 0 | } |
58 | |
|
59 | |
public void setPattern(String pattern) |
60 | |
{ |
61 | 0 | _pattern = pattern; |
62 | 0 | } |
63 | |
|
64 | |
public void setTimeStyle(String timeStyle) |
65 | |
{ |
66 | 0 | _timeStyle = timeStyle; |
67 | 0 | } |
68 | |
|
69 | |
public void setTimeZone(String timeZone) |
70 | |
{ |
71 | 0 | _timeZone = timeZone; |
72 | 0 | } |
73 | |
|
74 | |
public void setType(String type) |
75 | |
{ |
76 | 0 | _type = type; |
77 | 0 | } |
78 | |
|
79 | |
protected Converter createConverter() throws JspException |
80 | |
{ |
81 | 0 | DateTimeConverter converter = (DateTimeConverter)super.createConverter(); |
82 | |
|
83 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
84 | 0 | setConverterDateStyle(facesContext, converter, _dateStyle); |
85 | 0 | setConverterLocale(facesContext, converter, _locale); |
86 | 0 | setConverterPattern(facesContext, converter, _pattern); |
87 | 0 | setConverterTimeStyle(facesContext, converter, _timeStyle); |
88 | 0 | setConverterTimeZone(facesContext, converter, _timeZone); |
89 | 0 | setConverterType(facesContext, converter, _type); |
90 | |
|
91 | 0 | return converter; |
92 | |
} |
93 | |
|
94 | |
protected static void setConverterLocale(FacesContext facesContext, |
95 | |
DateTimeConverter converter, |
96 | |
String value) |
97 | |
{ |
98 | 0 | Locale locale = null; |
99 | 0 | Object _value = null; |
100 | |
|
101 | 0 | if (value == null) return; |
102 | 0 | if (UIComponentTag.isValueReference(value)) |
103 | |
{ |
104 | 0 | ValueBinding vb = facesContext.getApplication().createValueBinding(value); |
105 | 0 | _value = vb.getValue(facesContext); |
106 | 0 | if(_value instanceof Locale) |
107 | |
{ |
108 | 0 | locale = (Locale) _value; |
109 | |
} |
110 | |
else |
111 | |
{ |
112 | 0 | locale = LocaleUtils.converterTagLocaleFromString(_value.toString()); |
113 | |
} |
114 | 0 | } |
115 | |
else |
116 | |
{ |
117 | 0 | locale = LocaleUtils.converterTagLocaleFromString( value); |
118 | |
} |
119 | 0 | converter.setLocale(locale); |
120 | 0 | } |
121 | |
|
122 | |
|
123 | |
private static void setConverterDateStyle(FacesContext facesContext, |
124 | |
DateTimeConverter converter, |
125 | |
String value) |
126 | |
{ |
127 | 0 | if (value == null) return; |
128 | 0 | if (UIComponentTag.isValueReference(value)) |
129 | |
{ |
130 | 0 | ValueBinding vb = facesContext.getApplication().createValueBinding(value); |
131 | 0 | converter.setDateStyle((String)vb.getValue(facesContext)); |
132 | 0 | } |
133 | |
else |
134 | |
{ |
135 | 0 | converter.setDateStyle(value); |
136 | |
} |
137 | 0 | } |
138 | |
|
139 | |
private static void setConverterPattern(FacesContext facesContext, |
140 | |
DateTimeConverter converter, |
141 | |
String value) |
142 | |
{ |
143 | 0 | if (value == null) return; |
144 | 0 | if (UIComponentTag.isValueReference(value)) |
145 | |
{ |
146 | 0 | ValueBinding vb = facesContext.getApplication().createValueBinding(value); |
147 | 0 | converter.setPattern((String)vb.getValue(facesContext)); |
148 | 0 | } |
149 | |
else |
150 | |
{ |
151 | 0 | converter.setPattern(value); |
152 | |
} |
153 | 0 | } |
154 | |
|
155 | |
private static void setConverterTimeStyle(FacesContext facesContext, |
156 | |
DateTimeConverter converter, |
157 | |
String value) |
158 | |
{ |
159 | 0 | if (value == null) return; |
160 | 0 | if (UIComponentTag.isValueReference(value)) |
161 | |
{ |
162 | 0 | ValueBinding vb = facesContext.getApplication().createValueBinding(value); |
163 | 0 | converter.setTimeStyle((String)vb.getValue(facesContext)); |
164 | 0 | } |
165 | |
else |
166 | |
{ |
167 | 0 | converter.setTimeStyle(value); |
168 | |
} |
169 | 0 | } |
170 | |
|
171 | |
private static void setConverterTimeZone(FacesContext facesContext, |
172 | |
DateTimeConverter converter, |
173 | |
String value) |
174 | |
{ |
175 | 0 | if (value == null) return; |
176 | 0 | if (UIComponentTag.isValueReference(value)) |
177 | |
{ |
178 | 0 | ValueBinding vb = facesContext.getApplication().createValueBinding(value); |
179 | 0 | TimeZone timeZone = null; |
180 | 0 | Object _value = vb.getValue(facesContext); |
181 | 0 | if (_value instanceof TimeZone) |
182 | |
{ |
183 | 0 | timeZone = (TimeZone) _value; |
184 | |
} |
185 | |
else |
186 | |
{ |
187 | 0 | timeZone = TimeZone.getTimeZone(_value.toString()); |
188 | |
} |
189 | 0 | converter.setTimeZone(timeZone); |
190 | 0 | } |
191 | |
else |
192 | |
{ |
193 | 0 | converter.setTimeZone(TimeZone.getTimeZone(value)); |
194 | |
} |
195 | 0 | } |
196 | |
|
197 | |
private static void setConverterType(FacesContext facesContext, |
198 | |
DateTimeConverter converter, |
199 | |
String value) |
200 | |
{ |
201 | 0 | if (value == null) return; |
202 | 0 | if (UIComponentTag.isValueReference(value)) |
203 | |
{ |
204 | 0 | ValueBinding vb = facesContext.getApplication().createValueBinding(value); |
205 | 0 | converter.setType((String)vb.getValue(facesContext)); |
206 | 0 | } |
207 | |
else |
208 | |
{ |
209 | 0 | converter.setType(value); |
210 | |
} |
211 | 0 | } |
212 | |
|
213 | |
} |