1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the  "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18/*
19 * $Id: DecimalFormatProperties.java 468643 2006-10-28 06:56:03Z minchau $
20 */
21package org.apache.xalan.templates;
22
23import java.text.DecimalFormatSymbols;
24
25import org.apache.xml.utils.QName;
26
27/**
28 * Implement xsl:decimal-format.
29 * <pre>
30 * <!ELEMENT xsl:decimal-format EMPTY>
31 * <!ATTLIST xsl:decimal-format
32 *   name %qname; #IMPLIED
33 *   decimal-separator %char; "."
34 *   grouping-separator %char; ","
35 *   infinity CDATA "Infinity"
36 *   minus-sign %char; "-"
37 *   NaN CDATA "NaN"
38 *   percent %char; "%"
39 *   per-mille %char; "&#x2030;"
40 *   zero-digit %char; "0"
41 *   digit %char; "#"
42 *   pattern-separator %char; ";"
43 * >
44 * </pre>
45 * @see <a href="http://www.w3.org/TR/xslt#format-number">format-number in XSLT Specification</a>
46 * @xsl.usage advanced
47 */
48public class DecimalFormatProperties extends ElemTemplateElement
49{
50    static final long serialVersionUID = -6559409339256269446L;
51
52  /** An instance of DecimalFormatSymbols for this element.
53   *  @serial       */
54  DecimalFormatSymbols m_dfs;
55
56  /**
57   * Constructor DecimalFormatProperties
58   *
59   */
60  public DecimalFormatProperties(int docOrderNumber)
61  {
62
63    m_dfs = new java.text.DecimalFormatSymbols();
64
65    // Set default values, they can be overiden if necessary.
66    m_dfs.setInfinity(Constants.ATTRVAL_INFINITY);
67    m_dfs.setNaN(Constants.ATTRVAL_NAN);
68
69    m_docOrderNumber = docOrderNumber;
70  }
71
72  /**
73   * Return the decimal format Symbols for this element.
74   * <p>The xsl:decimal-format element declares a decimal-format,
75   * which controls the interpretation of a format pattern used by
76   * the format-number function. If there is a name attribute, then
77   * the element declares a named decimal-format; otherwise, it
78   * declares the default decimal-format. The value of the name
79   * attribute is a QName, which is expanded as described in [2.4 Qualified Names].
80   * It is an error to declare either the default decimal-format or a
81   * decimal-format with a given name more than once (even with different
82   * import precedence), unless it is declared every time with the same
83   * value for all attributes (taking into account any default values).</p>
84   * <p>The other attributes on xsl:decimal-format correspond to the
85   * methods on the JDK 1.1 DecimalFormatSymbols class. For each get/set
86   * method pair there is an attribute defined for the xsl:decimal-format
87   * element.</p>
88   *
89   * @return the decimal format Symbols for this element.
90   */
91  public DecimalFormatSymbols getDecimalFormatSymbols()
92  {
93    return m_dfs;
94  }
95
96  /**
97   * If there is a name attribute, then the element declares a named
98   * decimal-format; otherwise, it declares the default decimal-format.
99   * @serial
100   */
101  private QName m_qname = null;
102
103  /**
104   * Set the "name" attribute.
105   * If there is a name attribute, then the element declares a named
106   * decimal-format; otherwise, it declares the default decimal-format.
107   *
108   * @param qname The name to set as the "name" attribute.
109   */
110  public void setName(QName qname)
111  {
112    m_qname = qname;
113  }
114
115  /**
116   * Get the "name" attribute.
117   * If there is a name attribute, then the element declares a named
118   * decimal-format; otherwise, it declares the default decimal-format.
119   *
120   * @return the value of the "name" attribute.
121   */
122  public QName getName()
123  {
124
125    if (m_qname == null)
126      return new QName("");
127    else
128      return m_qname;
129  }
130
131  /**
132   * Set the "decimal-separator" attribute.
133   * decimal-separator specifies the character used for the decimal sign;
134   * the default value is the period character (.).
135   *
136   * @param ds Character to set as decimal separator
137   */
138  public void setDecimalSeparator(char ds)
139  {
140    m_dfs.setDecimalSeparator(ds);
141  }
142
143  /**
144   * Get the "decimal-separator" attribute.
145   * decimal-separator specifies the character used for the decimal sign;
146   * the default value is the period character (.).
147   *
148   * @return the character to use as decimal separator
149   */
150  public char getDecimalSeparator()
151  {
152    return m_dfs.getDecimalSeparator();
153  }
154
155  /**
156   * Set the "grouping-separator" attribute.
157   * grouping-separator specifies the character used as a grouping
158   * (e.g. thousands) separator; the default value is the comma character (,).
159   *
160   * @param gs Character to use a grouping separator
161   */
162  public void setGroupingSeparator(char gs)
163  {
164    m_dfs.setGroupingSeparator(gs);
165  }
166
167  /**
168   * Get the "grouping-separator" attribute.
169   * grouping-separator specifies the character used as a grouping
170   * (e.g. thousands) separator; the default value is the comma character (,).
171   *
172   * @return Character to use a grouping separator
173   */
174  public char getGroupingSeparator()
175  {
176    return m_dfs.getGroupingSeparator();
177  }
178
179  /**
180   * Set the "infinity" attribute.
181   * infinity specifies the string used to represent infinity;
182   * the default value is the string Infinity.
183   *
184   * @param inf String to use as the "infinity" attribute.
185   */
186  public void setInfinity(String inf)
187  {
188    m_dfs.setInfinity(inf);
189  }
190
191  /**
192   * Get the "infinity" attribute.
193   * infinity specifies the string used to represent infinity;
194   * the default value is the string Infinity.
195   *
196   * @return String to use as the "infinity" attribute.
197   */
198  public String getInfinity()
199  {
200    return m_dfs.getInfinity();
201  }
202
203  /**
204   * Set the "minus-sign" attribute.
205   * minus-sign specifies the character used as the default minus sign; the
206   * default value is the hyphen-minus character (-, #x2D).
207   *
208   * @param v Character to use as minus sign
209   */
210  public void setMinusSign(char v)
211  {
212    m_dfs.setMinusSign(v);
213  }
214
215  /**
216   * Get the "minus-sign" attribute.
217   * minus-sign specifies the character used as the default minus sign; the
218   * default value is the hyphen-minus character (-, #x2D).
219   *
220   * @return Character to use as minus sign
221   */
222  public char getMinusSign()
223  {
224    return m_dfs.getMinusSign();
225  }
226
227  /**
228   * Set the "NaN" attribute.
229   * NaN specifies the string used to represent the NaN value;
230   * the default value is the string NaN.
231   *
232   * @param v String to use as the "NaN" attribute.
233   */
234  public void setNaN(String v)
235  {
236    m_dfs.setNaN(v);
237  }
238
239  /**
240   * Get the "NaN" attribute.
241   * NaN specifies the string used to represent the NaN value;
242   * the default value is the string NaN.
243   *
244   * @return String to use as the "NaN" attribute.
245   */
246  public String getNaN()
247  {
248    return m_dfs.getNaN();
249  }
250
251  /**
252   * Return the node name.
253   *
254   * @return the element's name
255   */
256  public String getNodeName()
257  {
258    return Constants.ELEMNAME_DECIMALFORMAT_STRING;
259  }
260
261  /**
262   * Set the "percent" attribute.
263   * percent specifies the character used as a percent sign; the default
264   * value is the percent character (%).
265   *
266   * @param v Character to use as percent
267   */
268  public void setPercent(char v)
269  {
270    m_dfs.setPercent(v);
271  }
272
273  /**
274   * Get the "percent" attribute.
275   * percent specifies the character used as a percent sign; the default
276   * value is the percent character (%).
277   *
278   * @return Character to use as percent
279   */
280  public char getPercent()
281  {
282    return m_dfs.getPercent();
283  }
284
285  /**
286   * Set the "per-mille" attribute.
287   * per-mille specifies the character used as a per mille sign; the default
288   * value is the Unicode per-mille character (#x2030).
289   *
290   * @param v Character to use as per-mille
291   */
292  public void setPerMille(char v)
293  {
294    m_dfs.setPerMill(v);
295  }
296
297  /**
298   * Get the "per-mille" attribute.
299   * per-mille specifies the character used as a per mille sign; the default
300   * value is the Unicode per-mille character (#x2030).
301   *
302   * @return Character to use as per-mille
303   */
304  public char getPerMille()
305  {
306    return m_dfs.getPerMill();
307  }
308
309  /**
310   * Get an int constant identifying the type of element.
311   * @see org.apache.xalan.templates.Constants
312   *
313   * @return The token ID for this element
314   */
315  public int getXSLToken()
316  {
317    return Constants.ELEMNAME_DECIMALFORMAT;
318  }
319
320  /**
321   * Set the "zero-digit" attribute.
322   * zero-digit specifies the character used as the digit zero; the default
323   * value is the digit zero (0).
324   *
325   * @param v Character to use as the digit zero
326   */
327  public void setZeroDigit(char v)
328  {
329    m_dfs.setZeroDigit(v);
330  }
331
332  /**
333   * Get the "zero-digit" attribute.
334   * zero-digit specifies the character used as the digit zero; the default
335   * value is the digit zero (0).
336   *
337   * @return Character to use as the digit zero
338   */
339  public char getZeroDigit()
340  {
341    return m_dfs.getZeroDigit();
342  }
343
344  /**
345   * Set the "digit" attribute.
346   * digit specifies the character used for a digit in the format pattern;
347   * the default value is the number sign character (#).
348   *
349   * @param v Character to use for a digit in format pattern
350   */
351  public void setDigit(char v)
352  {
353    m_dfs.setDigit(v);
354  }
355
356  /**
357   * Get the "digit" attribute.
358   * digit specifies the character used for a digit in the format pattern;
359   * the default value is the number sign character (#).
360   *
361   * @return Character to use for a digit in format pattern
362   */
363  public char getDigit()
364  {
365    return m_dfs.getDigit();
366  }
367
368  /**
369   * Set the "pattern-separator" attribute.
370   * pattern-separator specifies the character used to separate positive
371   * and negative sub patterns in a pattern; the default value is the
372   * semi-colon character (;).
373   *
374   * @param v Character to use as a pattern separator
375   */
376  public void setPatternSeparator(char v)
377  {
378    m_dfs.setPatternSeparator(v);
379  }
380
381  /**
382   * Get the "pattern-separator" attribute.
383   * pattern-separator specifies the character used to separate positive
384   * and negative sub patterns in a pattern; the default value is the
385   * semi-colon character (;).
386   *
387   * @return Character to use as a pattern separator
388   */
389  public char getPatternSeparator()
390  {
391    return m_dfs.getPatternSeparator();
392  }
393
394  /**
395   * This function is called to recompose() all of the decimal format properties elements.
396   *
397   * @param root Stylesheet root
398   */
399  public void recompose(StylesheetRoot root)
400  {
401    root.recomposeDecimalFormats(this);
402  }
403
404}
405