KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > faces > taglib > ConvertNumberTag


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not 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.
15  */

16 package org.apache.cocoon.faces.taglib;
17
18 import org.apache.cocoon.i18n.I18nUtils;
19
20 import org.apache.cocoon.faces.FacesUtils;
21 import org.xml.sax.Attributes JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23
24 import javax.faces.convert.Converter;
25 import javax.faces.convert.NumberConverter;
26 import java.util.Locale JavaDoc;
27
28 /**
29  * @version CVS $Id: ConvertNumberTag.java 53791 2004-10-05 13:16:15Z vgritsenko $
30  */

31 public class ConvertNumberTag extends ConverterTag {
32     private String JavaDoc currencyCode;
33     private String JavaDoc currencySymbol;
34     private String JavaDoc groupingUsed;
35     private String JavaDoc integerOnly;
36     private String JavaDoc maxFractionDigits;
37     private String JavaDoc maxIntegerDigits;
38     private String JavaDoc minFractionDigits;
39     private String JavaDoc minIntegerDigits;
40     private String JavaDoc locale;
41     private String JavaDoc pattern;
42     private String JavaDoc type;
43
44
45     public void setCurrencyCode(String JavaDoc currencyCode) {
46         this.currencyCode = currencyCode;
47     }
48
49     public void setCurrencySymbol(String JavaDoc currencySymbol) {
50         this.currencySymbol = currencySymbol;
51     }
52
53     public void setGroupingUsed(String JavaDoc groupingUsed) {
54         this.groupingUsed = groupingUsed;
55     }
56
57     public void setIntegerOnly(String JavaDoc integerOnly) {
58         this.integerOnly = integerOnly;
59     }
60
61     public void setMaxFractionDigits(String JavaDoc maxFractionDigits) {
62         this.maxFractionDigits = maxFractionDigits;
63     }
64
65     public void setMaxIntegerDigits(String JavaDoc maxIntegerDigits) {
66         this.maxIntegerDigits = maxIntegerDigits;
67     }
68
69     public void setMinFractionDigits(String JavaDoc minFractionDigits) {
70         this.minFractionDigits = minFractionDigits;
71     }
72
73     public void setMinIntegerDigits(String JavaDoc minIntegerDigits) {
74         this.minIntegerDigits = minIntegerDigits;
75     }
76
77     public void setLocale(String JavaDoc locale) {
78         this.locale = locale;
79     }
80
81     public void setPattern(String JavaDoc pattern) {
82         this.pattern = pattern;
83     }
84
85     public void setType(String JavaDoc type) {
86         this.type = type;
87     }
88
89
90     public int doStartTag(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts)
91     throws SAXException JavaDoc {
92         super.setConverterId("javax.faces.Number");
93         return super.doStartTag(namespaceURI, localName, qName, atts);
94     }
95
96     protected Converter createConverter() {
97         final UIComponentTag tag = FacesUtils.findParentUIComponentTag(this);
98         NumberConverter converter = (NumberConverter) super.createConverter();
99
100         converter.setCurrencyCode((String JavaDoc) tag.evaluate(currencyCode));
101         converter.setCurrencySymbol((String JavaDoc) tag.evaluate(currencySymbol));
102         converter.setPattern((String JavaDoc) tag.evaluate(pattern));
103         converter.setType((String JavaDoc) tag.evaluate(type));
104
105         if (groupingUsed != null) {
106             converter.setGroupingUsed(tag.evaluateBoolean(groupingUsed));
107         }
108         if (integerOnly != null) {
109             converter.setIntegerOnly(tag.evaluateBoolean(integerOnly));
110         }
111
112         if (maxFractionDigits != null) {
113             converter.setMaxFractionDigits(tag.evaluateInteger(maxFractionDigits));
114         }
115         if (maxIntegerDigits != null) {
116             converter.setMaxIntegerDigits(tag.evaluateInteger(maxIntegerDigits));
117         }
118         if (minFractionDigits != null) {
119             converter.setMinFractionDigits(tag.evaluateInteger(minFractionDigits));
120         }
121         if (minIntegerDigits != null) {
122             converter.setMinIntegerDigits(tag.evaluateInteger(minIntegerDigits));
123         }
124
125         Locale JavaDoc l = null;
126         if (locale != null) {
127             if (FacesUtils.isExpression(locale)) {
128                 l = (Locale JavaDoc) tag.evaluate(locale);
129             } else {
130                 l = I18nUtils.parseLocale(locale);
131             }
132         }
133         converter.setLocale(l);
134
135         return converter;
136     }
137
138     public void recycle() {
139         super.recycle();
140         currencyCode = null;
141         currencySymbol = null;
142         groupingUsed = null;
143         integerOnly = null;
144         maxFractionDigits = null;
145         maxIntegerDigits = null;
146         minFractionDigits = null;
147         minIntegerDigits = null;
148         locale = null;
149         pattern = null;
150         type = null;
151     }
152 }
153
Popular Tags