1 16 19 package org.apache.xalan.processor; 20 21 import java.lang.reflect.InvocationTargetException ; 22 import java.lang.reflect.Method ; 23 import java.util.StringTokenizer ; 24 import java.util.Vector ; 25 26 import javax.xml.transform.TransformerException ; 27 28 import org.apache.xalan.res.XSLMessages; 29 import org.apache.xalan.res.XSLTErrorResources; 30 import org.apache.xalan.templates.AVT; 31 import org.apache.xalan.templates.Constants; 32 import org.apache.xalan.templates.ElemTemplateElement; 33 import org.apache.xml.utils.QName; 34 import org.apache.xml.utils.StringToIntTable; 35 import org.apache.xml.utils.StringVector; 36 import org.apache.xml.utils.XMLChar; 37 import org.apache.xpath.XPath; 38 39 40 45 public class XSLTAttributeDef 46 { 47 static final int FATAL = 0; 49 static final int ERROR = 1; 50 static final int WARNING = 2; 51 52 53 65 XSLTAttributeDef(String namespace, String name, int type, boolean required, boolean supportsAVT, int errorType) 66 { 67 this.m_namespace = namespace; 68 this.m_name = name; 69 this.m_type = type; 70 this.m_required = required; 71 this.m_supportsAVT = supportsAVT; 72 this.m_errorType = errorType; 73 } 74 75 88 XSLTAttributeDef(String namespace, String name, int type, boolean supportsAVT, int errorType, String defaultVal) 89 { 90 91 this.m_namespace = namespace; 92 this.m_name = name; 93 this.m_type = type; 94 this.m_required = false; 95 this.m_supportsAVT = supportsAVT; 96 this.m_errorType = errorType; 97 this.m_default = defaultVal; 98 } 99 100 115 XSLTAttributeDef(String namespace, String name, boolean required, boolean supportsAVT, 116 boolean prefixedQNameValAllowed, int errorType, String k1, int v1, String k2, int v2) 117 { 118 119 this.m_namespace = namespace; 120 this.m_name = name; 121 this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM; 122 this.m_required = required; 123 this.m_supportsAVT = supportsAVT; 124 this.m_errorType = errorType; 125 m_enums = new StringToIntTable(2); 126 127 m_enums.put(k1, v1); 128 m_enums.put(k2, v2); 129 } 130 131 148 XSLTAttributeDef(String namespace, String name, boolean required, boolean supportsAVT, 149 boolean prefixedQNameValAllowed, int errorType, String k1, int v1, String k2, int v2, String k3, int v3) 150 { 151 152 this.m_namespace = namespace; 153 this.m_name = name; 154 this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM; 155 this.m_required = required; 156 this.m_supportsAVT = supportsAVT; 157 this.m_errorType = errorType; 158 m_enums = new StringToIntTable(3); 159 160 m_enums.put(k1, v1); 161 m_enums.put(k2, v2); 162 m_enums.put(k3, v3); 163 } 164 165 183 XSLTAttributeDef(String namespace, String name, boolean required, boolean supportsAVT, 184 boolean prefixedQNameValAllowed, int errorType, String k1, int v1, String k2, int v2, 185 String k3, int v3, String k4, int v4) 186 { 187 188 this.m_namespace = namespace; 189 this.m_name = name; 190 this.m_type = prefixedQNameValAllowed ? this.T_ENUM_OR_PQNAME : this.T_ENUM; 191 this.m_required = required; 192 this.m_supportsAVT = supportsAVT; 193 this.m_errorType = errorType; 194 m_enums = new StringToIntTable(4); 195 196 m_enums.put(k1, v1); 197 m_enums.put(k2, v2); 198 m_enums.put(k3, v3); 199 m_enums.put(k4, v4); 200 } 201 202 203 static final int T_CDATA = 1, 204 205 T_URL = 2, 207 208 T_AVT = 3, 212 T_PATTERN = 4, 214 215 T_EXPR = 5, 217 218 T_CHAR = 6, 221 222 T_NUMBER = 7, 224 225 T_YESNO = 8, 227 228 T_QNAME = 9, 231 232 T_QNAMES = 10, 235 236 T_ENUM = 11, 238 239 T_SIMPLEPATTERNLIST = 12, 241 242 T_NMTOKEN = 13, 244 245 T_STRINGLIST = 14, 247 248 T_PREFIX_URLLIST = 15, 252 253 T_ENUM_OR_PQNAME = 16, 255 256 T_NCNAME = 17, 258 259 T_AVT_QNAME = 18, 261 262 T_QNAMES_RESOLVE_NULL = 19, 265 266 T_PREFIXLIST = 20; 270 271 272 static XSLTAttributeDef m_foreignAttr = new XSLTAttributeDef("*", "*", 273 XSLTAttributeDef.T_CDATA,false, false, WARNING); 274 275 276 static String S_FOREIGNATTR_SETTER = "setForeignAttr"; 277 278 281 private String m_namespace; 282 283 288 String getNamespace() 289 { 290 return m_namespace; 291 } 292 293 296 private String m_name; 297 298 303 String getName() 304 { 305 return m_name; 306 } 307 308 311 private int m_type; 312 313 320 int getType() 321 { 322 return m_type; 323 } 324 325 330 private StringToIntTable m_enums; 331 332 341 private int getEnum(String key) 342 { 343 return m_enums.get(key); 344 } 345 346 354 private String [] getEnumNames() 355 { 356 return m_enums.keys(); 357 } 358 359 362 private String m_default; 363 364 369 String getDefault() 370 { 371 return m_default; 372 } 373 374 379 void setDefault(String def) 380 { 381 m_default = def; 382 } 383 384 387 private boolean m_required; 388 389 394 boolean getRequired() 395 { 396 return m_required; 397 } 398 399 402 private boolean m_supportsAVT; 403 404 409 boolean getSupportsAVT() 410 { 411 return m_supportsAVT; 412 } 413 414 int m_errorType = this.WARNING; 415 416 421 int getErrorType() 422 { 423 return m_errorType; 424 } 425 429 String m_setterString = null; 430 431 441 public String getSetterMethodName() 442 { 443 444 if (null == m_setterString) 445 { 446 if (m_foreignAttr == this) 447 { 448 return S_FOREIGNATTR_SETTER; 449 } 450 else if (m_name.equals("*")) 451 { 452 m_setterString = "addLiteralResultAttribute"; 453 454 return m_setterString; 455 } 456 457 StringBuffer outBuf = new StringBuffer (); 458 459 outBuf.append("set"); 460 461 if ((m_namespace != null) 462 && m_namespace.equals(Constants.S_XMLNAMESPACEURI)) 463 { 464 outBuf.append("Xml"); 465 } 466 467 int n = m_name.length(); 468 469 for (int i = 0; i < n; i++) 470 { 471 char c = m_name.charAt(i); 472 473 if ('-' == c) 474 { 475 i++; 476 477 c = m_name.charAt(i); 478 c = Character.toUpperCase(c); 479 } 480 else if (0 == i) 481 { 482 c = Character.toUpperCase(c); 483 } 484 485 outBuf.append(c); 486 } 487 488 m_setterString = outBuf.toString(); 489 } 490 491 return m_setterString; 492 } 493 494 510 AVT processAVT( 511 StylesheetHandler handler, String uri, String name, String rawName, String value, 512 ElemTemplateElement owner) 513 throws org.xml.sax.SAXException 514 { 515 516 try 517 { 518 AVT avt = new AVT(handler, uri, name, rawName, value, owner); 519 520 return avt; 521 } 522 catch (TransformerException te) 523 { 524 throw new org.xml.sax.SAXException (te); 525 } 526 } 527 528 542 Object processCDATA(StylesheetHandler handler, String uri, String name, 543 String rawName, String value, ElemTemplateElement owner) 544 throws org.xml.sax.SAXException 545 { 546 if (getSupportsAVT()) { 547 try 548 { 549 AVT avt = new AVT(handler, uri, name, rawName, value, owner); 550 return avt; 551 } 552 catch (TransformerException te) 553 { 554 throw new org.xml.sax.SAXException (te); 555 } 556 } else { 557 return value; 558 } 559 } 560 561 575 Object processCHAR( 576 StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) 577 throws org.xml.sax.SAXException 578 { 579 if (getSupportsAVT()) { 580 try 581 { 582 AVT avt = new AVT(handler, uri, name, rawName, value, owner); 583 584 if ((avt.isSimple()) && (value.length() != 1)) { 586 handleError(handler, XSLTErrorResources.INVALID_TCHAR, new Object [] {name, value},null); 587 return null; 588 } 589 return avt; 590 } 591 catch (TransformerException te) 592 { 593 throw new org.xml.sax.SAXException (te); 594 } 595 } else { 596 if (value.length() != 1) 597 { 598 handleError(handler, XSLTErrorResources.INVALID_TCHAR, new Object [] {name, value},null); 599 return null; 600 } 601 602 return new Character (value.charAt(0)); 603 } 604 } 605 606 620 Object processENUM(StylesheetHandler handler, String uri, String name, 621 String rawName, String value, ElemTemplateElement owner) 622 throws org.xml.sax.SAXException 623 { 624 625 AVT avt = null; 626 if (getSupportsAVT()) { 627 try 628 { 629 avt = new AVT(handler, uri, name, rawName, value, owner); 630 631 if (!avt.isSimple()) return avt; 633 } 634 catch (TransformerException te) 635 { 636 throw new org.xml.sax.SAXException (te); 637 } 638 } 639 640 int retVal = this.getEnum(value); 641 642 if (retVal == StringToIntTable.INVALID_KEY) 643 { 644 StringBuffer enumNamesList = getListOfEnums(); 645 handleError(handler, XSLTErrorResources.INVALID_ENUM,new Object []{name, value, enumNamesList.toString() },null); 646 return null; 647 } 648 649 if (getSupportsAVT()) return avt; 650 else return new Integer (retVal); 651 652 } 653 654 670 Object processENUM_OR_PQNAME(StylesheetHandler handler, String uri, String name, 671 String rawName, String value, ElemTemplateElement owner) 672 throws org.xml.sax.SAXException 673 { 674 675 Object objToReturn = null; 676 677 if (getSupportsAVT()) { 678 try 679 { 680 AVT avt = new AVT(handler, uri, name, rawName, value, owner); 681 if (!avt.isSimple()) return avt; 682 else objToReturn = avt; 683 } 684 catch (TransformerException te) 685 { 686 throw new org.xml.sax.SAXException (te); 687 } 688 } 689 690 int key = this.getEnum(value); 692 693 if (key != StringToIntTable.INVALID_KEY) 694 { 695 if (objToReturn == null) objToReturn = new Integer (key); 696 } 697 698 else 700 { 701 try 702 { 703 QName qname = new QName(value, handler, true); 704 if (objToReturn == null) objToReturn = qname; 705 706 if (qname.getPrefix() == null) { 707 StringBuffer enumNamesList = getListOfEnums(); 708 709 enumNamesList.append(" <qname-but-not-ncname>"); 710 handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object []{name, value, enumNamesList.toString() },null); 711 return null; 712 713 } 714 } 715 catch (IllegalArgumentException ie) 716 { 717 StringBuffer enumNamesList = getListOfEnums(); 718 enumNamesList.append(" <qname-but-not-ncname>"); 719 720 handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object []{name, value, enumNamesList.toString() },ie); 721 return null; 722 723 } 724 catch (RuntimeException re) 725 { 726 StringBuffer enumNamesList = getListOfEnums(); 727 enumNamesList.append(" <qname-but-not-ncname>"); 728 729 handleError(handler,XSLTErrorResources.INVALID_ENUM,new Object []{name, value, enumNamesList.toString() },re); 730 return null; 731 } 732 } 733 734 return objToReturn; 735 } 736 737 753 Object processEXPR( 754 StylesheetHandler handler, String uri, String name, String rawName, String value, 755 ElemTemplateElement owner) 756 throws org.xml.sax.SAXException 757 { 758 759 try 760 { 761 XPath expr = handler.createXPath(value, owner); 762 763 return expr; 764 } 765 catch (TransformerException te) 766 { 767 org.xml.sax.SAXException se = new org.xml.sax.SAXException (te); 768 throw new org.xml.sax.SAXException (te); 769 } 770 } 771 772 786 Object processNMTOKEN(StylesheetHandler handler, String uri, String name, 787 String rawName, String value, ElemTemplateElement owner) 788 throws org.xml.sax.SAXException 789 { 790 791 if (getSupportsAVT()) { 792 try 793 { 794 AVT avt = new AVT(handler, uri, name, rawName, value, owner); 795 796 if ((avt.isSimple()) && (!XMLChar.isValidNmtoken(value))) { 798 handleError(handler,XSLTErrorResources.INVALID_NMTOKEN, new Object [] {name,value},null); 799 return null; 800 } 801 return avt; 802 } 803 catch (TransformerException te) 804 { 805 throw new org.xml.sax.SAXException (te); 806 } 807 } else { 808 if (!XMLChar.isValidNmtoken(value)) { 809 handleError(handler,XSLTErrorResources.INVALID_NMTOKEN, new Object [] {name,value},null); 810 return null; 811 } 812 } 813 return value; 814 } 815 816 832 Object processPATTERN( 833 StylesheetHandler handler, String uri, String name, String rawName, String value, 834 ElemTemplateElement owner) 835 throws org.xml.sax.SAXException 836 { 837 838 try 839 { 840 XPath pattern = handler.createMatchPatternXPath(value, owner); 841 842 return pattern; 843 } 844 catch (TransformerException te) 845 { 846 throw new org.xml.sax.SAXException (te); 847 } 848 } 849 850 867 Object processNUMBER( 868 StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) 869 throws org.xml.sax.SAXException 870 { 871 872 873 if (getSupportsAVT()) 874 { 875 Double val; 876 AVT avt = null; 877 try 878 { 879 avt = new AVT(handler, uri, name, rawName, value, owner); 880 881 if (avt.isSimple()) 883 { 884 val = Double.valueOf(value); 885 } 886 } 887 catch (TransformerException te) 888 { 889 throw new org.xml.sax.SAXException (te); 890 } 891 catch (NumberFormatException nfe) 892 { 893 handleError(handler,XSLTErrorResources.INVALID_NUMBER, new Object [] {name, value}, nfe); 894 return null; 895 } 896 return avt; 897 898 } 899 else 900 { 901 try 902 { 903 return Double.valueOf(value); 904 } 905 catch (NumberFormatException nfe) 906 { 907 handleError(handler,XSLTErrorResources.INVALID_NUMBER, new Object [] {name, value}, nfe); 908 return null; 909 } 910 } 911 } 912 913 929 Object processQNAME( 930 StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) 931 throws org.xml.sax.SAXException 932 { 933 934 try 935 { 936 QName qname = new QName(value, handler, true); 937 return qname; 938 } 939 catch (IllegalArgumentException ie) 940 { 941 handleError(handler,XSLTErrorResources.INVALID_QNAME, new Object [] {name, value},ie); 943 return null; 944 } 945 catch (RuntimeException re) { 946 handleError(handler,XSLTErrorResources.INVALID_QNAME, new Object [] {name, value},re); 948 return null; 949 } 950 } 951 952 953 968 Object processAVT_QNAME( 969 StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) 970 throws org.xml.sax.SAXException 971 { 972 973 AVT avt = null; 974 try 975 { 976 avt = new AVT(handler, uri, name, rawName, value, owner); 977 978 if (avt.isSimple()) 980 { 981 int indexOfNSSep = value.indexOf(':'); 982 983 if (indexOfNSSep >= 0) 984 { 985 String prefix = value.substring(0, indexOfNSSep); 986 if (!XMLChar.isValidNCName(prefix)) 987 { 988 handleError(handler,XSLTErrorResources.INVALID_QNAME,new Object []{name,value },null); 989 return null; 990 } 991 } 992 993 String localName = (indexOfNSSep < 0) 994 ? value : value.substring(indexOfNSSep + 1); 995 996 if ((localName == null) || (localName.length() == 0) || 997 (!XMLChar.isValidNCName(localName))) 998 { 999 handleError(handler,XSLTErrorResources.INVALID_QNAME,new Object []{name,value },null ); 1000 return null; 1001 } 1002 } 1003 } 1004 catch (TransformerException te) 1005 { 1006 throw new org.xml.sax.SAXException (te); 1008 } 1009 1010 return avt; 1011 } 1012 1013 1029 Object processNCNAME( 1030 StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) 1031 throws org.xml.sax.SAXException 1032 { 1033 1034 if (getSupportsAVT()) 1035 { 1036 AVT avt = null; 1037 try 1038 { 1039 avt = new AVT(handler, uri, name, rawName, value, owner); 1040 1041 if ((avt.isSimple()) && (!XMLChar.isValidNCName(value))) 1043 { 1044 handleError(handler,XSLTErrorResources.INVALID_NCNAME,new Object [] {name,value},null); 1045 return null; 1046 } 1047 return avt; 1048 } 1049 catch (TransformerException te) 1050 { 1051 throw new org.xml.sax.SAXException (te); 1053 } 1054 1055 } else { 1056 if (!XMLChar.isValidNCName(value)) 1057 { 1058 handleError(handler,XSLTErrorResources.INVALID_NCNAME,new Object [] {name,value},null); 1059 return null; 1060 } 1061 return value; 1062 } 1063 } 1064 1065 1082 Vector processQNAMES( 1083 StylesheetHandler handler, String uri, String name, String rawName, String value) 1084 throws org.xml.sax.SAXException 1085 { 1086 1087 StringTokenizer tokenizer = new StringTokenizer (value, " \t\n\r\f"); 1088 int nQNames = tokenizer.countTokens(); 1089 Vector qnames = new Vector (nQNames); 1090 1091 for (int i = 0; i < nQNames; i++) 1092 { 1093 qnames.addElement(new QName(tokenizer.nextToken(), handler)); 1095 } 1096 1097 return qnames; 1098 } 1099 1100 1119 final Vector processQNAMESRNU(StylesheetHandler handler, String uri, 1120 String name, String rawName, String value) 1121 throws org.xml.sax.SAXException 1122 { 1123 1124 StringTokenizer tokenizer = new StringTokenizer (value, " \t\n\r\f"); 1125 int nQNames = tokenizer.countTokens(); 1126 Vector qnames = new Vector (nQNames); 1127 1128 String defaultURI = handler.getNamespaceForPrefix(""); 1129 for (int i = 0; i < nQNames; i++) 1130 { 1131 String tok = tokenizer.nextToken(); 1132 if (tok.indexOf(':') == -1) { 1133 qnames.addElement(new QName(defaultURI,tok)); 1134 } else { 1135 qnames.addElement(new QName(tok, handler)); 1136 } 1137 } 1138 return qnames; 1139 } 1140 1141 1157 Vector processSIMPLEPATTERNLIST( 1158 StylesheetHandler handler, String uri, String name, String rawName, String value, 1159 ElemTemplateElement owner) 1160 throws org.xml.sax.SAXException 1161 { 1162 1163 try 1164 { 1165 StringTokenizer tokenizer = new StringTokenizer (value, " \t\n\r\f"); 1166 int nPatterns = tokenizer.countTokens(); 1167 Vector patterns = new Vector (nPatterns); 1168 1169 for (int i = 0; i < nPatterns; i++) 1170 { 1171 XPath pattern = 1172 handler.createMatchPatternXPath(tokenizer.nextToken(), owner); 1173 1174 patterns.addElement(pattern); 1175 } 1176 1177 return patterns; 1178 } 1179 catch (TransformerException te) 1180 { 1181 throw new org.xml.sax.SAXException (te); 1182 } 1183 } 1184 1185 1197 StringVector processSTRINGLIST(StylesheetHandler handler, String uri, 1198 String name, String rawName, String value) 1199 { 1200 1201 StringTokenizer tokenizer = new StringTokenizer (value, " \t\n\r\f"); 1202 int nStrings = tokenizer.countTokens(); 1203 StringVector strings = new StringVector(nStrings); 1204 1205 for (int i = 0; i < nStrings; i++) 1206 { 1207 strings.addElement(tokenizer.nextToken()); 1208 } 1209 1210 return strings; 1211 } 1212 1213 1227 StringVector processPREFIX_URLLIST( 1228 StylesheetHandler handler, String uri, String name, String rawName, String value) 1229 throws org.xml.sax.SAXException 1230 { 1231 1232 StringTokenizer tokenizer = new StringTokenizer (value, " \t\n\r\f"); 1233 int nStrings = tokenizer.countTokens(); 1234 StringVector strings = new StringVector(nStrings); 1235 1236 for (int i = 0; i < nStrings; i++) 1237 { 1238 String prefix = tokenizer.nextToken(); 1239 String url = handler.getNamespaceForPrefix(prefix); 1240 1241 if (url != null) 1242 strings.addElement(url); 1243 else 1244 throw new org.xml.sax.SAXException (XSLMessages.createMessage(XSLTErrorResources.ER_CANT_RESOLVE_NSPREFIX, new Object [] {prefix})); 1245 1246 } 1247 1248 return strings; 1249 } 1250 1251 1265 StringVector processPREFIX_LIST( 1266 StylesheetHandler handler, String uri, String name, 1267 String rawName, String value) throws org.xml.sax.SAXException 1268 { 1269 1270 StringTokenizer tokenizer = new StringTokenizer (value, " \t\n\r\f"); 1271 int nStrings = tokenizer.countTokens(); 1272 StringVector strings = new StringVector(nStrings); 1273 1274 for (int i = 0; i < nStrings; i++) 1275 { 1276 String prefix = tokenizer.nextToken(); 1277 String url = handler.getNamespaceForPrefix(prefix); 1278 if (prefix.equals(Constants.ATTRVAL_DEFAULT_PREFIX) || url != null) 1279 strings.addElement(prefix); 1280 else 1281 throw new org.xml.sax.SAXException ( 1282 XSLMessages.createMessage( 1283 XSLTErrorResources.ER_CANT_RESOLVE_NSPREFIX, 1284 new Object [] {prefix})); 1285 1286 } 1287 1288 return strings; 1289 } 1290 1291 1292 1307 Object processURL( 1308 StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) 1309 throws org.xml.sax.SAXException 1310 { 1311 1312 if (getSupportsAVT()) { 1313 try 1314 { 1315 AVT avt = new AVT(handler, uri, name, rawName, value, owner); 1316 1317 return avt; 1324 } 1325 catch (TransformerException te) 1326 { 1327 throw new org.xml.sax.SAXException (te); 1328 } 1329 } else { 1330 1334 return value; 1335 } 1336 } 1337 1338 1352 private Boolean processYESNO( 1353 StylesheetHandler handler, String uri, String name, String rawName, String value) 1354 throws org.xml.sax.SAXException 1355 { 1356 1357 if (!(value.equals("yes") || value.equals("no"))) 1359 { 1360 handleError(handler, XSLTErrorResources.INVALID_BOOLEAN, new Object [] {name,value}, null); 1361 return null; 1362 } 1363 1364 return new Boolean (value.equals("yes") ? true : false); 1365 } 1366 1367 1380 Object processValue( 1381 StylesheetHandler handler, String uri, String name, String rawName, String value, 1382 ElemTemplateElement owner) 1383 throws org.xml.sax.SAXException 1384 { 1385 1386 int type = getType(); 1387 Object processedValue = null; 1388 1389 switch (type) 1390 { 1391 case T_AVT : 1392 processedValue = processAVT(handler, uri, name, rawName, value, owner); 1393 break; 1394 case T_CDATA : 1395 processedValue = processCDATA(handler, uri, name, rawName, value, owner); 1396 break; 1397 case T_CHAR : 1398 processedValue = processCHAR(handler, uri, name, rawName, value, owner); 1399 break; 1400 case T_ENUM : 1401 processedValue = processENUM(handler, uri, name, rawName, value, owner); 1402 break; 1403 case T_EXPR : 1404 processedValue = processEXPR(handler, uri, name, rawName, value, owner); 1405 break; 1406 case T_NMTOKEN : 1407 processedValue = processNMTOKEN(handler, uri, name, rawName, value, owner); 1408 break; 1409 case T_PATTERN : 1410 processedValue = processPATTERN(handler, uri, name, rawName, value, owner); 1411 break; 1412 case T_NUMBER : 1413 processedValue = processNUMBER(handler, uri, name, rawName, value, owner); 1414 break; 1415 case T_QNAME : 1416 processedValue = processQNAME(handler, uri, name, rawName, value, owner); 1417 break; 1418 case T_QNAMES : 1419 processedValue = processQNAMES(handler, uri, name, rawName, value); 1420 break; 1421 case T_QNAMES_RESOLVE_NULL: 1422 processedValue = processQNAMESRNU(handler, uri, name, rawName, value); 1423 break; 1424 case T_SIMPLEPATTERNLIST : 1425 processedValue = processSIMPLEPATTERNLIST(handler, uri, name, rawName, 1426 value, owner); 1427 break; 1428 case T_URL : 1429 processedValue = processURL(handler, uri, name, rawName, value, owner); 1430 break; 1431 case T_YESNO : 1432 processedValue = processYESNO(handler, uri, name, rawName, value); 1433 break; 1434 case T_STRINGLIST : 1435 processedValue = processSTRINGLIST(handler, uri, name, rawName, value); 1436 break; 1437 case T_PREFIX_URLLIST : 1438 processedValue = processPREFIX_URLLIST(handler, uri, name, rawName, 1439 value); 1440 break; 1441 case T_ENUM_OR_PQNAME : 1442 processedValue = processENUM_OR_PQNAME(handler, uri, name, rawName, value, owner); 1443 break; 1444 case T_NCNAME : 1445 processedValue = processNCNAME(handler, uri, name, rawName, value, owner); 1446 break; 1447 case T_AVT_QNAME : 1448 processedValue = processAVT_QNAME(handler, uri, name, rawName, value, owner); 1449 break; 1450 case T_PREFIXLIST : 1451 processedValue = processPREFIX_LIST(handler, uri, name, rawName, 1452 value); 1453 break; 1454 1455 default : 1456 } 1457 1458 return processedValue; 1459 } 1460 1461 1470 void setDefAttrValue(StylesheetHandler handler, ElemTemplateElement elem) 1471 throws org.xml.sax.SAXException 1472 { 1473 setAttrValue(handler, this.getNamespace(), this.getName(), 1474 this.getName(), this.getDefault(), elem); 1475 } 1476 1477 1488 private Class getPrimativeClass(Object obj) 1489 { 1490 1491 if (obj instanceof XPath) 1492 return XPath.class; 1493 1494 Class cl = obj.getClass(); 1495 1496 if (cl == Double .class) 1497 { 1498 cl = double.class; 1499 } 1500 1501 if (cl == Float .class) 1502 { 1503 cl = float.class; 1504 } 1505 else if (cl == Boolean .class) 1506 { 1507 cl = boolean.class; 1508 } 1509 else if (cl == Byte .class) 1510 { 1511 cl = byte.class; 1512 } 1513 else if (cl == Character .class) 1514 { 1515 cl = char.class; 1516 } 1517 else if (cl == Short .class) 1518 { 1519 cl = short.class; 1520 } 1521 else if (cl == Integer .class) 1522 { 1523 cl = int.class; 1524 } 1525 else if (cl == Long .class) 1526 { 1527 cl = long.class; 1528 } 1529 1530 return cl; 1531 } 1532 1533 1537 private StringBuffer getListOfEnums() 1538 { 1539 StringBuffer enumNamesList = new StringBuffer (); 1540 String [] enumValues = this.getEnumNames(); 1541 1542 for (int i = 0; i < enumValues.length; i++) 1543 { 1544 if (i > 0) 1545 { 1546 enumNamesList.append(' '); 1547 } 1548 enumNamesList.append(enumValues[i]); 1549 } 1550 return enumNamesList; 1551 } 1552 1553 1565 boolean setAttrValue( 1566 StylesheetHandler handler, String attrUri, String attrLocalName, 1567 String attrRawName, String attrValue, ElemTemplateElement elem) 1568 throws org.xml.sax.SAXException 1569 { 1570 if(attrRawName.equals("xmlns") || attrRawName.startsWith("xmlns:")) 1571 return true; 1572 1573 String setterString = getSetterMethodName(); 1574 1575 if (null != setterString) 1578 { 1579 try 1580 { 1581 Method meth; 1582 Object [] args; 1583 1584 if(setterString.equals(S_FOREIGNATTR_SETTER)) 1585 { 1586 if( attrUri==null) attrUri=""; 1588 Class sclass = attrUri.getClass(); 1590 Class [] argTypes = new Class []{ sclass, sclass, 1591 sclass, sclass }; 1592 1593 meth = elem.getClass().getMethod(setterString, argTypes); 1594 1595 args = new Object []{ attrUri, attrLocalName, 1596 attrRawName, attrValue }; 1597 } 1598 else 1599 { 1600 Object value = processValue(handler, attrUri, attrLocalName, 1601 attrRawName, attrValue, elem); 1602 if (null == value) return false; 1605 1606 Class [] argTypes = new Class []{ getPrimativeClass(value) }; 1608 1609 try 1610 { 1611 meth = elem.getClass().getMethod(setterString, argTypes); 1612 } 1613 catch (NoSuchMethodException nsme) 1614 { 1615 Class cl = ((Object ) value).getClass(); 1616 1617 argTypes[0] = cl; 1619 meth = elem.getClass().getMethod(setterString, argTypes); 1620 } 1621 1622 args = new Object []{ value }; 1623 } 1624 1625 meth.invoke(elem, args); 1626 } 1627 catch (NoSuchMethodException nsme) 1628 { 1629 if (!setterString.equals(S_FOREIGNATTR_SETTER)) 1630 { 1631 handler.error(XSLTErrorResources.ER_FAILED_CALLING_METHOD, new Object []{setterString}, nsme); return false; 1633 } 1634 } 1635 catch (IllegalAccessException iae) 1636 { 1637 handler.error(XSLTErrorResources.ER_FAILED_CALLING_METHOD, new Object []{setterString}, iae); return false; 1639 } 1640 catch (InvocationTargetException nsme) 1641 { 1642 handleError(handler, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE, 1643 new Object []{ Constants.ATTRNAME_NAME, getName()}, nsme); 1644 return false; 1645 } 1646 } 1647 1648 return true; 1649 } 1650 1651 private void handleError(StylesheetHandler handler, String msg, Object [] args, Exception exc) throws org.xml.sax.SAXException 1652 { 1653 switch (getErrorType()) 1654 { 1655 case (FATAL): 1656 case (ERROR): 1657 handler.error(msg, args, exc); 1658 break; 1659 case (WARNING): 1660 handler.warn(msg, args); 1661 default: break; 1662 } 1663 } 1664} 1665 | Popular Tags |