KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xsl > java > XslDecimalFormat


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xsl.java;
30
31 import com.caucho.java.JavaWriter;
32 import com.caucho.xml.QName;
33 import com.caucho.xsl.XslParseException;
34
35 import java.text.DecimalFormatSymbols JavaDoc;
36
37 /**
38  * xsl:decimal-format
39  */

40 public class XslDecimalFormat extends XslNode implements XslTopNode {
41   private String JavaDoc _name;
42   private String JavaDoc _decimalSeparator;
43   private String JavaDoc _groupingSeparator;
44   private String JavaDoc _infinity;
45   private String JavaDoc _minusSign;
46   private String JavaDoc _nan;
47   private String JavaDoc _percent;
48   private String JavaDoc _perMille;
49   private String JavaDoc _zeroDigit;
50   private String JavaDoc _digit;
51   private String JavaDoc _patternSeparator;
52   
53   /**
54    * Returns the tag name.
55    */

56   public String JavaDoc getTagName()
57   {
58     return "xsl:decimal-format";
59   }
60   
61   /**
62    * Adds an attribute.
63    */

64   public void addAttribute(QName name, String JavaDoc value)
65     throws XslParseException
66   {
67     if (name.getName().equals("name"))
68       _name = value;
69     else if (name.getName().equals("decimal-separator"))
70       _decimalSeparator = value;
71     else if (name.getName().equals("grouping-separator"))
72       _groupingSeparator = value;
73     else if (name.getName().equals("infinity"))
74       _infinity = value;
75     else if (name.getName().equals("minus-sign"))
76       _minusSign = value;
77     else if (name.getName().equals("NaN"))
78       _nan = value;
79     else if (name.getName().equals("percent"))
80       _percent = value;
81     else if (name.getName().equals("per-mille"))
82       _perMille = value;
83     else if (name.getName().equals("zero-digit"))
84       _zeroDigit = value;
85     else if (name.getName().equals("digit"))
86       _digit = value;
87     else if (name.getName().equals("pattern-separator"))
88       _patternSeparator = value;
89     else
90       super.addAttribute(name, value);
91   }
92
93   /**
94    * Ends the attributes.
95    */

96   public void endAttributes()
97     throws XslParseException
98   {
99   }
100
101   /**
102    * Called when the element ends.
103    */

104   public void endElement()
105     throws Exception JavaDoc
106   {
107     String JavaDoc name = _name;
108     
109     if (name == null)
110       name = "*";
111
112     DecimalFormatSymbols JavaDoc format = new DecimalFormatSymbols JavaDoc();
113
114     if (_decimalSeparator != null && _decimalSeparator.length() > 0)
115       format.setDecimalSeparator(_decimalSeparator.charAt(0));
116
117     if (_groupingSeparator != null && _groupingSeparator.length() > 0)
118       format.setGroupingSeparator(_groupingSeparator.charAt(0));
119
120     if (_infinity != null)
121       format.setInfinity(_infinity);
122
123     if (_minusSign != null && _minusSign.length() > 0)
124       format.setMinusSign(_minusSign.charAt(0));
125
126     if (_nan != null)
127       format.setNaN(_nan);
128
129     if (_percent != null && _percent.length() > 0)
130       format.setPercent(_percent.charAt(0));
131
132     if (_perMille != null && _perMille.length() > 0)
133       format.setPerMill(_perMille.charAt(0));
134
135     if (_zeroDigit != null && _zeroDigit.length() > 0)
136       format.setZeroDigit(_zeroDigit.charAt(0));
137
138     if (_digit != null && _digit.length() > 0)
139       format.setDigit(_digit.charAt(0));
140
141     if (_patternSeparator != null && _patternSeparator.length() > 0)
142       format.setPatternSeparator(_patternSeparator.charAt(0));
143
144     _gen.addLocale(name, format);
145   }
146
147   /**
148    * Generates the code for the tag
149    *
150    * @param out the output writer for the generated java.
151    */

152   public void generate(JavaWriter out)
153     throws Exception JavaDoc
154   {
155   }
156 }
157
Popular Tags