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 ; 10 11 14 15 public class XSLDecimalFormat extends StyleElement { 16 17 String name; 18 String decimalSeparator; 19 String groupingSeparator; 20 String infinity; 21 String minusSign; 22 String NaN; 23 String percent; 24 String perMille; 25 String zeroDigit; 26 String digit; 27 String 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 d = new DecimalFormatSymbols (); 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 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 | Popular Tags |