1 16 17 package org.apache.xerces.dom; 18 19 20 import java.io.IOException ; 21 import java.io.StringReader ; 22 import java.util.Vector ; 23 24 import org.apache.xerces.impl.Constants; 25 import org.apache.xerces.impl.RevalidationHandler; 26 import org.apache.xerces.impl.dtd.DTDGrammar; 27 import org.apache.xerces.impl.dtd.XMLDTDDescription; 28 import org.apache.xerces.impl.dtd.XMLDTDValidator; 29 import org.apache.xerces.impl.dv.XSSimpleType; 30 import org.apache.xerces.impl.xs.util.SimpleLocator; 31 import org.apache.xerces.parsers.XMLGrammarPreparser; 32 import org.apache.xerces.util.AugmentationsImpl; 33 import org.apache.xerces.util.NamespaceSupport; 34 import org.apache.xerces.util.SymbolTable; 35 import org.apache.xerces.util.XML11Char; 36 import org.apache.xerces.util.XMLChar; 37 import org.apache.xerces.util.XMLGrammarPoolImpl; 38 import org.apache.xerces.util.XMLSymbols; 39 import org.apache.xerces.xni.Augmentations; 40 import org.apache.xerces.xni.NamespaceContext; 41 import org.apache.xerces.xni.QName; 42 import org.apache.xerces.xni.XMLAttributes; 43 import org.apache.xerces.xni.XMLDocumentHandler; 44 import org.apache.xerces.xni.XMLLocator; 45 import org.apache.xerces.xni.XMLResourceIdentifier; 46 import org.apache.xerces.xni.XMLString; 47 import org.apache.xerces.xni.XNIException; 48 import org.apache.xerces.xni.grammars.XMLGrammarDescription; 49 import org.apache.xerces.xni.grammars.XMLGrammarPool; 50 import org.apache.xerces.xni.parser.XMLComponent; 51 import org.apache.xerces.xni.parser.XMLDocumentSource; 52 import org.apache.xerces.xni.parser.XMLInputSource; 53 import org.apache.xerces.xs.AttributePSVI; 54 import org.apache.xerces.xs.ElementPSVI; 55 import org.apache.xerces.xs.XSTypeDefinition; 56 import org.w3c.dom.Attr ; 57 import org.w3c.dom.Comment ; 58 import org.w3c.dom.DOMError ; 59 import org.w3c.dom.DOMErrorHandler ; 60 import org.w3c.dom.Document ; 61 import org.w3c.dom.DocumentType ; 62 import org.w3c.dom.Element ; 63 import org.w3c.dom.Entity ; 64 import org.w3c.dom.NamedNodeMap ; 65 import org.w3c.dom.Node ; 66 import org.w3c.dom.NodeList ; 67 import org.w3c.dom.ProcessingInstruction ; 68 import org.w3c.dom.Text ; 69 94 public class DOMNormalizer implements XMLDocumentHandler { 95 96 100 protected final static boolean DEBUG_ND = false; 101 102 protected final static boolean DEBUG = false; 103 104 protected final static boolean DEBUG_EVENTS = false; 105 106 107 protected final static String PREFIX = "NS"; 108 109 protected DOMConfigurationImpl fConfiguration = null; 113 protected CoreDocumentImpl fDocument = null; 114 protected final XMLAttributesProxy fAttrProxy = new XMLAttributesProxy(); 115 protected final QName fQName = new QName(); 116 117 118 protected RevalidationHandler fValidationHandler; 119 120 121 protected SymbolTable fSymbolTable; 122 123 protected DOMErrorHandler fErrorHandler; 124 125 129 private final DOMErrorImpl fError = new DOMErrorImpl(); 130 131 protected boolean fNamespaceValidation = false; 133 134 protected boolean fPSVI = false; 136 137 138 protected final NamespaceContext fNamespaceContext = new NamespaceSupport(); 139 140 141 protected final NamespaceContext fLocalNSBinder = new NamespaceSupport(); 142 143 144 protected final Vector fAttributeList = new Vector (5,10); 145 146 147 148 protected final DOMLocatorImpl fLocator = new DOMLocatorImpl(); 149 150 151 protected Node fCurrentNode = null; 152 private QName fAttrQName = new QName(); 153 154 final XMLString fNormalizedValue = new XMLString(new char[16], 0, 0); 156 157 160 public static final RuntimeException abort = new RuntimeException (); 161 162 private XMLDTDValidator fDTDValidator; 164 165 private boolean allWhitespace = false; 167 168 171 public DOMNormalizer(){} 172 173 174 175 179 protected void normalizeDocument(CoreDocumentImpl document, DOMConfigurationImpl config) { 180 181 fDocument = document; 182 fConfiguration = config; 183 184 fSymbolTable = (SymbolTable) fConfiguration.getProperty(DOMConfigurationImpl.SYMBOL_TABLE); 187 fNamespaceContext.reset(); 189 fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); 190 191 if ((fConfiguration.features & DOMConfigurationImpl.VALIDATE) != 0) { 192 String schemaLang = (String )fConfiguration.getProperty(DOMConfigurationImpl.JAXP_SCHEMA_LANGUAGE); 193 194 if(schemaLang != null && schemaLang.equals(Constants.NS_XMLSCHEMA)) { 195 fValidationHandler = 196 CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_SCHEMA); 197 fConfiguration.setFeature(DOMConfigurationImpl.SCHEMA, true); 198 fNamespaceValidation = true; 200 201 fPSVI = ((fConfiguration.features & DOMConfigurationImpl.PSVI) !=0)?true:false; 203 } 204 205 fConfiguration.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, true); 206 207 fDocument.clearIdentifiers(); 209 210 if(fValidationHandler != null) 211 ((XMLComponent) fValidationHandler).reset(fConfiguration); 213 214 } 215 216 fErrorHandler = (DOMErrorHandler ) fConfiguration.getParameter(Constants.DOM_ERROR_HANDLER); 217 if (fValidationHandler != null) { 218 fValidationHandler.setDocumentHandler(this); 219 fValidationHandler.startDocument( 220 new SimpleLocator(fDocument.fDocumentURI, fDocument.fDocumentURI, 221 -1, -1 ), fDocument.encoding, fNamespaceContext, null); 222 223 } 224 try { 225 Node kid, next; 226 for (kid = fDocument.getFirstChild(); kid != null; kid = next) { 227 next = kid.getNextSibling(); 228 kid = normalizeNode(kid); 229 if (kid != null) { next = kid; 231 } 232 } 233 234 if (fValidationHandler != null) { 236 fValidationHandler.endDocument(null); 237 CoreDOMImplementationImpl.singleton.releaseValidator( 238 XMLGrammarDescription.XML_SCHEMA, fValidationHandler); 239 fValidationHandler = null; 240 } 241 } 242 catch (RuntimeException e) { 243 if( e==abort ) 244 return; throw e; } 247 248 } 249 250 251 266 protected Node normalizeNode (Node node){ 267 268 int type = node.getNodeType(); 269 boolean wellformed; 270 fLocator.fRelatedNode=node; 271 272 switch (type) { 273 case Node.DOCUMENT_TYPE_NODE: { 274 if (DEBUG_ND) { 275 System.out.println("==>normalizeNode:{doctype}"); 276 } 277 DocumentTypeImpl docType = (DocumentTypeImpl)node; 278 fDTDValidator = (XMLDTDValidator)CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_DTD); 279 fDTDValidator.setDocumentHandler(this); 280 fConfiguration.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY, createGrammarPool(docType)); 281 fDTDValidator.reset(fConfiguration); 282 fDTDValidator.startDocument( 283 new SimpleLocator(fDocument.fDocumentURI, fDocument.fDocumentURI, 284 -1, -1 ), fDocument.encoding, fNamespaceContext, null); 285 fDTDValidator.doctypeDecl(docType.getName(), docType.getPublicId(), docType.getSystemId(), null); 286 break; 288 } 289 290 case Node.ELEMENT_NODE: { 291 if (DEBUG_ND) { 292 System.out.println("==>normalizeNode:{element} "+node.getNodeName()); 293 } 294 295 if (fDocument.errorChecking) { 298 if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && 299 fDocument.isXMLVersionChanged()){ 300 if (fNamespaceValidation){ 301 wellformed = CoreDocumentImpl.isValidQName(node.getPrefix() , node.getLocalName(), fDocument.isXML11Version()) ; 302 } 303 else { 304 wellformed = CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); 305 } 306 if (!wellformed){ 307 String msg = DOMMessageFormatter.formatMessage( 308 DOMMessageFormatter.DOM_DOMAIN, 309 "wf-invalid-character-in-node-name", 310 new Object []{"Element", node.getNodeName()}); 311 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 312 "wf-invalid-character-in-node-name"); 313 } 314 } 315 } 316 fNamespaceContext.pushContext(); 318 fLocalNSBinder.reset(); 319 320 ElementImpl elem = (ElementImpl)node; 321 if (elem.needsSyncChildren()) { 322 elem.synchronizeChildren(); 323 } 324 AttributeMap attributes = (elem.hasAttributes()) ? (AttributeMap) elem.getAttributes() : null; 325 326 if ((fConfiguration.features & DOMConfigurationImpl.NAMESPACES) !=0) { 328 namespaceFixUp(elem, attributes); 332 333 if ((fConfiguration.features & DOMConfigurationImpl.NSDECL) == 0 && attributes != null ) { 334 for (int i = 0; i < attributes.getLength(); ++i) { 335 Attr att = (Attr )attributes.getItem(i); 336 if (XMLSymbols.PREFIX_XMLNS.equals(att.getPrefix()) || 337 XMLSymbols.PREFIX_XMLNS.equals(att.getName())) { 338 elem.removeAttributeNode(att); 339 --i; 340 } 341 } 342 } 343 344 } else { 345 if ( attributes!=null ) { 346 for ( int i=0; i<attributes.getLength(); ++i ) { 347 Attr attr = (Attr )attributes.item(i); 348 attr.normalize(); 350 if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ 351 isAttrValueWF(fErrorHandler, fError, fLocator, attributes, (AttrImpl)attr, attr.getValue(), fDocument.isXML11Version()); 352 if (fDocument.isXMLVersionChanged()){ 353 wellformed=CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); 354 if (!wellformed){ 355 String msg = DOMMessageFormatter.formatMessage( 356 DOMMessageFormatter.DOM_DOMAIN, 357 "wf-invalid-character-in-node-name", 358 new Object []{"Attr",node.getNodeName()}); 359 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 360 "wf-invalid-character-in-node-name"); 361 } 362 } 363 } 364 } 365 } 366 } 367 368 369 if (fValidationHandler != null) { 370 fAttrProxy.setAttributes(attributes, fDocument, elem); 374 updateQName(elem, fQName); fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 378 fCurrentNode = node; 379 fValidationHandler.startElement(fQName, fAttrProxy, null); 381 } 382 383 if (fDTDValidator != null) { 384 fAttrProxy.setAttributes(attributes, fDocument, elem); 388 updateQName(elem, fQName); fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 392 fCurrentNode = node; 393 fDTDValidator.startElement(fQName, fAttrProxy, null); 395 } 396 397 Node kid, next; 399 for (kid = elem.getFirstChild(); kid != null; kid = next) { 400 next = kid.getNextSibling(); 401 kid = normalizeNode(kid); 402 if (kid !=null) { 403 next = kid; } 405 } 406 if (DEBUG_ND) { 407 System.out.println("***The children of {"+node.getNodeName()+"} are normalized"); 409 for (kid = elem.getFirstChild(); kid != null; kid = next) { 410 next = kid.getNextSibling(); 411 System.out.println(kid.getNodeName() +"["+kid.getNodeValue()+"]"); 412 } 413 414 } 415 416 417 if (fValidationHandler != null) { 418 updateQName(elem, fQName); fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 423 fCurrentNode = node; 424 fValidationHandler.endElement(fQName, null); 425 } 426 427 if (fDTDValidator != null) { 428 updateQName(elem, fQName); fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 433 fCurrentNode = node; 434 fDTDValidator.endElement(fQName, null); 435 } 436 437 fNamespaceContext.popContext(); 439 440 break; 441 } 442 443 case Node.COMMENT_NODE: { 444 if (DEBUG_ND) { 445 System.out.println("==>normalizeNode:{comments}"); 446 } 447 448 if ((fConfiguration.features & DOMConfigurationImpl.COMMENTS) == 0) { 449 Node prevSibling = node.getPreviousSibling(); 450 Node parent = node.getParentNode(); 451 parent.removeChild(node); 453 if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE) { 454 Node nextSibling = prevSibling.getNextSibling(); 455 if (nextSibling != null && nextSibling.getNodeType() == Node.TEXT_NODE) { 456 ((TextImpl)nextSibling).insertData(0, prevSibling.getNodeValue()); 457 parent.removeChild(prevSibling); 458 return nextSibling; 459 } 460 } 461 } else { 463 if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ 464 String commentdata = ((Comment )node).getData(); 465 isCommentWF(fErrorHandler, fError, fLocator, commentdata, fDocument.isXML11Version()); 468 } 469 } break; 471 } 472 case Node.ENTITY_REFERENCE_NODE: { 473 if (DEBUG_ND) { 474 System.out.println("==>normalizeNode:{entityRef} "+node.getNodeName()); 475 } 476 477 if ((fConfiguration.features & DOMConfigurationImpl.ENTITIES) == 0) { 478 Node prevSibling = node.getPreviousSibling(); 479 Node parent = node.getParentNode(); 480 ((EntityReferenceImpl)node).setReadOnly(false, true); 481 expandEntityRef (parent, node); 482 parent.removeChild(node); 483 Node next = (prevSibling != null)?prevSibling.getNextSibling():parent.getFirstChild(); 484 if (prevSibling != null && next != null && prevSibling.getNodeType() == Node.TEXT_NODE && 488 next.getNodeType() == Node.TEXT_NODE) { 489 return prevSibling; } 491 return next; 492 } else { 493 if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && 494 fDocument.isXMLVersionChanged()){ 495 CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); 496 } 497 } 500 break; 501 } 502 503 case Node.CDATA_SECTION_NODE: { 504 if (DEBUG_ND) { 505 System.out.println("==>normalizeNode:{cdata}"); 506 } 507 508 if ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) { 509 Node prevSibling = node.getPreviousSibling(); 511 if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE){ 512 ((Text )prevSibling).appendData(node.getNodeValue()); 513 node.getParentNode().removeChild(node); 514 return prevSibling; } 516 else { 517 Text text = fDocument.createTextNode(node.getNodeValue()); 518 Node parent = node.getParentNode(); 519 node = parent.replaceChild(text, node); 520 return text; 522 } 523 } 524 525 if (fValidationHandler != null) { 527 fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 530 fCurrentNode = node; 531 fValidationHandler.startCDATA(null); 532 fValidationHandler.characterData(node.getNodeValue(), null); 533 fValidationHandler.endCDATA(null); 534 } 535 536 if (fDTDValidator != null) { 537 fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 540 fCurrentNode = node; 541 fDTDValidator.startCDATA(null); 542 fDTDValidator.characterData(node.getNodeValue(), null); 543 fDTDValidator.endCDATA(null); 544 } 545 String value = node.getNodeValue(); 546 547 if ((fConfiguration.features & DOMConfigurationImpl.SPLITCDATA) != 0) { 548 int index; 549 Node parent = node.getParentNode(); 550 if (fDocument.errorChecking) { 551 isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version()); 552 } 553 while ( (index=value.indexOf("]]>")) >= 0 ) { 554 node.setNodeValue(value.substring(0, index+2)); 555 value = value.substring(index +2); 556 557 Node firstSplitNode = node; 558 Node newChild = fDocument.createCDATASection(value); 559 parent.insertBefore(newChild, node.getNextSibling()); 560 node = newChild; 561 fLocator.fRelatedNode = firstSplitNode; 563 String msg = DOMMessageFormatter.formatMessage( 564 DOMMessageFormatter.DOM_DOMAIN, 565 "cdata-sections-splitted", 566 null); 567 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_WARNING, 568 "cdata-sections-splitted"); 569 } 570 571 } 572 else if (fDocument.errorChecking) { 573 isCDataWF(fErrorHandler, fError, fLocator, value, fDocument.isXML11Version()); 575 } 576 break; 577 } 578 579 case Node.TEXT_NODE: { 580 if (DEBUG_ND) { 581 System.out.println("==>normalizeNode(text):{"+node.getNodeValue()+"}"); 582 } 583 Node next = node.getNextSibling(); 589 if ( next!=null && next.getNodeType() == Node.TEXT_NODE ) { 591 ((Text )node).appendData(next.getNodeValue()); 592 node.getParentNode().removeChild( next ); 593 596 return node; } else if (node.getNodeValue().length()==0) { 598 node.getParentNode().removeChild( node ); 600 } else { 601 607 short nextType = (next != null)?next.getNodeType():-1; 608 if (nextType == -1 || !(((fConfiguration.features & DOMConfigurationImpl.ENTITIES) == 0 && 609 nextType == Node.ENTITY_NODE) || 610 ((fConfiguration.features & DOMConfigurationImpl.COMMENTS) == 0 && 611 nextType == Node.COMMENT_NODE) || 612 ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) && 613 nextType == Node.CDATA_SECTION_NODE)) { 614 if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) ){ 615 isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version()); 616 } 617 if (fValidationHandler != null) { 618 fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 619 fCurrentNode = node; 620 fValidationHandler.characterData(node.getNodeValue(), null); 621 if (DEBUG_ND) { 622 System.out.println("=====>characterData(),"+nextType); 623 624 } 625 } 626 if (fDTDValidator != null) { 627 fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 628 fCurrentNode = node; 629 fDTDValidator.characterData(node.getNodeValue(), null); 630 if (DEBUG_ND) { 631 System.out.println("=====>characterData(),"+nextType); 632 633 } 634 if(allWhitespace) { 635 allWhitespace = false; 636 ((TextImpl)node).setIgnorableWhitespace(true); 637 } 638 } 639 } 640 else { 641 if (DEBUG_ND) { 642 System.out.println("=====>don't send characters(),"+nextType); 643 644 } 645 } 646 } 647 break; 648 } 649 case Node.PROCESSING_INSTRUCTION_NODE: { 650 651 if (fDocument.errorChecking && (fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0 ) { 653 ProcessingInstruction pinode = (ProcessingInstruction )node ; 654 655 String target = pinode.getTarget(); 656 if(fDocument.isXML11Version()){ 658 wellformed = XML11Char.isXML11ValidName(target); 659 } 660 else{ 661 wellformed = XMLChar.isValidName(target); 662 } 663 664 if (!wellformed) { 665 String msg = DOMMessageFormatter.formatMessage( 666 DOMMessageFormatter.DOM_DOMAIN, 667 "wf-invalid-character-in-node-name", 668 new Object []{"Element", node.getNodeName()}); 669 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 670 "wf-invalid-character-in-node-name"); 671 } 672 673 isXMLCharWF(fErrorHandler, fError, fLocator, pinode.getData(), fDocument.isXML11Version()); 677 } 678 } 680 } return null; 682 } 684 private XMLGrammarPool createGrammarPool(DocumentTypeImpl docType) { 685 686 XMLGrammarPoolImpl pool = new XMLGrammarPoolImpl(); 687 688 XMLGrammarPreparser preParser = new XMLGrammarPreparser(fSymbolTable); 689 preParser.registerPreparser(XMLGrammarDescription.XML_DTD, null); 690 preParser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true); 691 preParser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, true); 692 preParser.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY, pool); 693 694 String internalSubset = docType.getInternalSubset(); 695 XMLInputSource is = new XMLInputSource(docType.getPublicId(), docType.getSystemId(), null); 696 697 if(internalSubset != null) 698 is.setCharacterStream(new StringReader (internalSubset)); 699 try { 700 DTDGrammar g = (DTDGrammar)preParser.preparseGrammar(XMLGrammarDescription.XML_DTD, is); 701 ((XMLDTDDescription)g.getGrammarDescription()).setRootName(docType.getName()); 702 is.setCharacterStream(null); 703 g = (DTDGrammar)preParser.preparseGrammar(XMLGrammarDescription.XML_DTD, is); 704 ((XMLDTDDescription)g.getGrammarDescription()).setRootName(docType.getName()); 705 706 } catch (XNIException e) { 707 } catch (IOException e) { 708 } 709 710 return pool; 711 } 712 713 714 715 protected final void expandEntityRef (Node parent, Node reference){ 716 Node kid, next; 717 for (kid = reference.getFirstChild(); kid != null; kid = next) { 718 next = kid.getNextSibling(); 719 parent.insertBefore(kid, reference); 720 } 721 } 722 723 728 protected final void namespaceFixUp (ElementImpl element, AttributeMap attributes){ 729 if (DEBUG) { 730 System.out.println("[ns-fixup] element:" +element.getNodeName()+ 731 " uri: "+element.getNamespaceURI()); 732 } 733 734 744 String value, name, uri, prefix; 745 if (attributes != null) { 746 747 for (int k = 0; k < attributes.getLength(); ++k) { 749 Attr attr = (Attr )attributes.getItem(k); 750 751 if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && 754 fDocument.isXMLVersionChanged()) { 755 fDocument.checkQName(attr.getPrefix() , attr.getLocalName()) ; 757 } 758 759 uri = attr.getNamespaceURI(); 760 if (uri != null && uri.equals(NamespaceContext.XMLNS_URI)) { 761 value = attr.getNodeValue(); 763 if (value == null) { 764 value=XMLSymbols.EMPTY_STRING; 765 } 766 767 if (fDocument.errorChecking && value.equals(NamespaceContext.XMLNS_URI)) { 769 fLocator.fRelatedNode = attr; 772 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,"CantBindXMLNS",null ); 773 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, "CantBindXMLNS"); 774 } else { 775 prefix = attr.getPrefix(); 778 prefix = (prefix == null || 779 prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); 780 String localpart = fSymbolTable.addSymbol( attr.getLocalName()); 781 if (prefix == XMLSymbols.PREFIX_XMLNS) { 783 value = fSymbolTable.addSymbol(value); 784 if (value.length() != 0) { 785 fNamespaceContext.declarePrefix(localpart, value); 786 } else { 787 790 } 791 continue; 793 } else { value = fSymbolTable.addSymbol(value); 796 fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, value); 797 continue; 799 } 800 } } } 803 } 804 805 806 807 822 uri = element.getNamespaceURI(); 823 prefix = element.getPrefix(); 824 if (uri != null) { uri = fSymbolTable.addSymbol(uri); 826 prefix = (prefix == null || 827 prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); 828 if (fNamespaceContext.getURI(prefix) == uri) { 829 } else { 832 addNamespaceDecl(prefix, uri, element); 836 fLocalNSBinder.declarePrefix(prefix, uri); 837 fNamespaceContext.declarePrefix(prefix, uri); 838 } 839 } else { if (element.getLocalName() == null) { 841 842 if (fNamespaceValidation) { 844 String msg = DOMMessageFormatter.formatMessage( 845 DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", 846 new Object []{element.getNodeName()}); 847 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR, 848 "NullLocalElementName"); 849 } else { 850 String msg = DOMMessageFormatter.formatMessage( 851 DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", 852 new Object []{element.getNodeName()}); 853 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 854 "NullLocalElementName"); 855 } 856 857 } else { uri = fNamespaceContext.getURI(XMLSymbols.EMPTY_STRING); 859 if (uri !=null && uri.length() > 0) { 860 addNamespaceDecl (XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING, element); 863 fLocalNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); 864 fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); 865 } 866 } 867 } 868 869 if (attributes != null) { 874 875 attributes.cloneMap(fAttributeList); 877 for (int i = 0; i < fAttributeList.size(); i++) { 878 Attr attr = (Attr ) fAttributeList.elementAt(i); 879 fLocator.fRelatedNode = attr; 880 881 if (DEBUG) { 882 System.out.println("==>[ns-fixup] process attribute: "+attr.getNodeName()); 883 } 884 attr.normalize(); 886 value = attr.getValue(); 887 name = attr.getNodeName(); 888 uri = attr.getNamespaceURI(); 889 890 if (value == null) { 892 value=XMLSymbols.EMPTY_STRING; 893 } 894 895 if (uri != null) { prefix = attr.getPrefix(); 897 prefix = (prefix == null || 898 prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); 899 fSymbolTable.addSymbol( attr.getLocalName()); 900 901 if (uri != null && uri.equals(NamespaceContext.XMLNS_URI)) { 907 continue; 908 } 909 if (fDocument.errorChecking && ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)) { 913 isAttrValueWF(fErrorHandler, fError, fLocator, attributes, (AttrImpl)attr, attr.getValue(), fDocument.isXML11Version()); 914 if (fDocument.isXMLVersionChanged()){ 915 boolean wellformed=CoreDocumentImpl.isXMLName(attr.getNodeName() , fDocument.isXML11Version()); 916 if (!wellformed){ 917 String msg = DOMMessageFormatter.formatMessage( 918 DOMMessageFormatter.DOM_DOMAIN, 919 "wf-invalid-character-in-node-name", 920 new Object []{"Attribute", attr.getNodeName()}); 921 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 922 "wf-invalid-character-in-node-name"); 923 } 924 } 925 } 926 927 935 938 ((AttrImpl)attr).setIdAttribute(false); 940 941 942 uri = fSymbolTable.addSymbol(uri); 943 944 String declaredURI = fNamespaceContext.getURI(prefix); 946 947 if (prefix == XMLSymbols.EMPTY_STRING || declaredURI != uri) { 948 955 name = attr.getNodeName(); 956 String declaredPrefix = fNamespaceContext.getPrefix(uri); 959 if (declaredPrefix !=null && declaredPrefix !=XMLSymbols.EMPTY_STRING) { 960 961 prefix = declaredPrefix; 963 } else { 964 if (prefix != XMLSymbols.EMPTY_STRING && fLocalNSBinder.getURI(prefix) == null) { 965 967 } else { 969 970 int counter = 1; 973 prefix = fSymbolTable.addSymbol(PREFIX +counter++); 974 while (fLocalNSBinder.getURI(prefix)!=null) { 975 prefix = fSymbolTable.addSymbol(PREFIX +counter++); 976 } 977 978 } 979 addNamespaceDecl(prefix, uri, element); 981 value = fSymbolTable.addSymbol(value); 982 fLocalNSBinder.declarePrefix(prefix, value); 983 fNamespaceContext.declarePrefix(prefix, uri); 984 } 985 986 attr.setPrefix(prefix); 988 } 989 } else { 991 994 ((AttrImpl)attr).setIdAttribute(false); 996 997 if (attr.getLocalName() == null) { 998 if (fNamespaceValidation) { 1000 String msg = DOMMessageFormatter.formatMessage( 1001 DOMMessageFormatter.DOM_DOMAIN, 1002 "NullLocalAttrName", new Object []{attr.getNodeName()}); 1003 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR, 1004 "NullLocalAttrName"); 1005 } else { 1006 String msg = DOMMessageFormatter.formatMessage( 1007 DOMMessageFormatter.DOM_DOMAIN, 1008 "NullLocalAttrName", new Object []{attr.getNodeName()}); 1009 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 1010 "NullLocalAttrName"); 1011 } 1012 } else { 1013 1016 } 1021 } 1022 } 1023 } } 1025 1026 1035 1036 protected final void addNamespaceDecl(String prefix, String uri, ElementImpl element){ 1037 if (DEBUG) { 1038 System.out.println("[ns-fixup] addNamespaceDecl ["+prefix+"]"); 1039 } 1040 if (prefix == XMLSymbols.EMPTY_STRING) { 1041 if (DEBUG) { 1042 System.out.println("=>add xmlns=\""+uri+"\" declaration"); 1043 } 1044 element.setAttributeNS(NamespaceContext.XMLNS_URI, XMLSymbols.PREFIX_XMLNS, uri); 1045 } else { 1046 if (DEBUG) { 1047 System.out.println("=>add xmlns:"+prefix+"=\""+uri+"\" declaration"); 1048 } 1049 element.setAttributeNS(NamespaceContext.XMLNS_URI, "xmlns:"+prefix, uri); 1050 } 1051 } 1052 1053 1054 1058 1059 1064 public static final void isCDataWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator, 1065 String datavalue, boolean isXML11Version) 1066 { 1067 if (datavalue == null || (datavalue.length() == 0) ) { 1068 return; 1069 } 1070 1071 char [] dataarray = datavalue.toCharArray(); 1072 int datalength = dataarray.length; 1073 1074 if (isXML11Version) { 1076 int i = 0; 1078 while(i < datalength){ 1079 char c = dataarray[i++]; 1080 if ( XML11Char.isXML11Invalid(c) ) { 1081 if (XMLChar.isHighSurrogate(c) && i < datalength) { 1083 char c2 = dataarray[i++]; 1084 if (XMLChar.isLowSurrogate(c2) && 1085 XMLChar.isSupplemental(XMLChar.supplemental(c, c2))) { 1086 continue; 1087 } 1088 } 1089 String msg = DOMMessageFormatter.formatMessage( 1090 DOMMessageFormatter.XML_DOMAIN, 1091 "InvalidCharInCDSect", 1092 new Object [] { Integer.toString(c, 16)}); 1093 reportDOMError( 1094 errorHandler, 1095 error, 1096 locator, 1097 msg, 1098 DOMError.SEVERITY_ERROR, 1099 "wf-invalid-character"); 1100 } 1101 else if (c == ']') { 1102 int count = i; 1103 if (count < datalength && dataarray[count] == ']') { 1104 while (++count < datalength && dataarray[count] == ']') { 1105 } 1107 if (count < datalength && dataarray[count] == '>') { 1108 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, "CDEndInContent", null); 1110 reportDOMError(errorHandler, error, locator,msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1111 } 1112 } 1113 1114 } 1115 } 1116 } else { 1118 int i = 0; 1120 while (i < datalength) { 1121 char c = dataarray[i++]; 1122 if( XMLChar.isInvalid(c) ) { 1123 if (XMLChar.isHighSurrogate(c) && i < datalength) { 1125 char c2 = dataarray[i++]; 1126 if (XMLChar.isLowSurrogate(c2) && 1127 XMLChar.isSupplemental(XMLChar.supplemental(c, c2))) { 1128 continue; 1129 } 1130 } 1131 String msg = DOMMessageFormatter.formatMessage( 1136 DOMMessageFormatter.XML_DOMAIN, 1137 "InvalidCharInCDSect", 1138 new Object []{Integer.toString(c, 16)}); 1139 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1140 } 1141 else if (c==']') { 1142 int count = i; 1143 if ( count< datalength && dataarray[count]==']' ) { 1144 while (++count < datalength && dataarray[count]==']' ) { 1145 } 1147 if ( count < datalength && dataarray[count]=='>' ) { 1148 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, "CDEndInContent", null); 1149 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1150 } 1151 } 1152 1153 } 1154 } 1155 } 1157 } 1159 1164 public static final void isXMLCharWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator, 1165 String datavalue, boolean isXML11Version) 1166 { 1167 if ( datavalue == null || (datavalue.length() == 0) ) { 1168 return; 1169 } 1170 1171 char [] dataarray = datavalue.toCharArray(); 1172 int datalength = dataarray.length; 1173 1174 if(isXML11Version){ 1176 int i = 0 ; 1178 while (i < datalength) { 1179 if(XML11Char.isXML11Invalid(dataarray[i++])){ 1180 char ch = dataarray[i-1]; 1182 if (XMLChar.isHighSurrogate(ch) && i < datalength) { 1183 char ch2 = dataarray[i++]; 1184 if (XMLChar.isLowSurrogate(ch2) && 1185 XMLChar.isSupplemental(XMLChar.supplemental(ch, ch2))) { 1186 continue; 1187 } 1188 } 1189 String msg = DOMMessageFormatter.formatMessage( 1190 DOMMessageFormatter.DOM_DOMAIN, "InvalidXMLCharInDOM", 1191 new Object []{Integer.toString(dataarray[i-1], 16)}); 1192 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, 1193 "wf-invalid-character"); 1194 } 1195 } 1196 } else{ 1198 int i = 0 ; 1200 while (i < datalength) { 1201 if( XMLChar.isInvalid(dataarray[i++]) ) { 1202 char ch = dataarray[i-1]; 1204 if (XMLChar.isHighSurrogate(ch) && i < datalength) { 1205 char ch2 = dataarray[i++]; 1206 if (XMLChar.isLowSurrogate(ch2) && 1207 XMLChar.isSupplemental(XMLChar.supplemental(ch, ch2))) { 1208 continue; 1209 } 1210 } 1211 String msg = DOMMessageFormatter.formatMessage( 1212 DOMMessageFormatter.DOM_DOMAIN, "InvalidXMLCharInDOM", 1213 new Object []{Integer.toString(dataarray[i-1], 16)}); 1214 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, 1215 "wf-invalid-character"); 1216 } 1217 } 1218 } 1220 } 1222 1227 public static final void isCommentWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator, 1228 String datavalue, boolean isXML11Version) 1229 { 1230 if ( datavalue == null || (datavalue.length() == 0) ) { 1231 return; 1232 } 1233 1234 char [] dataarray = datavalue.toCharArray(); 1235 int datalength = dataarray.length ; 1236 1237 if (isXML11Version) { 1239 int i = 0 ; 1241 while (i < datalength){ 1242 char c = dataarray[i++]; 1243 if ( XML11Char.isXML11Invalid(c) ) { 1244 if (XMLChar.isHighSurrogate(c) && i < datalength) { 1246 char c2 = dataarray[i++]; 1247 if (XMLChar.isLowSurrogate(c2) && 1248 XMLChar.isSupplemental(XMLChar.supplemental(c, c2))) { 1249 continue; 1250 } 1251 } 1252 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1253 "InvalidCharInComment", 1254 new Object [] {Integer.toString(dataarray[i-1], 16)}); 1255 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1256 } 1257 else if (c == '-' && i < datalength && dataarray[i] == '-') { 1258 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1259 "DashDashInComment", null); 1260 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1262 } 1263 } 1264 } else { 1266 int i = 0; 1268 while (i < datalength){ 1269 char c = dataarray[i++]; 1270 if( XMLChar.isInvalid(c) ){ 1271 if (XMLChar.isHighSurrogate(c) && i < datalength) { 1273 char c2 = dataarray[i++]; 1274 if (XMLChar.isLowSurrogate(c2) && 1275 XMLChar.isSupplemental(XMLChar.supplemental(c, c2))) { 1276 continue; 1277 } 1278 } 1279 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1280 "InvalidCharInComment", new Object [] {Integer.toString(dataarray[i-1], 16)}); 1281 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1282 } 1283 else if (c == '-' && i<datalength && dataarray[i]=='-'){ 1284 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1285 "DashDashInComment", null); 1286 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1288 } 1289 } 1290 1291 } 1293 } 1295 1300 public static final void isAttrValueWF(DOMErrorHandler errorHandler, DOMErrorImpl error, 1301 DOMLocatorImpl locator, NamedNodeMap attributes, Attr a, String value, boolean xml11Version) { 1302 if (a instanceof AttrImpl && ((AttrImpl)a).hasStringValue()) { 1303 isXMLCharWF(errorHandler, error, locator, value, xml11Version); 1304 } else { 1305 NodeList children = a.getChildNodes(); 1306 for (int j = 0; j < children.getLength(); j++) { 1308 Node child = children.item(j); 1309 if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) { 1311 Document owner = a.getOwnerDocument(); 1312 Entity ent = null; 1313 if (owner != null) { 1316 DocumentType docType = owner.getDoctype(); 1317 if (docType != null) { 1318 NamedNodeMap entities = docType.getEntities(); 1319 ent = (Entity ) entities.getNamedItemNS( 1320 "*", 1321 child.getNodeName()); 1322 } 1323 } 1324 if (ent == null) { 1326 String msg = DOMMessageFormatter.formatMessage( 1327 DOMMessageFormatter.DOM_DOMAIN, "UndeclaredEntRefInAttrValue", 1328 new Object []{a.getNodeName()}); 1329 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, 1330 "UndeclaredEntRefInAttrValue"); 1331 } 1332 } 1333 else { 1334 isXMLCharWF(errorHandler, error, locator, child.getNodeValue(), xml11Version); 1336 } 1337 } 1338 } 1339 } 1340 1341 1342 1343 1348 public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator, 1349 String message, short severity, String type ) { 1350 if( errorHandler!=null ) { 1351 error.reset(); 1352 error.fMessage = message; 1353 error.fSeverity = severity; 1354 error.fLocator = locator; 1355 error.fType = type; 1356 error.fRelatedData = locator.fRelatedNode; 1357 1358 if(!errorHandler.handleError(error)) 1359 throw abort; 1360 } 1361 if( severity==DOMError.SEVERITY_FATAL_ERROR ) 1362 throw abort; 1363 } 1364 1365 protected final void updateQName (Node node, QName qname){ 1366 1367 String prefix = node.getPrefix(); 1368 String namespace = node.getNamespaceURI(); 1369 String localName = node.getLocalName(); 1370 qname.prefix = (prefix!=null && prefix.length()!=0)?fSymbolTable.addSymbol(prefix):null; 1373 qname.localpart = (localName != null)?fSymbolTable.addSymbol(localName):null; 1374 qname.rawname = fSymbolTable.addSymbol(node.getNodeName()); 1375 qname.uri = (namespace != null)?fSymbolTable.addSymbol(namespace):null; 1376 } 1377 1378 1379 1380 1398 final String normalizeAttributeValue(String value, Attr attr) { 1399 if (!attr.getSpecified()){ 1400 return value; 1403 } 1404 int end = value.length(); 1405 if (fNormalizedValue.ch.length < end) { 1407 fNormalizedValue.ch = new char[end]; 1408 } 1409 fNormalizedValue.length = 0; 1410 boolean normalized = false; 1411 for (int i = 0; i < end; i++) { 1412 char c = value.charAt(i); 1413 if (c==0x0009 || c==0x000A) { 1414 fNormalizedValue.ch[fNormalizedValue.length++] = ' '; 1415 normalized = true; 1416 } 1417 else if(c==0x000D){ 1418 normalized = true; 1419 fNormalizedValue.ch[fNormalizedValue.length++] = ' '; 1420 int next = i+1; 1421 if (next < end && value.charAt(next)==0x000A) i=next; } 1423 else { 1424 fNormalizedValue.ch[fNormalizedValue.length++] = c; 1425 } 1426 } 1427 if (normalized){ 1428 value = fNormalizedValue.toString(); 1429 attr.setValue(value); 1430 } 1431 return value; 1432 } 1433 1434 protected final class XMLAttributesProxy 1435 implements XMLAttributes { 1436 protected AttributeMap fAttributes; 1437 protected CoreDocumentImpl fDocument; 1438 protected ElementImpl fElement; 1439 1440 protected final Vector fAugmentations = new Vector (5); 1441 1442 1443 public void setAttributes(AttributeMap attributes, CoreDocumentImpl doc, ElementImpl elem) { 1444 fDocument = doc; 1445 fAttributes = attributes; 1446 fElement = elem; 1447 if (attributes != null) { 1448 int length = attributes.getLength(); 1449 1450 fAugmentations.setSize(length); 1451 for (int i = 0; i < length; i++) { 1455 fAugmentations.setElementAt(new AugmentationsImpl(), i); 1456 } 1457 } else { 1458 fAugmentations.setSize(0); 1459 } 1460 } 1461 1462 1463 1467 public int addAttribute(QName qname, String attrType, String attrValue) { 1468 int index = fElement.getXercesAttribute(qname.uri, qname.localpart); 1469 if (index < 0) { 1471 AttrImpl attr = (AttrImpl) 1474 ((CoreDocumentImpl) fElement.getOwnerDocument()).createAttributeNS( 1475 qname.uri, 1476 qname.rawname, 1477 qname.localpart); 1478 index = fElement.setXercesAttributeNode(attr); 1480 attr.setNodeValue(attrValue); 1481 fAugmentations.insertElementAt(new AugmentationsImpl(), index); 1482 attr.setSpecified(false); 1483 } 1484 else { 1485 1491 } 1492 return index; 1493 } 1494 1495 1496 public void removeAllAttributes(){ 1497 } 1499 1500 1501 public void removeAttributeAt(int attrIndex){ 1502 } 1504 1505 1506 public int getLength(){ 1507 return(fAttributes != null)?fAttributes.getLength():0; 1508 } 1509 1510 1511 public int getIndex(String qName){ 1512 return -1; 1514 } 1515 1516 public int getIndex(String uri, String localPart){ 1517 return -1; 1519 } 1520 1521 public void setName(int attrIndex, QName attrName){ 1522 } 1524 1525 public void getName(int attrIndex, QName attrName){ 1526 if (fAttributes !=null) { 1527 updateQName((Node )fAttributes.getItem(attrIndex), attrName); 1528 } 1529 } 1530 1531 public String getPrefix(int index){ 1532 return null; 1534 } 1535 1536 1537 public String getURI(int index){ 1538 return null; 1540 } 1541 1542 1543 public String getLocalName(int index){ 1544 return null; 1546 } 1547 1548 1549 public String getQName(int index){ 1550 return null; 1552 } 1553 1554 1555 public void setType(int attrIndex, String attrType){ 1556 } 1558 1559 1560 public String getType(int index){ 1561 return "CDATA"; 1562 } 1563 1564 1565 public String getType(String qName){ 1566 return "CDATA"; 1567 } 1568 1569 1570 public String getType(String uri, String localName){ 1571 return "CDATA"; 1572 } 1573 1574 1575 public void setValue(int attrIndex, String attrValue){ 1576 1580 if (fAttributes != null){ 1581 AttrImpl attr = (AttrImpl)fAttributes.getItem(attrIndex); 1582 boolean specified = attr.getSpecified(); 1583 attr.setValue(attrValue); 1584 attr.setSpecified(specified); 1585 1586 } 1587 } 1588 1589 1590 public String getValue(int index){ 1591 return (fAttributes !=null)?fAttributes.item(index).getNodeValue():""; 1592 1593 } 1594 1595 1596 public String getValue(String qName){ 1597 return null; 1599 } 1600 1601 1602 public String getValue(String uri, String localName){ 1603 if (fAttributes != null) { 1604 Node node = fAttributes.getNamedItemNS(uri, localName); 1605 return(node != null)? node.getNodeValue():null; 1606 } 1607 return null; 1608 } 1609 1610 1611 public void setNonNormalizedValue(int attrIndex, String attrValue){ 1612 1614 } 1615 1616 1617 public String getNonNormalizedValue(int attrIndex){ 1618 return null; 1620 } 1621 1622 1623 public void setSpecified(int attrIndex, boolean specified){ 1624 AttrImpl attr = (AttrImpl)fAttributes.getItem(attrIndex); 1625 attr.setSpecified(specified); 1626 } 1627 1628 public boolean isSpecified(int attrIndex){ 1629 return((Attr )fAttributes.getItem(attrIndex)).getSpecified(); 1630 } 1631 1632 public Augmentations getAugmentations (int attributeIndex){ 1633 return(Augmentations)fAugmentations.elementAt(attributeIndex); 1634 } 1635 1636 public Augmentations getAugmentations (String uri, String localPart){ 1637 return null; 1639 } 1640 1641 public Augmentations getAugmentations(String qName){ 1642 return null; 1644 } 1645 1646 1652 public void setAugmentations(int attrIndex, Augmentations augs) { 1653 fAugmentations.setElementAt(augs, attrIndex); 1654 } 1655 } 1656 1657 1661 1688 public void startDocument(XMLLocator locator, String encoding, 1689 NamespaceContext namespaceContext, 1690 Augmentations augs) 1691 throws XNIException{ 1692 } 1693 1694 1708 public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) 1709 throws XNIException{ 1710 } 1711 1712 1726 public void doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs) 1727 throws XNIException{ 1728 } 1729 1730 1739 public void comment(XMLString text, Augmentations augs) throws XNIException{ 1740 } 1741 1742 1760 public void processingInstruction(String target, XMLString data, Augmentations augs) 1761 throws XNIException{ 1762 } 1763 1764 1774 public void startElement(QName element, XMLAttributes attributes, Augmentations augs) 1775 throws XNIException { 1776 Element currentElement = (Element ) fCurrentNode; 1777 int attrCount = attributes.getLength(); 1778 if (DEBUG_EVENTS) { 1779 System.out.println("==>startElement: " +element+ 1780 " attrs.length="+attrCount); 1781 } 1782 1783 for (int i = 0; i < attrCount; i++) { 1784 attributes.getName(i, fAttrQName); 1785 Attr attr = null; 1786 1787 attr = currentElement.getAttributeNodeNS(fAttrQName.uri, fAttrQName.localpart); 1788 AttributePSVI attrPSVI = 1789 (AttributePSVI) attributes.getAugmentations(i).getItem(Constants.ATTRIBUTE_PSVI); 1790 1791 if (attrPSVI != null) { 1792 XSTypeDefinition decl = attrPSVI.getMemberTypeDefinition(); 1795 boolean id = false; 1796 if (decl != null){ 1797 id = ((XSSimpleType)decl).isIDType(); 1798 } else{ 1799 decl = attrPSVI.getTypeDefinition(); 1800 if (decl !=null){ 1801 id = ((XSSimpleType)decl).isIDType(); 1802 } 1803 } 1804 if (id){ 1805 ((ElementImpl)currentElement).setIdAttributeNode(attr, true); 1806 } 1807 1808 if (fPSVI) { 1809 ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI); 1810 } 1811 if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) { 1812 boolean specified = attr.getSpecified(); 1818 attr.setValue(attrPSVI.getSchemaNormalizedValue()); 1819 if (!specified) { 1820 ((AttrImpl) attr).setSpecified(specified); 1821 } 1822 } 1823 } 1824 } 1825 } 1826 1827 1828 1838 public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) 1839 throws XNIException { 1840 if (DEBUG_EVENTS) { 1841 System.out.println("==>emptyElement: " +element); 1842 } 1843 1844 startElement(element, attributes, augs); 1845 endElement(element, augs); 1846 } 1847 1848 1865 public void startGeneralEntity(String name, 1866 XMLResourceIdentifier identifier, 1867 String encoding, 1868 Augmentations augs) throws XNIException{ 1869 } 1870 1871 1889 public void textDecl(String version, String encoding, Augmentations augs) throws XNIException{ 1890 } 1891 1892 1904 public void endGeneralEntity(String name, Augmentations augs) throws XNIException{ 1905 } 1906 1907 1916 public void characters(XMLString text, Augmentations augs) throws XNIException{ 1917 } 1918 1919 1933 public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException{ 1934 allWhitespace = true; 1935 } 1936 1937 1946 public void endElement(QName element, Augmentations augs) throws XNIException { 1947 if (DEBUG_EVENTS) { 1948 System.out.println("==>endElement: " + element); 1949 } 1950 1951 if(augs != null) { 1952 ElementPSVI elementPSVI = (ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI); 1953 if (elementPSVI != null) { 1954 ElementImpl elementNode = (ElementImpl) fCurrentNode; 1955 if (fPSVI) { 1956 ((PSVIElementNSImpl) fCurrentNode).setPSVI(elementPSVI); 1957 } 1958 String normalizedValue = elementPSVI.getSchemaNormalizedValue(); 1960 if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) { 1961 if (normalizedValue !=null) 1962 elementNode.setTextContent(normalizedValue); 1963 } 1964 else { 1965 String text = elementNode.getTextContent(); 1969 if (text.length() == 0) { 1970 if (normalizedValue !=null) 1972 elementNode.setTextContent(normalizedValue); 1973 } 1974 } 1975 } 1976 } 1977 } 1978 1979 1980 1988 public void startCDATA(Augmentations augs) throws XNIException{ 1989 } 1990 1991 1999 public void endCDATA(Augmentations augs) throws XNIException{ 2000 } 2001 2002 2010 public void endDocument(Augmentations augs) throws XNIException{ 2011 } 2012 2013 2014 2015 public void setDocumentSource(XMLDocumentSource source){ 2016 } 2017 2018 2019 2020 public XMLDocumentSource getDocumentSource(){ 2021 return null; 2022 } 2023 2024 2025} | Popular Tags |