| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.style; |
| 9 |
|
| 10 |
import net.sf.saxon.Configuration; |
| 11 |
import net.sf.saxon.om.AttributeCollection; |
| 12 |
import net.sf.saxon.om.StructuredQName; |
| 13 |
import net.sf.saxon.trans.DecimalFormatManager; |
| 14 |
import net.sf.saxon.trans.DecimalSymbols; |
| 15 |
import net.sf.saxon.trans.XPathException; |
| 16 |
import net.sf.saxon.tree.AttributeLocation; |
| 17 |
import net.sf.saxon.value.Whitespace; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public class XSLDecimalFormat extends StyleElement { |
| 24 |
|
| 25 |
boolean prepared = false; |
| 26 |
|
| 27 |
String name; |
| 28 |
String decimalSeparator; |
| 29 |
String groupingSeparator; |
| 30 |
String exponentSeparator; |
| 31 |
String infinity; |
| 32 |
String minusSign; |
| 33 |
String NaN; |
| 34 |
String percent; |
| 35 |
String perMille; |
| 36 |
String zeroDigit; |
| 37 |
String digit; |
| 38 |
String patternSeparator; |
| 39 |
|
| 40 |
DecimalSymbols symbols; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
@Override |
| 50 |
public boolean isDeclaration() { |
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
public void prepareAttributes() throws XPathException { |
| 55 |
|
| 56 |
if (prepared) { |
| 57 |
return; |
| 58 |
} |
| 59 |
prepared = true; |
| 60 |
|
| 61 |
AttributeCollection atts = getAttributeList(); |
| 62 |
|
| 63 |
for (int a = 0; a < atts.getLength(); a++) { |
| 64 |
String f = atts.getQName(a); |
| 65 |
switch (f) { |
| 66 |
case "name": |
| 67 |
name = Whitespace.trim(atts.getValue(a)); |
| 68 |
break; |
| 69 |
case "decimal-separator": |
| 70 |
decimalSeparator = atts.getValue(a); |
| 71 |
break; |
| 72 |
case "grouping-separator": |
| 73 |
groupingSeparator = atts.getValue(a); |
| 74 |
break; |
| 75 |
case "infinity": |
| 76 |
infinity = atts.getValue(a); |
| 77 |
break; |
| 78 |
case "minus-sign": |
| 79 |
minusSign = atts.getValue(a); |
| 80 |
break; |
| 81 |
case "NaN": |
| 82 |
NaN = atts.getValue(a); |
| 83 |
break; |
| 84 |
case "percent": |
| 85 |
percent = atts.getValue(a); |
| 86 |
break; |
| 87 |
case "per-mille": |
| 88 |
perMille = atts.getValue(a); |
| 89 |
break; |
| 90 |
case "zero-digit": |
| 91 |
zeroDigit = atts.getValue(a); |
| 92 |
break; |
| 93 |
case "digit": |
| 94 |
digit = atts.getValue(a); |
| 95 |
break; |
| 96 |
case "exponent-separator": |
| 97 |
exponentSeparator = atts.getValue(a); |
| 98 |
break; |
| 99 |
case "pattern-separator": |
| 100 |
patternSeparator = atts.getValue(a); |
| 101 |
break; |
| 102 |
default: |
| 103 |
checkUnknownAttribute(atts.getNodeName(a)); |
| 104 |
break; |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 110 |
checkTopLevel("XTSE0010", false); |
| 111 |
checkEmpty(); |
| 112 |
int precedence = decl.getPrecedence(); |
| 113 |
|
| 114 |
if (symbols == null) { |
| 115 |
return; |
| 116 |
} |
| 117 |
if (decimalSeparator != null) { |
| 118 |
setProp(DecimalSymbols.DECIMAL_SEPARATOR, decimalSeparator, precedence); |
| 119 |
} |
| 120 |
if (groupingSeparator != null) { |
| 121 |
setProp(DecimalSymbols.GROUPING_SEPARATOR, groupingSeparator, precedence); |
| 122 |
} |
| 123 |
if (infinity != null) { |
| 124 |
setProp(DecimalSymbols.INFINITY, infinity, precedence); |
| 125 |
} |
| 126 |
if (minusSign != null) { |
| 127 |
setProp(DecimalSymbols.MINUS_SIGN, minusSign, precedence); |
| 128 |
} |
| 129 |
if (NaN != null) { |
| 130 |
setProp(DecimalSymbols.NAN, NaN, precedence); |
| 131 |
} |
| 132 |
if (percent != null) { |
| 133 |
setProp(DecimalSymbols.PERCENT, percent, precedence); |
| 134 |
} |
| 135 |
if (perMille != null) { |
| 136 |
setProp(DecimalSymbols.PER_MILLE, perMille, precedence); |
| 137 |
} |
| 138 |
if (zeroDigit != null) { |
| 139 |
setProp(DecimalSymbols.ZERO_DIGIT, zeroDigit, precedence); |
| 140 |
} |
| 141 |
if (digit != null) { |
| 142 |
setProp(DecimalSymbols.DIGIT, digit, precedence); |
| 143 |
} |
| 144 |
if (exponentSeparator != null) { |
| 145 |
setProp(DecimalSymbols.EXPONENT_SEPARATOR, exponentSeparator, precedence); |
| 146 |
} |
| 147 |
if (patternSeparator != null) { |
| 148 |
setProp(DecimalSymbols.PATTERN_SEPARATOR, patternSeparator, precedence); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
private void setProp(int propertyCode, String value, int precedence) throws XPathException { |
| 153 |
try { |
| 154 |
symbols.setProperty(propertyCode, value, precedence); |
| 155 |
} catch (XPathException err) { |
| 156 |
String attName = DecimalSymbols.propertyNames[propertyCode]; |
| 157 |
err.setLocation(new AttributeLocation(this, StructuredQName.fromClarkName(attName))); |
| 158 |
throw err; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public void index(ComponentDeclaration decl, PrincipalStylesheetModule top) throws XPathException { |
| 171 |
prepareAttributes(); |
| 172 |
DecimalFormatManager dfm = getCompilation().getPrincipalStylesheetModule().getDecimalFormatManager(); |
| 173 |
if (name == null) { |
| 174 |
symbols = dfm.getDefaultDecimalFormat(); |
| 175 |
} else { |
| 176 |
try { |
| 177 |
StructuredQName formatName = makeQName(name); |
| 178 |
symbols = dfm.obtainNamedDecimalFormat(formatName); |
| 179 |
symbols.setHostLanguage(Configuration.XSLT, 30); |
| 180 |
} catch (XPathException err) { |
| 181 |
compileErrorInAttribute("Invalid decimal format name. " + err.getMessage(), "XTSE0020", "name"); |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
public void compileDeclaration(Compilation compilation, ComponentDeclaration decl) throws XPathException { |
| 187 |
|
| 188 |
} |
| 189 |
|
| 190 |
} |