001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: DecimalFormatProperties.java 468643 2006-10-28 06:56:03Z minchau $ 020 */ 021 package org.apache.xalan.templates; 022 023 import java.text.DecimalFormatSymbols; 024 025 import org.apache.xml.utils.QName; 026 027 /** 028 * Implement xsl:decimal-format. 029 * <pre> 030 * <!ELEMENT xsl:decimal-format EMPTY> 031 * <!ATTLIST xsl:decimal-format 032 * name %qname; #IMPLIED 033 * decimal-separator %char; "." 034 * grouping-separator %char; "," 035 * infinity CDATA "Infinity" 036 * minus-sign %char; "-" 037 * NaN CDATA "NaN" 038 * percent %char; "%" 039 * per-mille %char; "‰" 040 * zero-digit %char; "0" 041 * digit %char; "#" 042 * pattern-separator %char; ";" 043 * > 044 * </pre> 045 * @see <a href="http://www.w3.org/TR/xslt#format-number">format-number in XSLT Specification</a> 046 * @xsl.usage advanced 047 */ 048 public class DecimalFormatProperties extends ElemTemplateElement 049 { 050 static final long serialVersionUID = -6559409339256269446L; 051 052 /** An instance of DecimalFormatSymbols for this element. 053 * @serial */ 054 DecimalFormatSymbols m_dfs; 055 056 /** 057 * Constructor DecimalFormatProperties 058 * 059 */ 060 public DecimalFormatProperties(int docOrderNumber) 061 { 062 063 m_dfs = new java.text.DecimalFormatSymbols(); 064 065 // Set default values, they can be overiden if necessary. 066 m_dfs.setInfinity(Constants.ATTRVAL_INFINITY); 067 m_dfs.setNaN(Constants.ATTRVAL_NAN); 068 069 m_docOrderNumber = docOrderNumber; 070 } 071 072 /** 073 * Return the decimal format Symbols for this element. 074 * <p>The xsl:decimal-format element declares a decimal-format, 075 * which controls the interpretation of a format pattern used by 076 * the format-number function. If there is a name attribute, then 077 * the element declares a named decimal-format; otherwise, it 078 * declares the default decimal-format. The value of the name 079 * attribute is a QName, which is expanded as described in [2.4 Qualified Names]. 080 * It is an error to declare either the default decimal-format or a 081 * decimal-format with a given name more than once (even with different 082 * import precedence), unless it is declared every time with the same 083 * value for all attributes (taking into account any default values).</p> 084 * <p>The other attributes on xsl:decimal-format correspond to the 085 * methods on the JDK 1.1 DecimalFormatSymbols class. For each get/set 086 * method pair there is an attribute defined for the xsl:decimal-format 087 * element.</p> 088 * 089 * @return the decimal format Symbols for this element. 090 */ 091 public DecimalFormatSymbols getDecimalFormatSymbols() 092 { 093 return m_dfs; 094 } 095 096 /** 097 * If there is a name attribute, then the element declares a named 098 * decimal-format; otherwise, it declares the default decimal-format. 099 * @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 }