1 28 29 package com.caucho.xsl.java; 30 31 import com.caucho.java.JavaWriter; 32 import com.caucho.xml.QName; 33 import com.caucho.xpath.Expr; 34 import com.caucho.xpath.pattern.AbstractPattern; 35 import com.caucho.xsl.XslNumberFormat; 36 import com.caucho.xsl.XslParseException; 37 38 41 public class XslNumber extends XslNode { 42 private String _value; 43 private String _count; 44 private String _from; 45 private String _level = "single"; 46 private String _format; 47 private String _letter; 48 private String _lang; 49 private String _groupingSeparator; 50 private String _groupingSize = ""; 51 52 55 public String getTagName() 56 { 57 return "xsl:number"; 58 } 59 60 63 public void addAttribute(QName name, String value) 64 throws XslParseException 65 { 66 if ("value".equals(name.getName())) { 67 _value = value; 68 } 69 else if ("count".equals(name.getName())) { 70 _count = value; 71 } 72 else if ("from".equals(name.getName())) { 73 _from = value; 74 } 75 else if ("level".equals(name.getName())) { 76 _level = value; 77 } 78 else if ("format".equals(name.getName())) { 79 _format = value; 80 } 81 else if ("letter-value".equals(name.getName())) { 82 _letter = value; 83 } 84 else if ("lang".equals(name.getName())) { 85 _lang = value; 86 } 87 else if ("grouping-separator".equals(name.getName())) { 88 _groupingSeparator = value; 89 } 90 else if ("grouping-size".equals(name.getName())) { 91 _groupingSize = value; 92 } 93 else 94 super.addAttribute(name, value); 95 } 96 97 100 public void endAttributes() 101 throws XslParseException 102 { 103 } 104 105 110 public void generate(JavaWriter out) 111 throws Exception 112 { 113 int size = 0; 114 115 for (int i = 0; i < _groupingSize.length(); i++) { 116 char ch = _groupingSize.charAt(i); 117 if (ch >= '0' && ch <= '9') 118 size = 10 * size + ch - '0'; 119 } 120 121 boolean isAlphabetic = true; 122 if (! "alphabetic".equals(_letter)) 123 isAlphabetic = false; 124 125 AbstractPattern countPattern = null; 126 if (_count != null) 127 countPattern = parseMatch(_count); 128 129 AbstractPattern fromPattern = null; 130 if (_from != null) 131 fromPattern = parseMatch(_from); 132 133 if (_level == null || _level.equals("single")) { 134 _level = "single"; 135 } 136 else if (_level.equals("multiple")) { 137 } 138 else if (_level.equals("any")) { 139 } 140 else 141 throw error(L.l("xsl:number can't understand level=`{0}'", 142 _level)); 143 144 XslNumberFormat xslFormat; 145 xslFormat = new XslNumberFormat(_format, _lang, isAlphabetic, 146 _groupingSeparator, size); 147 148 if (_value != null) 149 printNumber(out, parseExpr(_value), xslFormat); 150 else 151 printNumber(out, _level, countPattern, fromPattern, xslFormat); 152 } 153 154 void printNumber(JavaWriter out, Expr expr, XslNumberFormat format) 155 throws Exception 156 { 157 int index = _gen.addExpr(expr); 158 159 out.print("exprNumber(out, node, env, _exprs[" + index + "]"); 160 out.print(", _xsl_formats[" + _gen.addFormat(format) + "]"); 161 out.println(");"); 162 } 163 164 void printNumber(JavaWriter out, String level, 165 AbstractPattern countPattern, 166 AbstractPattern fromPattern, 167 XslNumberFormat format) 168 throws Exception 169 { 170 if (level.equals("single")) 171 out.print("singleNumber(out, "); 172 else if (level.equals("multiple")) 173 out.print("multiNumber(out, "); 174 else if (level.equals("any")) 175 out.print("anyNumber(out, "); 176 else 177 throw error(L.l("xsl:number cannot understand level='{0}'", 178 level)); 179 180 out.print("node, env, "); 181 printPattern(out, countPattern); 182 out.print(", "); 183 printPattern(out, fromPattern); 184 out.print(", _xsl_formats[" + _gen.addFormat(format) + "]"); 185 out.println(");"); 186 } 187 188 void printPattern(JavaWriter out, AbstractPattern pattern) 189 throws Exception 190 { 191 if (pattern == null) 192 out.print("null"); 193 else { 194 out.print("_match_patterns[" + _gen.addMatch(pattern) + "]"); 195 } 196 } 197 } 198 | Popular Tags |