1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xalan.templates;
  58. import org.w3c.dom.*;
  59. import org.xml.sax.*;
  60. import org.apache.xpath.*;
  61. import java.util.*;
  62. import java.text.NumberFormat;
  63. import java.text.DecimalFormat;
  64. import java.text.DecimalFormatSymbols;
  65. import org.apache.xml.utils.QName;
  66. import org.apache.xalan.res.*;
  67. import org.apache.xalan.transformer.TransformerImpl;
  68. /**
  69. * <meta name="usage" content="advanced"/>
  70. * Implement xsl:decimal-format.
  71. * <pre>
  72. * <!ELEMENT xsl:decimal-format EMPTY>
  73. * <!ATTLIST xsl:decimal-format
  74. * name %qname; #IMPLIED
  75. * decimal-separator %char; "."
  76. * grouping-separator %char; ","
  77. * infinity CDATA "Infinity"
  78. * minus-sign %char; "-"
  79. * NaN CDATA "NaN"
  80. * percent %char; "%"
  81. * per-mille %char; "‰"
  82. * zero-digit %char; "0"
  83. * digit %char; "#"
  84. * pattern-separator %char; ";"
  85. * >
  86. * </pre>
  87. * @see <a href="http://www.w3.org/TR/xslt#format-number">format-number in XSLT Specification</a>
  88. */
  89. public class DecimalFormatProperties extends ElemTemplateElement
  90. {
  91. /** An instance of DecimalFormatSymbols for this element.
  92. * @serial */
  93. DecimalFormatSymbols m_dfs;
  94. /**
  95. * Constructor DecimalFormatProperties
  96. *
  97. */
  98. public DecimalFormatProperties(int docOrderNumber)
  99. {
  100. m_dfs = new java.text.DecimalFormatSymbols();
  101. // Set default values, they can be overiden if necessary.
  102. m_dfs.setInfinity(Constants.ATTRVAL_INFINITY);
  103. m_dfs.setNaN(Constants.ATTRVAL_NAN);
  104. m_docOrderNumber = docOrderNumber;
  105. }
  106. /**
  107. * Return the decimal format Symbols for this element.
  108. * <p>The xsl:decimal-format element declares a decimal-format,
  109. * which controls the interpretation of a format pattern used by
  110. * the format-number function. If there is a name attribute, then
  111. * the element declares a named decimal-format; otherwise, it
  112. * declares the default decimal-format. The value of the name
  113. * attribute is a QName, which is expanded as described in [2.4 Qualified Names].
  114. * It is an error to declare either the default decimal-format or a
  115. * decimal-format with a given name more than once (even with different
  116. * import precedence), unless it is declared every time with the same
  117. * value for all attributes (taking into account any default values).</p>
  118. * <p>The other attributes on xsl:decimal-format correspond to the
  119. * methods on the JDK 1.1 DecimalFormatSymbols class. For each get/set
  120. * method pair there is an attribute defined for the xsl:decimal-format
  121. * element.</p>
  122. *
  123. * @return the decimal format Symbols for this element.
  124. */
  125. public DecimalFormatSymbols getDecimalFormatSymbols()
  126. {
  127. return m_dfs;
  128. }
  129. /**
  130. * If there is a name attribute, then the element declares a named
  131. * decimal-format; otherwise, it declares the default decimal-format.
  132. * @serial
  133. */
  134. private QName m_qname = null;
  135. /**
  136. * Set the "name" attribute.
  137. * If there is a name attribute, then the element declares a named
  138. * decimal-format; otherwise, it declares the default decimal-format.
  139. *
  140. * @param qname The name to set as the "name" attribute.
  141. */
  142. public void setName(QName qname)
  143. {
  144. m_qname = qname;
  145. }
  146. /**
  147. * Get the "name" attribute.
  148. * If there is a name attribute, then the element declares a named
  149. * decimal-format; otherwise, it declares the default decimal-format.
  150. *
  151. * @return the value of the "name" attribute.
  152. */
  153. public QName getName()
  154. {
  155. if (m_qname == null)
  156. return new QName("");
  157. else
  158. return m_qname;
  159. }
  160. /**
  161. * Set the "decimal-separator" attribute.
  162. * decimal-separator specifies the character used for the decimal sign;
  163. * the default value is the period character (.).
  164. *
  165. * @param ds Character to set as decimal separator
  166. */
  167. public void setDecimalSeparator(char ds)
  168. {
  169. m_dfs.setDecimalSeparator(ds);
  170. }
  171. /**
  172. * Get the "decimal-separator" attribute.
  173. * decimal-separator specifies the character used for the decimal sign;
  174. * the default value is the period character (.).
  175. *
  176. * @return the character to use as decimal separator
  177. */
  178. public char getDecimalSeparator()
  179. {
  180. return m_dfs.getDecimalSeparator();
  181. }
  182. /**
  183. * Set the "grouping-separator" attribute.
  184. * grouping-separator specifies the character used as a grouping
  185. * (e.g. thousands) separator; the default value is the comma character (,).
  186. *
  187. * @param gs Character to use a grouping separator
  188. */
  189. public void setGroupingSeparator(char gs)
  190. {
  191. m_dfs.setGroupingSeparator(gs);
  192. }
  193. /**
  194. * Get the "grouping-separator" attribute.
  195. * grouping-separator specifies the character used as a grouping
  196. * (e.g. thousands) separator; the default value is the comma character (,).
  197. *
  198. * @return Character to use a grouping separator
  199. */
  200. public char getGroupingSeparator()
  201. {
  202. return m_dfs.getGroupingSeparator();
  203. }
  204. /**
  205. * Set the "infinity" attribute.
  206. * infinity specifies the string used to represent infinity;
  207. * the default value is the string Infinity.
  208. *
  209. * @param inf String to use as the "infinity" attribute.
  210. */
  211. public void setInfinity(String inf)
  212. {
  213. m_dfs.setInfinity(inf);
  214. }
  215. /**
  216. * Get the "infinity" attribute.
  217. * infinity specifies the string used to represent infinity;
  218. * the default value is the string Infinity.
  219. *
  220. * @return String to use as the "infinity" attribute.
  221. */
  222. public String getInfinity()
  223. {
  224. return m_dfs.getInfinity();
  225. }
  226. /**
  227. * Set the "minus-sign" attribute.
  228. * minus-sign specifies the character used as the default minus sign; the
  229. * default value is the hyphen-minus character (-, #x2D).
  230. *
  231. * @param v Character to use as minus sign
  232. */
  233. public void setMinusSign(char v)
  234. {
  235. m_dfs.setMinusSign(v);
  236. }
  237. /**
  238. * Get the "minus-sign" attribute.
  239. * minus-sign specifies the character used as the default minus sign; the
  240. * default value is the hyphen-minus character (-, #x2D).
  241. *
  242. * @return Character to use as minus sign
  243. */
  244. public char getMinusSign()
  245. {
  246. return m_dfs.getMinusSign();
  247. }
  248. /**
  249. * Set the "NaN" attribute.
  250. * NaN specifies the string used to represent the NaN value;
  251. * the default value is the string NaN.
  252. *
  253. * @param v String to use as the "NaN" attribute.
  254. */
  255. public void setNaN(String v)
  256. {
  257. m_dfs.setNaN(v);
  258. }
  259. /**
  260. * Get the "NaN" attribute.
  261. * NaN specifies the string used to represent the NaN value;
  262. * the default value is the string NaN.
  263. *
  264. * @return String to use as the "NaN" attribute.
  265. */
  266. public String getNaN()
  267. {
  268. return m_dfs.getNaN();
  269. }
  270. /**
  271. * Set the "percent" attribute.
  272. * percent specifies the character used as a percent sign; the default
  273. * value is the percent character (%).
  274. *
  275. * @param v Character to use as percent
  276. */
  277. public void setPercent(char v)
  278. {
  279. m_dfs.setPercent(v);
  280. }
  281. /**
  282. * Get the "percent" attribute.
  283. * percent specifies the character used as a percent sign; the default
  284. * value is the percent character (%).
  285. *
  286. * @return Character to use as percent
  287. */
  288. public char getPercent()
  289. {
  290. return m_dfs.getPercent();
  291. }
  292. /**
  293. * Set the "per-mille" attribute.
  294. * per-mille specifies the character used as a per mille sign; the default
  295. * value is the Unicode per-mille character (#x2030).
  296. *
  297. * @param v Character to use as per-mille
  298. */
  299. public void setPerMille(char v)
  300. {
  301. m_dfs.setPerMill(v);
  302. }
  303. /**
  304. * Get the "per-mille" attribute.
  305. * per-mille specifies the character used as a per mille sign; the default
  306. * value is the Unicode per-mille character (#x2030).
  307. *
  308. * @return Character to use as per-mille
  309. */
  310. public char getPerMille()
  311. {
  312. return m_dfs.getPerMill();
  313. }
  314. /**
  315. * Set the "zero-digit" attribute.
  316. * zero-digit specifies the character used as the digit zero; the default
  317. * value is the digit zero (0).
  318. *
  319. * @param v Character to use as the digit zero
  320. */
  321. public void setZeroDigit(char v)
  322. {
  323. m_dfs.setZeroDigit(v);
  324. }
  325. /**
  326. * Get the "zero-digit" attribute.
  327. * zero-digit specifies the character used as the digit zero; the default
  328. * value is the digit zero (0).
  329. *
  330. * @return Character to use as the digit zero
  331. */
  332. public char getZeroDigit()
  333. {
  334. return m_dfs.getZeroDigit();
  335. }
  336. /**
  337. * Set the "digit" attribute.
  338. * digit specifies the character used for a digit in the format pattern;
  339. * the default value is the number sign character (#).
  340. *
  341. * @param v Character to use for a digit in format pattern
  342. */
  343. public void setDigit(char v)
  344. {
  345. m_dfs.setDigit(v);
  346. }
  347. /**
  348. * Get the "digit" attribute.
  349. * digit specifies the character used for a digit in the format pattern;
  350. * the default value is the number sign character (#).
  351. *
  352. * @return Character to use for a digit in format pattern
  353. */
  354. public char getDigit()
  355. {
  356. return m_dfs.getDigit();
  357. }
  358. /**
  359. * Set the "pattern-separator" attribute.
  360. * pattern-separator specifies the character used to separate positive
  361. * and negative sub patterns in a pattern; the default value is the
  362. * semi-colon character (;).
  363. *
  364. * @param v Character to use as a pattern separator
  365. */
  366. public void setPatternSeparator(char v)
  367. {
  368. m_dfs.setPatternSeparator(v);
  369. }
  370. /**
  371. * Get the "pattern-separator" attribute.
  372. * pattern-separator specifies the character used to separate positive
  373. * and negative sub patterns in a pattern; the default value is the
  374. * semi-colon character (;).
  375. *
  376. * @return Character to use as a pattern separator
  377. */
  378. public char getPatternSeparator()
  379. {
  380. return m_dfs.getPatternSeparator();
  381. }
  382. /**
  383. * This function is called to recompose() all of the decimal format properties elements.
  384. *
  385. * @param root Stylesheet root
  386. */
  387. public void recompose(StylesheetRoot root)
  388. {
  389. root.recomposeDecimalFormats(this);
  390. }
  391. }