KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > style > XSLDecimalFormat


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.om.Name;
5 import com.icl.saxon.om.NamespaceException;
6 import com.icl.saxon.expr.*;
7 import javax.xml.transform.*;
8
9 import java.text.DecimalFormatSymbols JavaDoc;
10
11 /**
12 * Handler for xsl:decimal-format elements in stylesheet.<BR>
13 */

14
15 public class XSLDecimalFormat extends StyleElement {
16
17     String JavaDoc name;
18     String JavaDoc decimalSeparator;
19     String JavaDoc groupingSeparator;
20     String JavaDoc infinity;
21     String JavaDoc minusSign;
22     String JavaDoc NaN;
23     String JavaDoc percent;
24     String JavaDoc perMille;
25     String JavaDoc zeroDigit;
26     String JavaDoc digit;
27     String JavaDoc patternSeparator;
28
29     public void prepareAttributes() throws TransformerConfigurationException {
30         
31         StandardNames sn = getStandardNames();
32         AttributeCollection atts = getAttributeList();
33
34         for (int a=0; a<atts.getLength(); a++) {
35             int nc = atts.getNameCode(a);
36             int f = nc & 0xfffff;
37             if (f==sn.NAME) {
38                 name = atts.getValue(a);
39             } else if (f==sn.DECIMAL_SEPARATOR) {
40                 decimalSeparator = atts.getValue(a);
41             } else if (f==sn.GROUPING_SEPARATOR) {
42                 groupingSeparator = atts.getValue(a);
43             } else if (f==sn.INFINITY) {
44                 infinity = atts.getValue(a);
45             } else if (f==sn.MINUS_SIGN) {
46                 minusSign = atts.getValue(a);
47             } else if (f==sn.NAN) {
48                 NaN = atts.getValue(a);
49             } else if (f==sn.PERCENT) {
50                 percent = atts.getValue(a);
51             } else if (f==sn.PER_MILLE) {
52                 perMille = atts.getValue(a);
53             } else if (f==sn.ZERO_DIGIT) {
54                 zeroDigit = atts.getValue(a);
55             } else if (f==sn.DIGIT) {
56                 digit = atts.getValue(a);
57             } else if (f==sn.PATTERN_SEPARATOR) {
58                 patternSeparator = atts.getValue(a);
59             } else {
60                 checkUnknownAttribute(nc);
61             }
62         }
63     }
64
65     public void validate() throws TransformerConfigurationException {
66         checkTopLevel();
67     }
68
69     public void preprocess() throws TransformerConfigurationException
70     {
71
72         DecimalFormatSymbols JavaDoc d = new DecimalFormatSymbols JavaDoc();
73         DecimalFormatManager.setDefaults(d);
74         if (decimalSeparator!=null) {
75             d.setDecimalSeparator(toChar(decimalSeparator));
76         }
77         if (groupingSeparator!=null) {
78             d.setGroupingSeparator(toChar(groupingSeparator));
79         }
80         if (infinity!=null) {
81         d.setInfinity(infinity);
82         }
83         if (minusSign!=null) {
84             d.setMinusSign(toChar(minusSign));
85         }
86         if (NaN!=null) {
87             d.setNaN(NaN);
88         }
89         if (percent!=null) {
90             d.setPercent(toChar(percent));
91         }
92         if (perMille!=null) {
93             d.setPerMill(toChar(perMille));
94         }
95         if (zeroDigit!=null) {
96             d.setZeroDigit(toChar(zeroDigit));
97         }
98         if (digit!=null) {
99             d.setDigit(toChar(digit));
100         }
101         if (patternSeparator!=null) {
102             d.setPatternSeparator(toChar(patternSeparator));
103         }
104
105         DecimalFormatManager dfm = getPrincipalStyleSheet().getDecimalFormatManager();
106         if (name==null) {
107             dfm.setDefaultDecimalFormat(d);
108         } else {
109             if (!Name.isQName(name)) {
110                 compileError("Name of decimal-format must be a valid QName");
111             }
112             int fprint;
113             try {
114                 fprint = makeNameCode(name, false) & 0xfffff;
115             } catch (NamespaceException err) {
116                 compileError(err.getMessage());
117                 return;
118             }
119             dfm.setNamedDecimalFormat(fprint, d);
120         }
121     }
122
123     public void process(Context context) {}
124
125     private char toChar(String JavaDoc s) throws TransformerConfigurationException {
126         if (s.length()!=1)
127             compileError("Attribute \"" + s + "\" should be a single character");
128         return s.charAt(0);
129     }
130
131 }
132 //
133
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
134
// you may not use this file except in compliance with the License. You may obtain a copy of the
135
// License at http://www.mozilla.org/MPL/
136
//
137
// Software distributed under the License is distributed on an "AS IS" basis,
138
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
139
// See the License for the specific language governing rights and limitations under the License.
140
//
141
// The Original Code is: all this file.
142
//
143
// The Initial Developer of the Original Code is
144
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
145
//
146
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
147
//
148
// Contributor(s): none.
149
//
150
Popular Tags