1 57 58 package org.enhydra.apache.xerces.validators.schema; 59 60 import java.util.Enumeration ; 61 import java.util.Hashtable ; 62 import java.util.StringTokenizer ; 63 import java.util.Vector ; 64 65 import org.enhydra.apache.xerces.framework.XMLErrorReporter; 66 import org.enhydra.apache.xerces.validators.common.Grammar; 67 import org.enhydra.apache.xerces.validators.common.GrammarResolver; 68 import org.enhydra.apache.xerces.validators.common.XMLAttributeDecl; 69 import org.enhydra.apache.xerces.validators.datatype.DatatypeValidator; 70 import org.enhydra.apache.xerces.validators.datatype.DatatypeValidatorFactoryImpl; 71 import org.enhydra.apache.xerces.validators.datatype.IDDatatypeValidator; 72 import org.enhydra.apache.xerces.validators.datatype.InvalidDatatypeValueException; 73 import org.w3c.dom.Attr ; 74 import org.w3c.dom.Element ; 75 import org.w3c.dom.NamedNodeMap ; 76 77 84 85 public class GeneralAttrCheck { 86 87 public static int ELE_CONTEXT_GLOBAL = 0; 89 public static int ELE_CONTEXT_LOCAL = 1; 90 91 public static int ATT_REQUIRED = 0; 94 public static int ATT_OPT_DFLT = 1; 95 public static int ATT_OPT_NODFLT = 2; 96 97 protected static String PRE_GLOBAL = "G_"; 99 protected static String PRE_LOC_NAME = "LN_"; 100 protected static String PRE_LOC_REF = "LR_"; 101 102 protected static Hashtable fEleAttrsMap = new Hashtable (); 104 105 protected static DatatypeValidator[] fExtraDVs = null; 107 108 protected static int dtCount = 0; 113 114 protected static final int DT_ANYURI = dtCount++; 115 protected static final int DT_BOOLEAN = dtCount++; 116 protected static final int DT_ID = dtCount++; 117 protected static final int DT_NONNEGINT = dtCount++; 118 protected static final int DT_QNAME = dtCount++; 119 protected static final int DT_STRING = dtCount++; 120 protected static final int DT_TOKEN = dtCount++; 121 protected static final int DT_NCNAME = dtCount++; 122 protected static final int DT_XPATH = dtCount++; 123 protected static final int DT_XPATH1 = dtCount++; 124 125 protected static final int DT_BLOCK = -1; 126 protected static final int DT_BLOCK1 = DT_BLOCK-1; 127 protected static final int DT_FINAL = DT_BLOCK1-1; 128 protected static final int DT_FINAL1 = DT_FINAL-1; 129 protected static final int DT_FORM = DT_FINAL1-1; 130 protected static final int DT_MAXOCCURS = DT_FORM-1; 131 protected static final int DT_MAXOCCURS1 = DT_MAXOCCURS-1; 132 protected static final int DT_MEMBERTYPES = DT_MAXOCCURS1-1; 133 protected static final int DT_MINOCCURS1 = DT_MEMBERTYPES-1; 134 protected static final int DT_NAMESPACE = DT_MINOCCURS1-1; 135 protected static final int DT_PROCESSCONTENTS = DT_NAMESPACE-1; 136 protected static final int DT_PUBLIC = DT_PROCESSCONTENTS-1; 137 protected static final int DT_USE = DT_PUBLIC-1; 138 protected static final int DT_WHITESPACE = DT_USE-1; 139 140 static { 141 fExtraDVs = new DatatypeValidator[dtCount]; 142 143 int attCount = 0; 145 int ATT_ABSTRACT_D = attCount++; 146 int ATT_ATTRIBUTE_FD_D = attCount++; 147 int ATT_BASE_R = attCount++; 148 int ATT_BASE_N = attCount++; 149 int ATT_BLOCK_N = attCount++; 150 int ATT_BLOCK1_N = attCount++; 151 int ATT_BLOCK_D_D = attCount++; 152 int ATT_DEFAULT_N = attCount++; 153 int ATT_ELEMENT_FD_D = attCount++; 154 int ATT_FINAL_N = attCount++; 155 int ATT_FINAL1_N = attCount++; 156 int ATT_FINAL_D_D = attCount++; 157 int ATT_FIXED_N = attCount++; 158 int ATT_FIXED_D = attCount++; 159 int ATT_FORM_N = attCount++; 160 int ATT_ID_N = attCount++; 161 int ATT_ITEMTYPE_N = attCount++; 162 int ATT_MAXOCCURS_D = attCount++; 163 int ATT_MAXOCCURS1_D = attCount++; 164 int ATT_MEMBER_T_N = attCount++; 165 int ATT_MINOCCURS_D = attCount++; 166 int ATT_MINOCCURS1_D = attCount++; 167 int ATT_MIXED_D = attCount++; 168 int ATT_MIXED_N = attCount++; 169 int ATT_NAME_R = attCount++; 170 int ATT_NAMESPACE_D = attCount++; 171 int ATT_NAMESPACE_N = attCount++; 172 int ATT_NILLABLE_D = attCount++; 173 int ATT_PROCESS_C_D = attCount++; 174 int ATT_PUBLIC_R = attCount++; 175 int ATT_REF_R = attCount++; 176 int ATT_REFER_R = attCount++; 177 int ATT_SCHEMA_L_R = attCount++; 178 int ATT_SCHEMA_L_N = attCount++; 179 int ATT_SOURCE_N = attCount++; 180 int ATT_SUBSTITUTION_G_N = attCount++; 181 int ATT_SYSTEM_N = attCount++; 182 int ATT_TARGET_N_N = attCount++; 183 int ATT_TYPE_N = attCount++; 184 int ATT_USE_D = attCount++; 185 int ATT_VALUE_NNI_N = attCount++; 186 int ATT_VALUE_STR_N = attCount++; 187 int ATT_VALUE_WS_N = attCount++; 188 int ATT_VERSION_N = attCount++; 189 int ATT_XPATH_R = attCount++; 190 int ATT_XPATH1_R = attCount++; 191 192 OneAttr[] allAttrs = new OneAttr[attCount]; 194 allAttrs[ATT_ABSTRACT_D] = new OneAttr(SchemaSymbols.ATT_ABSTRACT, 195 DT_BOOLEAN, 196 ATT_OPT_DFLT, 197 SchemaSymbols.ATTVAL_FALSE); 198 allAttrs[ATT_ATTRIBUTE_FD_D] = new OneAttr(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT, 199 DT_FORM, 200 ATT_OPT_DFLT, 201 SchemaSymbols.ATTVAL_UNQUALIFIED); 202 allAttrs[ATT_BASE_R] = new OneAttr(SchemaSymbols.ATT_BASE, 203 DT_QNAME, 204 ATT_REQUIRED, 205 null); 206 allAttrs[ATT_BASE_N] = new OneAttr(SchemaSymbols.ATT_BASE, 207 DT_QNAME, 208 ATT_OPT_NODFLT, 209 null); 210 allAttrs[ATT_BLOCK_N] = new OneAttr(SchemaSymbols.ATT_BLOCK, 211 DT_BLOCK, 212 ATT_OPT_NODFLT, 213 null); 214 allAttrs[ATT_BLOCK1_N] = new OneAttr(SchemaSymbols.ATT_BLOCK, 215 DT_BLOCK1, 216 ATT_OPT_NODFLT, 217 null); 218 allAttrs[ATT_BLOCK_D_D] = new OneAttr(SchemaSymbols.ATT_BLOCKDEFAULT, 219 DT_BLOCK, 220 ATT_OPT_DFLT, 221 ""); 222 allAttrs[ATT_DEFAULT_N] = new OneAttr(SchemaSymbols.ATT_DEFAULT, 223 DT_STRING, 224 ATT_OPT_NODFLT, 225 null); 226 allAttrs[ATT_ELEMENT_FD_D] = new OneAttr(SchemaSymbols.ATT_ELEMENTFORMDEFAULT, 227 DT_FORM, 228 ATT_OPT_DFLT, 229 SchemaSymbols.ATTVAL_UNQUALIFIED); 230 allAttrs[ATT_FINAL_N] = new OneAttr(SchemaSymbols.ATT_FINAL, 231 DT_FINAL, 232 ATT_OPT_NODFLT, 233 null); 234 allAttrs[ATT_FINAL1_N] = new OneAttr(SchemaSymbols.ATT_FINAL, 235 DT_FINAL1, 236 ATT_OPT_NODFLT, 237 null); 238 allAttrs[ATT_FINAL_D_D] = new OneAttr(SchemaSymbols.ATT_FINALDEFAULT, 239 DT_FINAL, 240 ATT_OPT_DFLT, 241 ""); 242 allAttrs[ATT_FIXED_N] = new OneAttr(SchemaSymbols.ATT_FIXED, 243 DT_STRING, 244 ATT_OPT_NODFLT, 245 null); 246 allAttrs[ATT_FIXED_D] = new OneAttr(SchemaSymbols.ATT_FIXED, 247 DT_BOOLEAN, 248 ATT_OPT_DFLT, 249 SchemaSymbols.ATTVAL_FALSE); 250 allAttrs[ATT_FORM_N] = new OneAttr(SchemaSymbols.ATT_FORM, 251 DT_FORM, 252 ATT_OPT_NODFLT, 253 null); 254 allAttrs[ATT_ID_N] = new OneAttr(SchemaSymbols.ATT_ID, 255 DT_ID, 256 ATT_OPT_NODFLT, 257 null); 258 allAttrs[ATT_ITEMTYPE_N] = new OneAttr(SchemaSymbols.ATT_ITEMTYPE, 259 DT_QNAME, 260 ATT_OPT_NODFLT, 261 null); 262 allAttrs[ATT_MAXOCCURS_D] = new OneAttr(SchemaSymbols.ATT_MAXOCCURS, 263 DT_MAXOCCURS, 264 ATT_OPT_DFLT, 265 "1"); 266 allAttrs[ATT_MAXOCCURS1_D] = new OneAttr(SchemaSymbols.ATT_MAXOCCURS, 267 DT_MAXOCCURS1, 268 ATT_OPT_DFLT, 269 "1"); 270 allAttrs[ATT_MEMBER_T_N] = new OneAttr(SchemaSymbols.ATT_MEMBERTYPES, 271 DT_MEMBERTYPES, 272 ATT_OPT_NODFLT, 273 null); 274 allAttrs[ATT_MINOCCURS_D] = new OneAttr(SchemaSymbols.ATT_MINOCCURS, 275 DT_NONNEGINT, 276 ATT_OPT_DFLT, 277 "1"); 278 allAttrs[ATT_MINOCCURS1_D] = new OneAttr(SchemaSymbols.ATT_MINOCCURS, 279 DT_MINOCCURS1, 280 ATT_OPT_DFLT, 281 "1"); 282 allAttrs[ATT_MIXED_D] = new OneAttr(SchemaSymbols.ATT_MIXED, 283 DT_BOOLEAN, 284 ATT_OPT_DFLT, 285 SchemaSymbols.ATTVAL_FALSE); 286 allAttrs[ATT_MIXED_N] = new OneAttr(SchemaSymbols.ATT_MIXED, 287 DT_BOOLEAN, 288 ATT_OPT_NODFLT, 289 null); 290 allAttrs[ATT_NAME_R] = new OneAttr(SchemaSymbols.ATT_NAME, 291 DT_NCNAME, 292 ATT_REQUIRED, 293 null); 294 allAttrs[ATT_NAMESPACE_D] = new OneAttr(SchemaSymbols.ATT_NAMESPACE, 295 DT_NAMESPACE, 296 ATT_OPT_DFLT, 297 SchemaSymbols.ATTVAL_TWOPOUNDANY); 298 allAttrs[ATT_NAMESPACE_N] = new OneAttr(SchemaSymbols.ATT_NAMESPACE, 299 DT_ANYURI, 300 ATT_OPT_NODFLT, 301 null); 302 allAttrs[ATT_NILLABLE_D] = new OneAttr(SchemaSymbols.ATT_NILLABLE, 303 DT_BOOLEAN, 304 ATT_OPT_DFLT, 305 SchemaSymbols.ATTVAL_FALSE); 306 allAttrs[ATT_PROCESS_C_D] = new OneAttr(SchemaSymbols.ATT_PROCESSCONTENTS, 307 DT_PROCESSCONTENTS, 308 ATT_OPT_DFLT, 309 SchemaSymbols.ATTVAL_STRICT); 310 allAttrs[ATT_PUBLIC_R] = new OneAttr(SchemaSymbols.ATT_PUBLIC, 311 DT_PUBLIC, 312 ATT_REQUIRED, 313 null); 314 allAttrs[ATT_REF_R] = new OneAttr(SchemaSymbols.ATT_REF, 315 DT_QNAME, 316 ATT_REQUIRED, 317 null); 318 allAttrs[ATT_REFER_R] = new OneAttr(SchemaSymbols.ATT_REFER, 319 DT_QNAME, 320 ATT_REQUIRED, 321 null); 322 allAttrs[ATT_SCHEMA_L_R] = new OneAttr(SchemaSymbols.ATT_SCHEMALOCATION, 323 DT_ANYURI, 324 ATT_REQUIRED, 325 null); 326 allAttrs[ATT_SCHEMA_L_N] = new OneAttr(SchemaSymbols.ATT_SCHEMALOCATION, 327 DT_ANYURI, 328 ATT_OPT_NODFLT, 329 null); 330 allAttrs[ATT_SOURCE_N] = new OneAttr(SchemaSymbols.ATT_SOURCE, 331 DT_ANYURI, 332 ATT_OPT_NODFLT, 333 null); 334 allAttrs[ATT_SUBSTITUTION_G_N] = new OneAttr(SchemaSymbols.ATT_SUBSTITUTIONGROUP, 335 DT_QNAME, 336 ATT_OPT_NODFLT, 337 null); 338 allAttrs[ATT_SYSTEM_N] = new OneAttr(SchemaSymbols.ATT_SYSTEM, 339 DT_ANYURI, 340 ATT_OPT_NODFLT, 341 null); 342 allAttrs[ATT_TARGET_N_N] = new OneAttr(SchemaSymbols.ATT_TARGETNAMESPACE, 343 DT_ANYURI, 344 ATT_OPT_NODFLT, 345 null); 346 allAttrs[ATT_TYPE_N] = new OneAttr(SchemaSymbols.ATT_TYPE, 347 DT_QNAME, 348 ATT_OPT_NODFLT, 349 null); 350 allAttrs[ATT_USE_D] = new OneAttr(SchemaSymbols.ATT_USE, 351 DT_USE, 352 ATT_OPT_DFLT, 353 SchemaSymbols.ATTVAL_OPTIONAL); 354 allAttrs[ATT_VALUE_NNI_N] = new OneAttr(SchemaSymbols.ATT_VALUE, 355 DT_NONNEGINT, 356 ATT_OPT_NODFLT, 357 null); 358 allAttrs[ATT_VALUE_STR_N] = new OneAttr(SchemaSymbols.ATT_VALUE, 359 DT_STRING, 360 ATT_OPT_NODFLT, 361 null); 362 allAttrs[ATT_VALUE_WS_N] = new OneAttr(SchemaSymbols.ATT_VALUE, 363 DT_WHITESPACE, 364 ATT_OPT_NODFLT, 365 null); 366 allAttrs[ATT_VERSION_N] = new OneAttr(SchemaSymbols.ATT_VERSION, 367 DT_TOKEN, 368 ATT_OPT_NODFLT, 369 null); 370 allAttrs[ATT_XPATH_R] = new OneAttr(SchemaSymbols.ATT_XPATH, 371 DT_XPATH, 372 ATT_REQUIRED, 373 null); 374 allAttrs[ATT_XPATH1_R] = new OneAttr(SchemaSymbols.ATT_XPATH, 375 DT_XPATH1, 376 ATT_REQUIRED, 377 null); 378 379 Hashtable attrList; 381 Object [] attrArray; 382 OneElement oneEle; 383 384 attrList = new Hashtable (); 386 attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); 388 attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); 390 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 392 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 394 attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]); 396 oneEle = new OneElement (attrList); 397 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_ATTRIBUTE, oneEle); 398 399 attrList = new Hashtable (); 401 attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); 403 attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); 405 attrList.put(SchemaSymbols.ATT_FORM, allAttrs[ATT_FORM_N]); 407 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 409 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 411 attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]); 413 attrList.put(SchemaSymbols.ATT_USE, allAttrs[ATT_USE_D]); 415 oneEle = new OneElement (attrList); 416 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_ATTRIBUTE, oneEle); 417 418 attrList = new Hashtable (); 420 attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); 422 attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); 424 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 426 attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]); 428 attrList.put(SchemaSymbols.ATT_USE, allAttrs[ATT_USE_D]); 430 oneEle = new OneElement (attrList); 431 fEleAttrsMap.put(PRE_LOC_REF+SchemaSymbols.ELT_ATTRIBUTE, oneEle); 432 433 attrList = new Hashtable (); 435 attrList.put(SchemaSymbols.ATT_ABSTRACT, allAttrs[ATT_ABSTRACT_D]); 437 attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK_N]); 439 attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); 441 attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL_N]); 443 attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); 445 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 447 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 449 attrList.put(SchemaSymbols.ATT_NILLABLE, allAttrs[ATT_NILLABLE_D]); 451 attrList.put(SchemaSymbols.ATT_SUBSTITUTIONGROUP, allAttrs[ATT_SUBSTITUTION_G_N]); 453 attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]); 455 oneEle = new OneElement (attrList); 456 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_ELEMENT, oneEle); 457 458 attrList = new Hashtable (); 460 attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK_N]); 462 attrList.put(SchemaSymbols.ATT_DEFAULT, allAttrs[ATT_DEFAULT_N]); 464 attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_N]); 466 attrList.put(SchemaSymbols.ATT_FORM, allAttrs[ATT_FORM_N]); 468 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 470 attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); 472 attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); 474 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 476 attrList.put(SchemaSymbols.ATT_NILLABLE, allAttrs[ATT_NILLABLE_D]); 478 attrList.put(SchemaSymbols.ATT_TYPE, allAttrs[ATT_TYPE_N]); 480 oneEle = new OneElement (attrList); 481 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_ELEMENT, oneEle); 482 483 attrList = new Hashtable (); 485 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 487 attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); 489 attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); 491 attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]); 493 oneEle = new OneElement (attrList); 494 fEleAttrsMap.put(PRE_LOC_REF+SchemaSymbols.ELT_ELEMENT, oneEle); 495 496 attrList = new Hashtable (); 498 attrList.put(SchemaSymbols.ATT_ABSTRACT, allAttrs[ATT_ABSTRACT_D]); 500 attrList.put(SchemaSymbols.ATT_BLOCK, allAttrs[ATT_BLOCK1_N]); 502 attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL_N]); 504 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 506 attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_D]); 508 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 510 oneEle = new OneElement (attrList); 511 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_COMPLEXTYPE, oneEle); 512 513 attrList = new Hashtable (); 515 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 517 attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_D]); 519 oneEle = new OneElement (attrList); 520 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_COMPLEXTYPE, oneEle); 521 522 attrList = new Hashtable (); 524 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 526 oneEle = new OneElement (attrList); 527 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_SIMPLECONTENT, oneEle); 528 529 attrList = new Hashtable (); 531 attrList.put(SchemaSymbols.ATT_BASE, allAttrs[ATT_BASE_N]); 533 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 535 oneEle = new OneElement (attrList); 536 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_RESTRICTION, oneEle); 537 538 attrList = new Hashtable (); 540 attrList.put(SchemaSymbols.ATT_BASE, allAttrs[ATT_BASE_R]); 542 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 544 oneEle = new OneElement (attrList); 545 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_EXTENSION, oneEle); 546 547 attrList = new Hashtable (); 549 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 551 attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]); 553 oneEle = new OneElement (attrList); 554 fEleAttrsMap.put(PRE_LOC_REF+SchemaSymbols.ELT_ATTRIBUTEGROUP, oneEle); 555 556 attrList = new Hashtable (); 558 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 560 attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_D]); 562 attrList.put(SchemaSymbols.ATT_PROCESSCONTENTS, allAttrs[ATT_PROCESS_C_D]); 564 oneEle = new OneElement (attrList); 565 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_ANYATTRIBUTE, oneEle); 566 567 attrList = new Hashtable (); 569 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 571 attrList.put(SchemaSymbols.ATT_MIXED, allAttrs[ATT_MIXED_N]); 573 oneEle = new OneElement (attrList); 574 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_COMPLEXCONTENT, oneEle); 575 576 attrList = new Hashtable (); 578 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 580 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 582 oneEle = new OneElement (attrList); 583 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_ATTRIBUTEGROUP, oneEle); 584 585 attrList = new Hashtable (); 587 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 589 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 591 oneEle = new OneElement (attrList); 592 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_GROUP, oneEle); 593 594 attrList = new Hashtable (); 596 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 598 attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); 600 attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); 602 attrList.put(SchemaSymbols.ATT_REF, allAttrs[ATT_REF_R]); 604 oneEle = new OneElement (attrList); 605 fEleAttrsMap.put(PRE_LOC_REF+SchemaSymbols.ELT_GROUP, oneEle); 606 607 attrList = new Hashtable (); 609 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 611 attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS1_D]); 613 attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS1_D]); 615 oneEle = new OneElement (attrList); 616 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_ALL, oneEle); 617 618 attrList = new Hashtable (); 620 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 622 attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); 624 attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); 626 oneEle = new OneElement (attrList); 627 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_CHOICE, oneEle); 628 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_SEQUENCE, oneEle); 630 631 attrList = new Hashtable (); 633 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 635 attrList.put(SchemaSymbols.ATT_MAXOCCURS, allAttrs[ATT_MAXOCCURS_D]); 637 attrList.put(SchemaSymbols.ATT_MINOCCURS, allAttrs[ATT_MINOCCURS_D]); 639 attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_D]); 641 attrList.put(SchemaSymbols.ATT_PROCESSCONTENTS, allAttrs[ATT_PROCESS_C_D]); 643 oneEle = new OneElement (attrList); 644 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_ANY, oneEle); 645 646 attrList = new Hashtable (); 648 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 650 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 652 oneEle = new OneElement (attrList); 653 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_UNIQUE, oneEle); 654 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_KEY, oneEle); 656 657 attrList = new Hashtable (); 659 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 661 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 663 attrList.put(SchemaSymbols.ATT_REFER, allAttrs[ATT_REFER_R]); 665 oneEle = new OneElement (attrList); 666 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_KEYREF, oneEle); 667 668 attrList = new Hashtable (); 670 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 672 attrList.put(SchemaSymbols.ATT_XPATH, allAttrs[ATT_XPATH_R]); 674 oneEle = new OneElement (attrList); 675 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_SELECTOR, oneEle); 676 677 attrList = new Hashtable (); 679 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 681 attrList.put(SchemaSymbols.ATT_XPATH, allAttrs[ATT_XPATH1_R]); 683 oneEle = new OneElement (attrList); 684 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_FIELD, oneEle); 685 686 attrList = new Hashtable (); 688 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 690 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 692 attrList.put(SchemaSymbols.ATT_PUBLIC, allAttrs[ATT_PUBLIC_R]); 694 attrList.put(SchemaSymbols.ATT_SYSTEM, allAttrs[ATT_SYSTEM_N]); 696 oneEle = new OneElement (attrList); 697 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_NOTATION, oneEle); 698 699 attrList = new Hashtable (); 701 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 703 oneEle = new OneElement (attrList); 704 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_ANNOTATION, oneEle); 705 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_ANNOTATION, oneEle); 707 708 attrList = new Hashtable (); 710 attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]); 712 oneEle = new OneElement (attrList, false); 713 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_APPINFO, oneEle); 714 715 attrList = new Hashtable (); 717 attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]); 719 oneEle = new OneElement (attrList, false); 721 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_DOCUMENTATION, oneEle); 722 723 attrList = new Hashtable (); 725 attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL1_N]); 727 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 729 attrList.put(SchemaSymbols.ATT_NAME, allAttrs[ATT_NAME_R]); 731 oneEle = new OneElement (attrList); 732 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_SIMPLETYPE, oneEle); 733 734 attrList = new Hashtable (); 736 attrList.put(SchemaSymbols.ATT_FINAL, allAttrs[ATT_FINAL1_N]); 738 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 740 oneEle = new OneElement (attrList); 741 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_SIMPLETYPE, oneEle); 742 743 746 attrList = new Hashtable (); 748 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 750 attrList.put(SchemaSymbols.ATT_ITEMTYPE, allAttrs[ATT_ITEMTYPE_N]); 752 oneEle = new OneElement (attrList); 753 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_LIST, oneEle); 754 755 attrList = new Hashtable (); 757 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 759 attrList.put(SchemaSymbols.ATT_MEMBERTYPES, allAttrs[ATT_MEMBER_T_N]); 761 oneEle = new OneElement (attrList); 762 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_UNION, oneEle); 763 764 attrList = new Hashtable (); 766 attrList.put(SchemaSymbols.ATT_ATTRIBUTEFORMDEFAULT, allAttrs[ATT_ATTRIBUTE_FD_D]); 768 attrList.put(SchemaSymbols.ATT_BLOCKDEFAULT, allAttrs[ATT_BLOCK_D_D]); 770 attrList.put(SchemaSymbols.ATT_ELEMENTFORMDEFAULT, allAttrs[ATT_ELEMENT_FD_D]); 772 attrList.put(SchemaSymbols.ATT_FINALDEFAULT, allAttrs[ATT_FINAL_D_D]); 774 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 776 attrList.put(SchemaSymbols.ATT_TARGETNAMESPACE, allAttrs[ATT_TARGET_N_N]); 778 attrList.put(SchemaSymbols.ATT_VERSION, allAttrs[ATT_VERSION_N]); 780 oneEle = new OneElement (attrList); 782 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_SCHEMA, oneEle); 783 784 attrList = new Hashtable (); 786 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 788 attrList.put(SchemaSymbols.ATT_SCHEMALOCATION, allAttrs[ATT_SCHEMA_L_R]); 790 oneEle = new OneElement (attrList); 791 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_INCLUDE, oneEle); 792 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_REDEFINE, oneEle); 794 795 attrList = new Hashtable (); 797 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 799 attrList.put(SchemaSymbols.ATT_NAMESPACE, allAttrs[ATT_NAMESPACE_N]); 801 attrList.put(SchemaSymbols.ATT_SCHEMALOCATION, allAttrs[ATT_SCHEMA_L_N]); 803 oneEle = new OneElement (attrList); 804 fEleAttrsMap.put(PRE_GLOBAL+SchemaSymbols.ELT_IMPORT, oneEle); 805 806 attrList = new Hashtable (); 808 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 810 attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_NNI_N]); 812 attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]); 814 oneEle = new OneElement (attrList); 815 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_LENGTH, oneEle); 816 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_MINLENGTH, oneEle); 818 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_MAXLENGTH, oneEle); 820 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_TOTALDIGITS, oneEle); 822 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_FRACTIONDIGITS, oneEle); 824 825 attrList = new Hashtable (); 827 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 829 attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]); 831 oneEle = new OneElement (attrList); 832 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_PATTERN, oneEle); 833 834 attrList = new Hashtable (); 836 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 838 attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]); 840 oneEle = new OneElement (attrList); 841 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_ENUMERATION, oneEle); 842 843 attrList = new Hashtable (); 845 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 847 attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_WS_N]); 849 attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]); 851 oneEle = new OneElement (attrList); 852 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_WHITESPACE, oneEle); 853 854 attrList = new Hashtable (); 856 attrList.put(SchemaSymbols.ATT_ID, allAttrs[ATT_ID_N]); 858 attrList.put(SchemaSymbols.ATT_VALUE, allAttrs[ATT_VALUE_STR_N]); 860 attrList.put(SchemaSymbols.ATT_FIXED, allAttrs[ATT_FIXED_D]); 862 oneEle = new OneElement (attrList); 863 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_MAXINCLUSIVE, oneEle); 864 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_MAXEXCLUSIVE, oneEle); 866 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_MININCLUSIVE, oneEle); 868 fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_MINEXCLUSIVE, oneEle); 870 } 871 872 private Hashtable fIdDefs = new Hashtable (); 873 874 protected XMLErrorReporter fErrorReporter = null; 876 877 protected Hashtable fProcessedElements = new Hashtable (); 879 880 protected Hashtable fNonSchemaAttrs = new Hashtable (); 882 883 private GeneralAttrCheck() {} 885 public GeneralAttrCheck (XMLErrorReporter er, DatatypeValidatorFactoryImpl datatypeRegistry) { 886 fErrorReporter = er; 887 synchronized (getClass()) { 888 if (fExtraDVs[DT_ANYURI] == null) { 889 datatypeRegistry.expandRegistryToFullSchemaSet(); 891 fExtraDVs[DT_ANYURI] = datatypeRegistry.getDatatypeValidator("anyURI"); 893 fExtraDVs[DT_BOOLEAN] = datatypeRegistry.getDatatypeValidator("boolean"); 895 fExtraDVs[DT_ID] = datatypeRegistry.getDatatypeValidator("ID"); 897 fExtraDVs[DT_NONNEGINT] = datatypeRegistry.getDatatypeValidator("nonNegativeInteger"); 899 fExtraDVs[DT_QNAME] = datatypeRegistry.getDatatypeValidator("QName"); 901 fExtraDVs[DT_STRING] = datatypeRegistry.getDatatypeValidator("string"); 903 fExtraDVs[DT_TOKEN] = datatypeRegistry.getDatatypeValidator("token"); 905 fExtraDVs[DT_NCNAME] = datatypeRegistry.getDatatypeValidator("NCName"); 907 fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING]; 909 fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING]; 911 } 912 } 913 } 914 915 public Hashtable checkAttributes(Element element, int eleContext) throws Exception { 920 if (element == null) 921 return null; 922 923 Hashtable attrValues = (Hashtable )fProcessedElements.get(element); 924 if (attrValues != null) 925 return attrValues; 926 927 String elName = element.getLocalName(), name; 932 if (eleContext == ELE_CONTEXT_GLOBAL) { 933 name = PRE_GLOBAL + elName; 934 } else { 935 if (element.getAttributeNode(SchemaSymbols.ATT_REF) == null) 936 name = PRE_LOC_NAME + elName; 937 else 938 name = PRE_LOC_REF + elName; 939 } 940 941 OneElement oneEle = (OneElement)fEleAttrsMap.get(name); 943 if (oneEle == null) { 944 reportSchemaError (SchemaMessageProvider.Con3X3ElementAppearance, 945 new Object [] {elName}); 946 return null; 947 } 948 949 attrValues = new Hashtable (); 950 Hashtable attrList = oneEle.attrList; 951 952 NamedNodeMap attrs = element.getAttributes(); 954 Attr sattr = null; 955 int i = 0; 956 while ((sattr = (Attr )attrs.item(i++)) != null) { 957 String attrName = sattr.getName(); 959 String attrVal = sattr.getValue(); 960 961 if (attrName.toLowerCase().startsWith("xml")) { 964 attrValues.put(attrName, new Object [] {sattr.getValue(), Boolean.FALSE}); 965 continue; 966 } 967 968 String attrURI = sattr.getNamespaceURI(); 970 if (attrURI != null && attrURI.length() != 0) { 971 if (attrURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) || 974 !oneEle.allowNonSchemaAttr) { 975 reportSchemaError (SchemaMessageProvider.Con3X3AttributeAppearance, 976 new Object [] {elName, attrName}); 977 } else { 978 attrValues.put(attrName, 982 new Object [] {attrVal, Boolean.FALSE}); 983 String attrRName = attrURI + "," + sattr.getLocalName(); 984 Vector values = (Vector )fNonSchemaAttrs.get(attrRName); 985 if (values == null) { 986 values = new Vector (); 987 values.addElement(attrName); 988 values.addElement(elName); 989 values.addElement(attrVal); 990 fNonSchemaAttrs.put(attrRName, values); 991 } else { 992 values.addElement(elName); 993 values.addElement(attrVal); 994 } 995 } 996 continue; 997 } 998 999 OneAttr oneAttr = (OneAttr)attrList.get(attrName); 1001 if (oneAttr == null) { 1002 reportSchemaError (SchemaMessageProvider.Con3X3AttributeAppearance, 1003 new Object [] {elName, attrName}); 1004 continue; 1005 } 1006 1007 try { 1009 if (oneAttr.dvIndex >= 0) { 1013 if (oneAttr.dvIndex != DT_STRING && 1014 oneAttr.dvIndex != DT_XPATH && 1015 oneAttr.dvIndex != DT_XPATH1) { 1016 DatatypeValidator dv = fExtraDVs[oneAttr.dvIndex]; 1017 if (dv instanceof IDDatatypeValidator) { 1018 dv.validate( attrVal, fIdDefs ); 1019 } else { 1020 dv.validate( attrVal, null); 1021 } 1022 } 1023 attrValues.put(attrName, new Object [] {attrVal, Boolean.FALSE}); 1024 } else { 1025 attrVal = validate(attrName, attrVal, oneAttr.dvIndex); 1026 attrValues.put(attrName, new Object [] {attrVal, Boolean.FALSE}); 1027 } 1028 } catch(InvalidDatatypeValueException ide) { 1029 reportSchemaError (SchemaMessageProvider.Con3X3AttributeInvalidValue, 1030 new Object [] {elName, attrName, ide.getLocalizedMessage()}); 1031 } 1032 } 1033 1034 Object [] reqAttrs = oneEle.attrArray; 1036 for (i = 0; i < reqAttrs.length; i++) { 1037 OneAttr oneAttr = (OneAttr)reqAttrs[i]; 1038 1039 if (element.getAttributeNode(oneAttr.name) != null) 1041 continue; 1042 1043 if (oneAttr.optdflt == ATT_REQUIRED) { 1045 reportSchemaError (SchemaMessageProvider.Con3X3AttributeMustAppear, 1046 new Object [] {elName, oneAttr.name}); 1047 } 1048 else if (oneAttr.optdflt == ATT_OPT_DFLT) { 1050 attrValues.put(oneAttr.name, new Object [] {oneAttr.dfltValue, Boolean.TRUE}); 1051 } 1052 } 1053 1054 fProcessedElements.put(element, attrValues); 1055 1056 return attrValues; 1057 } 1058 1059 private String validate(String attr, String value, int dvIndex) throws InvalidDatatypeValueException { 1060 Vector unionBase, enumer; 1061 int choice; 1062 1063 if (value == null) 1064 return null; 1065 1066 switch (dvIndex) { 1067 case DT_BLOCK: 1068 choice = 0; 1070 if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) { 1071 choice = SchemaSymbols.SUBSTITUTION|SchemaSymbols.EXTENSION| 1072 SchemaSymbols.RESTRICTION|SchemaSymbols.LIST| 1073 SchemaSymbols.UNION; 1074 } else { 1075 StringTokenizer t = new StringTokenizer (value, " "); 1076 while (t.hasMoreTokens()) { 1077 String token = t.nextToken (); 1078 1079 if (token.equals (SchemaSymbols.ATTVAL_SUBSTITUTION) ) { 1080 choice |= SchemaSymbols.SUBSTITUTION; 1081 } else if (token.equals (SchemaSymbols.ATTVAL_EXTENSION)) { 1082 choice |= SchemaSymbols.EXTENSION; 1083 } else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) { 1084 choice |= SchemaSymbols.RESTRICTION; 1085 } else if ( token.equals (SchemaSymbols.ELT_LIST) ) { 1086 choice |= SchemaSymbols.LIST; 1087 } else if ( token.equals (SchemaSymbols.ELT_UNION) ) { 1088 choice |= SchemaSymbols.RESTRICTION; 1089 } else { 1090 throw new InvalidDatatypeValueException("the value '"+value+"' must match (#all | List of (substitution | extension | restriction | list | union))"); 1091 } 1092 } 1093 } 1094 break; 1096 case DT_BLOCK1: 1097 case DT_FINAL: 1098 choice = 0; 1101 if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) { 1102 choice = SchemaSymbols.EXTENSION|SchemaSymbols.RESTRICTION; 1103 } else { 1104 StringTokenizer t = new StringTokenizer (value, " "); 1105 while (t.hasMoreTokens()) { 1106 String token = t.nextToken (); 1107 1108 if (token.equals (SchemaSymbols.ATTVAL_EXTENSION)) { 1109 choice |= SchemaSymbols.EXTENSION; 1110 } else if (token.equals (SchemaSymbols.ATTVAL_RESTRICTION)) { 1111 choice |= SchemaSymbols.RESTRICTION; 1112 } else { 1113 throw new InvalidDatatypeValueException("the value '"+value+"' must match (#all | List of (extension | restriction))"); 1114 } 1115 } 1116 } 1117 break; 1119 case DT_FINAL1: 1120 choice = 0; 1122 if (value.equals (SchemaSymbols.ATTVAL_POUNDALL)) { 1123 choice = SchemaSymbols.RESTRICTION|SchemaSymbols.LIST| 1124 SchemaSymbols.UNION; 1125 } else if (value.equals (SchemaSymbols.ELT_LIST)) { 1126 choice = SchemaSymbols.LIST; 1127 } else if (value.equals (SchemaSymbols.ELT_UNION)) { 1128 choice = SchemaSymbols.UNION; 1129 } else if (value.equals (SchemaSymbols.ATTVAL_RESTRICTION)) { 1130 choice = SchemaSymbols.RESTRICTION; 1131 } else { 1132 throw new InvalidDatatypeValueException("the value '"+value+"' must match (#all | (list | union | restriction))"); 1133 } 1134 break; 1136 case DT_FORM: 1137 if (!value.equals (SchemaSymbols.ATTVAL_QUALIFIED) && 1139 !value.equals (SchemaSymbols.ATTVAL_UNQUALIFIED)) { 1140 throw new InvalidDatatypeValueException("the value '"+value+"' must match (qualified | unqualified)"); 1141 } 1142 break; 1143 case DT_MAXOCCURS: 1144 if (!value.equals("unbounded")) { 1146 try { 1147 fExtraDVs[DT_NONNEGINT].validate(value, null); 1148 } catch (InvalidDatatypeValueException ide) { 1149 throw new InvalidDatatypeValueException("the value '"+value+"' must match (nonNegativeInteger | unbounded)"); 1150 } 1151 } 1152 break; 1153 case DT_MAXOCCURS1: 1154 if (!value.equals("1")) 1156 throw new InvalidDatatypeValueException("the value '"+value+"' must be '1'"); 1157 break; 1158 case DT_MEMBERTYPES: 1159 try { 1161 StringTokenizer t = new StringTokenizer (value, " "); 1162 while (t.hasMoreTokens()) { 1163 String token = t.nextToken (); 1164 fExtraDVs[DT_QNAME].validate(token, null); 1165 } 1166 } catch (InvalidDatatypeValueException ide) { 1167 throw new InvalidDatatypeValueException("the value '"+value+"' must match (List of QName)"); 1168 } 1169 break; 1170 case DT_MINOCCURS1: 1171 if (!value.equals("0") && !value.equals("1")) 1173 throw new InvalidDatatypeValueException("the value '"+value+"' must be '0' or '1'"); 1174 break; 1175 case DT_NAMESPACE: 1176 if (!value.equals(SchemaSymbols.ATTVAL_TWOPOUNDANY) && 1178 !value.equals(SchemaSymbols.ATTVAL_TWOPOUNDOTHER)) { 1179 StringTokenizer t = new StringTokenizer (value, " "); 1180 try { 1181 while (t.hasMoreTokens()) { 1182 String token = t.nextToken (); 1183 if (!token.equals(SchemaSymbols.ATTVAL_TWOPOUNDTARGETNS) && 1184 !token.equals(SchemaSymbols.ATTVAL_TWOPOUNDLOCAL)) { 1185 fExtraDVs[DT_ANYURI].validate(token, null); 1186 } 1187 } 1188 } catch (InvalidDatatypeValueException ide) { 1189 throw new InvalidDatatypeValueException("the value '"+value+"' must match ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )"); 1190 } 1191 } 1192 break; 1193 case DT_PROCESSCONTENTS: 1194 if (!value.equals (SchemaSymbols.ATTVAL_SKIP) && 1196 !value.equals (SchemaSymbols.ATTVAL_LAX) && 1197 !value.equals (SchemaSymbols.ATTVAL_STRICT)) { 1198 throw new InvalidDatatypeValueException("the value '"+value+"' must match (lax | skip | strict)"); 1199 } 1200 break; 1201 case DT_PUBLIC: 1202 fExtraDVs[DT_TOKEN].validate(value, null); 1204 break; 1205 case DT_USE: 1206 if (!value.equals (SchemaSymbols.ATTVAL_OPTIONAL) && 1208 !value.equals (SchemaSymbols.ATTVAL_PROHIBITED) && 1209 !value.equals (SchemaSymbols.ATTVAL_REQUIRED)) { 1210 throw new InvalidDatatypeValueException("the value '"+value+"' must match (optional | prohibited | required)"); 1211 } 1212 break; 1213 case DT_WHITESPACE: 1214 if (!value.equals (SchemaSymbols.ATT_PRESERVE) && 1216 !value.equals (SchemaSymbols.ATT_REPLACE) && 1217 !value.equals (SchemaSymbols.ATT_COLLAPSE)) { 1218 throw new InvalidDatatypeValueException("the value '"+value+"' must match (preserve | replace | collapse)"); 1219 } 1220 break; 1221 } 1222 1223 return value; 1224 } 1225 1226 private void reportSchemaError(int major, Object args[]) throws Exception { 1228 if (fErrorReporter == null) { 1229 System.out.println("__TraverseSchemaError__ : " + SchemaMessageProvider.fgMessageKeys[major]); 1230 for (int i=0; i< args.length ; i++) { 1231 System.out.println((String )args[i]); 1232 } 1233 } 1234 else { 1235 fErrorReporter.reportError(fErrorReporter.getLocator(), 1236 SchemaMessageProvider.SCHEMA_DOMAIN, 1237 major, 1238 SchemaMessageProvider.MSG_NONE, 1239 args, 1240 XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR); 1241 } 1242 } 1243 1244 public void checkNonSchemaAttributes(GrammarResolver grammarResolver) throws Exception { 1246 Enumeration enumer = fNonSchemaAttrs.keys(); 1248 while (enumer.hasMoreElements()) { 1249 String attrRName = (String )enumer.nextElement(); 1251 String attrURI = attrRName.substring(0,attrRName.indexOf(',')); 1252 String attrLocal = attrRName.substring(attrRName.indexOf(',')+1); 1253 Grammar grammar = grammarResolver.getGrammar(attrURI); 1255 if (grammar == null || !(grammar instanceof SchemaGrammar)) 1256 continue; 1257 SchemaGrammar sGrammar = (SchemaGrammar)grammar; 1258 Hashtable attrRegistry = sGrammar.getAttributeDeclRegistry(); 1260 if (attrRegistry == null) 1261 continue; 1262 XMLAttributeDecl tempAttrDecl = (XMLAttributeDecl)attrRegistry.get(attrLocal); 1264 if (tempAttrDecl == null) 1265 continue; 1266 DatatypeValidator dv = tempAttrDecl.datatypeValidator; 1267 if (dv == null) 1268 continue; 1269 1270 Vector values = (Vector )fNonSchemaAttrs.get(attrRName); 1272 String elName, attrVal; 1273 String attrName = (String )values.elementAt(0); 1274 int count = values.size(); 1276 for (int i = 1; i < count; i += 2) { 1277 elName = (String )values.elementAt(i); 1279 attrVal = normalize((String )values.elementAt(i+1), dv.getWSFacet()); 1280 try { 1281 dv.validate(attrVal,null); 1283 } catch(InvalidDatatypeValueException ide) { 1284 reportSchemaError (SchemaMessageProvider.Con3X3AttributeInvalidValue, 1285 new Object [] {elName, attrName, ide.getLocalizedMessage()}); 1286 } 1287 } 1288 } 1289 } 1290 1291 private String normalize(String content, short ws) { 1293 int len = content == null ? 0 : content.length(); 1294 if (len == 0 || ws == DatatypeValidator.PRESERVE) 1295 return content; 1296 1297 StringBuffer sb = new StringBuffer (); 1298 if (ws == DatatypeValidator.REPLACE) { 1299 char ch; 1300 for (int i = 0; i < len; i++) { 1302 ch = content.charAt(i); 1303 if (ch != 0x9 && ch != 0xa && ch != 0xd) 1304 sb.append(ch); 1305 else 1306 sb.append((char)0x20); 1307 } 1308 } else { 1309 char ch; 1310 int i; 1311 boolean isLeading = true; 1312 for (i = 0; i < len; i++) { 1314 ch = content.charAt(i); 1315 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) { 1317 sb.append(ch); 1318 isLeading = false; 1319 } else { 1320 for (; i < len-1; i++) { 1322 ch = content.charAt(i+1); 1323 if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) 1324 break; 1325 } 1326 if (i < len - 1 && !isLeading) 1328 sb.append((char)0x20); 1329 } 1330 } 1331 } 1332 1333 return sb.toString(); 1334 } 1335} 1336 1337class OneAttr { 1338 public String name; 1340 public int dvIndex; 1342 public int optdflt; 1344 public String dfltValue; 1346 1347 public OneAttr(String name, int dvIndex, int optdflt, String dfltValue) { 1348 this.name = name; 1349 this.dvIndex = dvIndex; 1350 this.optdflt = optdflt; 1351 this.dfltValue = dfltValue; 1352 } 1353} 1354 1355class OneElement { 1356 public Hashtable attrList; 1358 public Object [] attrArray; 1360 public boolean allowNonSchemaAttr; 1362 1363 public OneElement (Hashtable attrList) { 1364 this(attrList, true); 1365 } 1366 1367 public OneElement (Hashtable attrList, boolean allowNonSchemaAttr) { 1368 this.attrList = attrList; 1369 1370 int count = attrList.size(); 1371 this.attrArray = new Object [count]; 1372 Enumeration enumer = attrList.elements(); 1373 for (int i = 0; i < count; i++) 1374 this.attrArray[i] = enumer.nextElement(); 1375 1376 this.allowNonSchemaAttr = allowNonSchemaAttr; 1377 } 1378} 1379 | Popular Tags |