1 package com.icl.saxon; 2 3 import java.text.DecimalFormatSymbols ; 4 import java.util.Hashtable ; 5 import javax.xml.transform.TransformerConfigurationException ; 6 7 12 13 public class DecimalFormatManager { 14 15 private DecimalFormatSymbols defaultDFS; 16 private Hashtable formatTable; private boolean usingOriginalDefault = true; 18 19 22 23 public DecimalFormatManager() { 24 formatTable = new Hashtable (); 25 DecimalFormatSymbols d = new DecimalFormatSymbols (); 26 setDefaults(d); 27 defaultDFS = d; 28 } 29 30 33 34 public static void setDefaults(DecimalFormatSymbols d) { 35 d.setDecimalSeparator('.'); 36 d.setGroupingSeparator(','); 37 d.setInfinity("Infinity"); 38 d.setMinusSign('-'); 39 d.setNaN("NaN"); 40 d.setPercent('%'); 41 d.setPerMill('\u2030'); 42 d.setZeroDigit('0'); 43 d.setDigit('#'); 44 d.setPatternSeparator(';'); 45 } 46 47 52 53 public void setDefaultDecimalFormat(DecimalFormatSymbols dfs) 54 throws TransformerConfigurationException { 55 if (!usingOriginalDefault) { 56 if (!dfs.equals(defaultDFS)) { 57 throw new TransformerConfigurationException ( 58 "There are two conflicting definitions of the default decimal format"); 59 } 60 } 61 defaultDFS = dfs; 62 usingOriginalDefault = false; 63 } 64 65 68 69 public DecimalFormatSymbols getDefaultDecimalFormat() { 70 return defaultDFS; 71 } 72 73 78 79 public void setNamedDecimalFormat(int fingerprint, DecimalFormatSymbols dfs) 80 throws TransformerConfigurationException { 81 Integer dfskey = new Integer (fingerprint); 82 DecimalFormatSymbols old = (DecimalFormatSymbols )formatTable.get(dfskey); 83 if (old!=null) { 84 if (!dfs.equals(old)) { 85 throw new TransformerConfigurationException ("Duplicate declaration of decimal-format"); 86 } 87 } 88 formatTable.put(dfskey, dfs); 89 } 90 91 97 98 public DecimalFormatSymbols getNamedDecimalFormat(int fingerprint) { 99 return (DecimalFormatSymbols )formatTable.get(new Integer (fingerprint)); 100 } 101 102 103 } 104 105 | Popular Tags |