001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.xsl.java;
030:
031: import com.caucho.java.JavaWriter;
032: import com.caucho.xml.QName;
033: import com.caucho.xsl.XslParseException;
034:
035: import java.text.DecimalFormatSymbols;
036:
037: /**
038: * xsl:decimal-format
039: */
040: public class XslDecimalFormat extends XslNode implements XslTopNode {
041: private String _name;
042: private String _decimalSeparator;
043: private String _groupingSeparator;
044: private String _infinity;
045: private String _minusSign;
046: private String _nan;
047: private String _percent;
048: private String _perMille;
049: private String _zeroDigit;
050: private String _digit;
051: private String _patternSeparator;
052:
053: /**
054: * Returns the tag name.
055: */
056: public String getTagName() {
057: return "xsl:decimal-format";
058: }
059:
060: /**
061: * Adds an attribute.
062: */
063: public void addAttribute(QName name, String value)
064: throws XslParseException {
065: if (name.getName().equals("name"))
066: _name = value;
067: else if (name.getName().equals("decimal-separator"))
068: _decimalSeparator = value;
069: else if (name.getName().equals("grouping-separator"))
070: _groupingSeparator = value;
071: else if (name.getName().equals("infinity"))
072: _infinity = value;
073: else if (name.getName().equals("minus-sign"))
074: _minusSign = value;
075: else if (name.getName().equals("NaN"))
076: _nan = value;
077: else if (name.getName().equals("percent"))
078: _percent = value;
079: else if (name.getName().equals("per-mille"))
080: _perMille = value;
081: else if (name.getName().equals("zero-digit"))
082: _zeroDigit = value;
083: else if (name.getName().equals("digit"))
084: _digit = value;
085: else if (name.getName().equals("pattern-separator"))
086: _patternSeparator = value;
087: else
088: super .addAttribute(name, value);
089: }
090:
091: /**
092: * Ends the attributes.
093: */
094: public void endAttributes() throws XslParseException {
095: }
096:
097: /**
098: * Called when the element ends.
099: */
100: public void endElement() throws Exception {
101: String name = _name;
102:
103: if (name == null)
104: name = "*";
105:
106: DecimalFormatSymbols format = new DecimalFormatSymbols();
107:
108: if (_decimalSeparator != null && _decimalSeparator.length() > 0)
109: format.setDecimalSeparator(_decimalSeparator.charAt(0));
110:
111: if (_groupingSeparator != null
112: && _groupingSeparator.length() > 0)
113: format.setGroupingSeparator(_groupingSeparator.charAt(0));
114:
115: if (_infinity != null)
116: format.setInfinity(_infinity);
117:
118: if (_minusSign != null && _minusSign.length() > 0)
119: format.setMinusSign(_minusSign.charAt(0));
120:
121: if (_nan != null)
122: format.setNaN(_nan);
123:
124: if (_percent != null && _percent.length() > 0)
125: format.setPercent(_percent.charAt(0));
126:
127: if (_perMille != null && _perMille.length() > 0)
128: format.setPerMill(_perMille.charAt(0));
129:
130: if (_zeroDigit != null && _zeroDigit.length() > 0)
131: format.setZeroDigit(_zeroDigit.charAt(0));
132:
133: if (_digit != null && _digit.length() > 0)
134: format.setDigit(_digit.charAt(0));
135:
136: if (_patternSeparator != null && _patternSeparator.length() > 0)
137: format.setPatternSeparator(_patternSeparator.charAt(0));
138:
139: _gen.addLocale(name, format);
140: }
141:
142: /**
143: * Generates the code for the tag
144: *
145: * @param out the output writer for the generated java.
146: */
147: public void generate(JavaWriter out) throws Exception {
148: }
149: }
|