1 57 58 package com.sun.org.apache.xerces.internal.dom; 59 60 61 import java.util.Vector ; 62 import com.sun.org.apache.xerces.internal.parsers.XMLGrammarPreparser; 64 import com.sun.org.apache.xerces.internal.parsers.IntegratedParserConfiguration; 65 import com.sun.org.apache.xerces.internal.util.XMLGrammarPoolImpl; 66 import com.sun.org.apache.xerces.internal.xni.grammars.Grammar; 67 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 68 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration; 69 import org.xml.sax.InputSource ; 70 72 import org.w3c.dom.DOMError ; 73 import org.w3c.dom.DOMErrorHandler ; 74 import com.sun.org.apache.xerces.internal.impl.Constants; 75 import com.sun.org.apache.xerces.internal.impl.RevalidationHandler; 76 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; 77 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 78 import com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator; 79 import com.sun.org.apache.xerces.internal.util.AugmentationsImpl; 80 import com.sun.org.apache.xerces.internal.util.NamespaceSupport; 81 import com.sun.org.apache.xerces.internal.util.SymbolTable; 82 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 83 import com.sun.org.apache.xerces.internal.xni.Augmentations; 84 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 85 import com.sun.org.apache.xerces.internal.xni.QName; 86 import com.sun.org.apache.xerces.internal.xni.XMLAttributes; 87 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 88 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 89 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 90 import com.sun.org.apache.xerces.internal.xni.XMLString; 91 import com.sun.org.apache.xerces.internal.xni.XNIException; 92 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; 93 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 94 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 95 import com.sun.org.apache.xerces.internal.xs.AttributePSVI; 96 import com.sun.org.apache.xerces.internal.xs.ElementPSVI; 97 import org.w3c.dom.Attr ; 98 import org.w3c.dom.Element ; 99 import org.w3c.dom.Node ; 100 import org.w3c.dom.NodeList ; 101 import org.w3c.dom.Text ; 102 import org.w3c.dom.ProcessingInstruction ; 103 import com.sun.org.apache.xerces.internal.util.XML11Char; 104 import com.sun.org.apache.xerces.internal.util.XMLChar; 105 import org.w3c.dom.Document ; 106 import org.w3c.dom.DocumentType ; 107 import org.w3c.dom.Entity ; 108 import org.w3c.dom.NamedNodeMap ; 109 import org.w3c.dom.Comment ; 110 import com.sun.org.apache.xerces.internal.impl.dtd.*; 111 import java.io.*; 112 113 139 public class DOMNormalizer implements XMLDocumentHandler { 140 141 142 146 148 149 public static final String SYMBOL_TABLE = Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 150 151 152 public static final String GRAMMAR_POOL = Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 153 154 156 157 protected static final String NAMESPACES_FEATURE_ID = "http://xml.org/sax/features/namespaces"; 158 159 160 protected static final String VALIDATION_FEATURE_ID = "http://xml.org/sax/features/validation"; 161 162 163 protected static final String SCHEMA_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/schema"; 164 165 166 protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking"; 167 168 173 protected final static boolean DEBUG_ND = false; 174 175 protected final static boolean DEBUG = false; 176 177 protected final static boolean DEBUG_EVENTS = false; 178 179 180 protected final static String PREFIX = "NS"; 181 182 protected DOMConfigurationImpl fConfiguration = null; 186 protected CoreDocumentImpl fDocument = null; 187 protected final XMLAttributesProxy fAttrProxy = new XMLAttributesProxy(); 188 protected final QName fQName = new QName(); 189 190 191 protected RevalidationHandler fValidationHandler; 192 protected XMLDTDValidator fDTDValidator; 193 194 195 protected SymbolTable fSymbolTable; 196 197 protected DOMErrorHandler fErrorHandler; 198 199 203 private final DOMErrorImpl fError = new DOMErrorImpl(); 204 205 protected boolean fNamespaceValidation = false; 207 208 protected boolean fPSVI = false; 210 211 212 protected final NamespaceContext fNamespaceContext = new NamespaceSupport(); 213 214 215 protected final NamespaceContext fLocalNSBinder = new NamespaceSupport(); 216 217 218 protected final Vector fAttributeList = new Vector (5,10); 219 220 221 222 protected final DOMLocatorImpl fLocator = new DOMLocatorImpl(); 223 224 225 protected Node fCurrentNode = null; 226 private QName fAttrQName = new QName(); 227 228 final XMLString fNormalizedValue = new XMLString(new char[16], 0, 0); 230 231 234 public static final RuntimeException abort = new RuntimeException (); 235 236 239 public boolean isWhitespace = false; 240 public boolean docTypeFound = false; 241 242 public DOMNormalizer(){} 243 244 245 246 250 protected void normalizeDocument(CoreDocumentImpl document, DOMConfigurationImpl config) { 251 252 fDocument = document; 253 fConfiguration = config; 254 255 fSymbolTable = (SymbolTable) fConfiguration.getProperty(DOMConfigurationImpl.SYMBOL_TABLE); 258 fNamespaceContext.reset(); 260 fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); 261 docTypeFound = false; 262 if ((fConfiguration.features & DOMConfigurationImpl.VALIDATE) != 0) { 263 String type =(String ) fConfiguration.getProperty(fConfiguration.JAXP_SCHEMA_LANGUAGE); 264 if(type != null && type.equals(Constants.NS_XMLSCHEMA)) 265 fValidationHandler = CoreDOMImplementationImpl.singleton.getValidator(XMLGrammarDescription.XML_SCHEMA); 266 fConfiguration.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, true); 267 fConfiguration.setFeature(DOMConfigurationImpl.SCHEMA, true); 268 fNamespaceValidation = true; 270 271 fPSVI = ((fConfiguration.features & DOMConfigurationImpl.PSVI) !=0)?true:false; 273 274 fDocument.clearIdentifiers(); 276 277 if(fValidationHandler!=null) 279 ((XMLComponent) fValidationHandler).reset(fConfiguration); 280 281 } 282 283 fErrorHandler = (DOMErrorHandler ) fConfiguration.getParameter(Constants.DOM_ERROR_HANDLER); 284 if (fValidationHandler != null) { 285 fValidationHandler.setDocumentHandler(this); 286 fValidationHandler.startDocument( new SimpleLocator(fDocument.fDocumentURI, fDocument.fDocumentURI, -1, -1 ), fDocument.encoding, fNamespaceContext, null); 287 288 } 289 try { 290 Node kid, next; 291 for (kid = fDocument.getFirstChild(); kid != null; kid = next) { 292 next = kid.getNextSibling(); 293 kid = normalizeNode(kid); 294 if (kid != null) { next = kid; 296 } 297 } 298 299 if (fValidationHandler != null) { 301 fValidationHandler.endDocument(null); 302 CoreDOMImplementationImpl.singleton.releaseValidator( 303 XMLGrammarDescription.XML_SCHEMA, fValidationHandler); 304 fValidationHandler = null; 305 } 306 } 307 catch (RuntimeException e) { 308 if(DEBUG_ND) e.printStackTrace(); 309 if( e==abort ) 310 return; throw e; } 313 314 } 315 316 317 332 protected Node normalizeNode(Node node){ 333 334 int type = node.getNodeType(); 335 boolean wellformed; 336 fLocator.fRelatedNode=node; 337 338 switch (type) { 339 case Node.DOCUMENT_TYPE_NODE: { 340 if (DEBUG_ND) { 341 System.out.println("==>normalizeNode:{doctype}"); 342 } 343 fDTDValidator =(XMLDTDValidator) CoreDOMImplementationImpl.singleton.getDTDValidator(); 344 DocumentTypeImpl docNode = (DocumentTypeImpl)node; 345 if(fDTDValidator != null){ 346 fConfiguration.setFeature(DOMConfigurationImpl.XERCES_VALIDATION, false); 348 349 fDTDValidator.startDocument( new SimpleLocator(fDocument.fDocumentURI, fDocument.fDocumentURI, -1, -1 ), fDocument.encoding, fNamespaceContext, null); 350 351 352 if (DEBUG_ND) 353 System.out.println("Internal subset is "+docNode.getInternalSubset()); 354 XMLGrammarPoolImpl grammarPool = getGrammarPool(docNode.getSystemId(),docNode.getInternalSubset()); 355 fConfiguration.setProperty(GRAMMAR_POOL, grammarPool); 356 fDTDValidator.setDocumentHandler(this); 357 ((XMLComponent) fDTDValidator).reset(fConfiguration); 358 fDTDValidator.doctypeDecl(docNode.getName(),docNode.getPublicId(),docNode.getSystemId(),null); 359 docTypeFound = true; 360 } 361 break; 363 } 364 365 case Node.ELEMENT_NODE: { 366 if (DEBUG_ND) { 367 System.out.println("==>normalizeNode:{element} "+node.getNodeName()); 368 } 369 370 if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && 373 fDocument.isXMLVersionChanged()){ 374 if(fNamespaceValidation){ 375 wellformed = CoreDocumentImpl.isValidQName(node.getPrefix() , node.getLocalName(), fDocument.isXML11Version()) ; 376 } 377 else{ 378 wellformed = CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); 379 } 380 if (!wellformed){ 381 String msg = DOMMessageFormatter.formatMessage( 382 DOMMessageFormatter.DOM_DOMAIN, 383 "wf-invalid-character-in-node-name", 384 new Object []{"Element", node.getNodeName()}); 385 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 386 "wf-invalid-character-in-node-name"); 387 } 388 } 389 fNamespaceContext.pushContext(); 391 fLocalNSBinder.reset(); 392 393 ElementImpl elem = (ElementImpl)node; 394 if (elem.needsSyncChildren()) { 395 elem.synchronizeChildren(); 396 } 397 AttributeMap attributes = (elem.hasAttributes()) ? (AttributeMap) elem.getAttributes() : null; 398 399 if ((fConfiguration.features & DOMConfigurationImpl.NAMESPACES) !=0) { 401 namespaceFixUp(elem, attributes); 405 } else { 406 if ( attributes!=null ) { 407 for ( int i=0; i<attributes.getLength(); ++i ) { 408 Attr attr = (Attr )attributes.item(i); 409 attr.normalize(); 411 if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ 412 isAttrValueWF(fErrorHandler, fError, fLocator, attributes, (AttrImpl)attr, attr.getValue(), fDocument.isXML11Version()); 413 if (fDocument.isXMLVersionChanged()){ 414 wellformed=CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); 415 if (!wellformed){ 416 String msg = DOMMessageFormatter.formatMessage( 417 DOMMessageFormatter.DOM_DOMAIN, 418 "wf-invalid-character-in-node-name", 419 new Object []{"Attr",node.getNodeName()}); 420 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 421 "wf-invalid-character-in-node-name"); 422 } 423 } 424 } 425 } 426 } 427 } 428 429 430 if (fValidationHandler != null) { 431 fAttrProxy.setAttributes(attributes, fDocument, elem); 435 updateQName(elem, fQName); fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 439 fCurrentNode = node; 440 fValidationHandler.startElement(fQName, fAttrProxy, null); 442 } 443 444 if(fDTDValidator != null){ 445 if(attributes!=null) 446 fAttrProxy.setAttributes(attributes, fDocument, elem); 447 updateQName(elem, fQName); fCurrentNode = node; 449 fDTDValidator.startElement(fQName, fAttrProxy, null); 450 } 451 452 Node kid, next; 454 for (kid = elem.getFirstChild(); kid != null; kid = next) { 455 next = kid.getNextSibling(); 456 kid = normalizeNode(kid); 457 if (kid !=null) { 458 next = kid; } 460 } 461 if (DEBUG_ND) { 462 System.out.println("***The children of {"+node.getNodeName()+"} are normalized"); 464 for (kid = elem.getFirstChild(); kid != null; kid = next) { 465 next = kid.getNextSibling(); 466 System.out.println(kid.getNodeName() +"["+kid.getNodeValue()+"]"); 467 } 468 469 } 470 471 472 if (fValidationHandler != null) { 473 updateQName(elem, fQName); fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 478 fCurrentNode = node; 479 fValidationHandler.endElement(fQName, null); 480 } 481 if(fDTDValidator != null ){ 482 updateQName(elem, fQName); fCurrentNode = node; 484 fDTDValidator.endElement(fQName,null); 485 } 486 487 fNamespaceContext.popContext(); 489 490 break; 491 } 492 493 case Node.COMMENT_NODE: { 494 if (DEBUG_ND) { 495 System.out.println("==>normalizeNode:{comments}"); 496 } 497 498 if ((fConfiguration.features & DOMConfigurationImpl.COMMENTS) == 0) { 499 Node prevSibling = node.getPreviousSibling(); 500 Node parent = node.getParentNode(); 501 parent.removeChild(node); 503 if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE) { 504 Node nextSibling = prevSibling.getNextSibling(); 505 if (nextSibling != null && nextSibling.getNodeType() == Node.TEXT_NODE) { 506 ((TextImpl)nextSibling).insertData(0, prevSibling.getNodeValue()); 507 parent.removeChild(prevSibling); 508 return nextSibling; 509 } 510 } 511 } else { 513 if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ 514 String commentdata = ((Comment )node).getData(); 515 isCommentWF(fErrorHandler, fError, fLocator, commentdata, fDocument.isXML11Version()); 518 } 519 } break; 521 } 522 case Node.ENTITY_REFERENCE_NODE: { 523 if (DEBUG_ND) { 524 System.out.println("==>normalizeNode:{entityRef} "+node.getNodeName()); 525 } 526 527 if ((fConfiguration.features & DOMConfigurationImpl.ENTITIES) == 0) { 528 Node prevSibling = node.getPreviousSibling(); 529 Node parent = node.getParentNode(); 530 ((EntityReferenceImpl)node).setReadOnly(false, true); 531 expandEntityRef(parent, node); 532 parent.removeChild(node); 533 Node next = (prevSibling != null)?prevSibling.getNextSibling():parent.getFirstChild(); 534 if (prevSibling != null && next != null && prevSibling.getNodeType() == Node.TEXT_NODE && next.getNodeType() == Node.TEXT_NODE) { 538 return prevSibling; } 540 return next; 541 } else { 542 if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && 543 fDocument.isXMLVersionChanged()){ 544 CoreDocumentImpl.isXMLName(node.getNodeName() , fDocument.isXML11Version()); 545 } 546 } 549 break; 550 } 551 552 case Node.CDATA_SECTION_NODE: { 553 if (DEBUG_ND) { 554 System.out.println("==>normalizeNode:{cdata}"); 555 } 556 557 if ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) { 558 Node prevSibling = node.getPreviousSibling(); 560 if (prevSibling != null && prevSibling.getNodeType() == Node.TEXT_NODE){ 561 ((Text )prevSibling).appendData(node.getNodeValue()); 562 node.getParentNode().removeChild(node); 563 return prevSibling; } 565 else { 566 Text text = fDocument.createTextNode(node.getNodeValue()); 567 Node parent = node.getParentNode(); 568 node = parent.replaceChild(text, node); 569 return text; 571 } 572 } 573 574 if (fValidationHandler != null) { 576 fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 579 fCurrentNode = node; 580 fValidationHandler.startCDATA(null); 581 fValidationHandler.characterData(node.getNodeValue(),null); 582 583 fValidationHandler.endCDATA(null); 584 } 585 586 if(fDTDValidator != null){ 587 fCurrentNode = node; 588 fDTDValidator.startCDATA(null); 589 String st = node.getNodeValue(); 590 XMLString str = new XMLString(); 591 if(st!=null) 592 str.setValues(st.toCharArray(),0,st.length()); 593 fDTDValidator.characters(str, null); 594 fDTDValidator.endCDATA(null); 595 } 596 597 String value = node.getNodeValue(); 598 599 if ((fConfiguration.features & DOMConfigurationImpl.SPLITCDATA) != 0) { 600 int index; 601 Node parent = node.getParentNode(); 602 603 isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version()); 604 while ( (index=value.indexOf("]]>")) >= 0 ) { 605 node.setNodeValue(value.substring(0, index+2)); 606 value = value.substring(index +2); 607 608 Node firstSplitNode = node; 609 Node newChild = fDocument.createCDATASection(value); 610 parent.insertBefore(newChild, node.getNextSibling()); 611 node = newChild; 612 fLocator.fRelatedNode = firstSplitNode; 614 String msg = DOMMessageFormatter.formatMessage( 615 DOMMessageFormatter.DOM_DOMAIN, 616 "cdata-sections-splitted", 617 null); 618 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_WARNING, 619 "cdata-sections-splitted"); 620 } 621 622 } 623 else { 624 isCDataWF(fErrorHandler, fError, fLocator, value, fDocument.isXML11Version()); 626 } 627 break; 628 } 629 630 case Node.TEXT_NODE: { 631 if (DEBUG_ND) { 632 System.out.println("==>normalizeNode(text):{"+node.getNodeValue()+"}"); 633 } 634 Node next = node.getNextSibling(); 640 if ( next!=null && next.getNodeType() == Node.TEXT_NODE ) { 642 ((Text )node).appendData(next.getNodeValue()); 643 node.getParentNode().removeChild( next ); 644 647 return node; } else if (node.getNodeValue().length()==0) { 649 node.getParentNode().removeChild( node ); 651 } else { 652 658 short nextType = (next != null)?next.getNodeType():-1; 659 if (nextType == -1 || !(((fConfiguration.features & DOMConfigurationImpl.ENTITIES) == 0 && 660 nextType == Node.ENTITY_NODE) || 661 ((fConfiguration.features & DOMConfigurationImpl.COMMENTS) == 0 && 662 nextType == Node.COMMENT_NODE) || 663 ((fConfiguration.features & DOMConfigurationImpl.CDATA) == 0) && 664 nextType == Node.CDATA_SECTION_NODE)) { 665 if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) ){ 666 isXMLCharWF(fErrorHandler, fError, fLocator, node.getNodeValue(), fDocument.isXML11Version()); 667 } 668 if (fValidationHandler != null) { 669 fConfiguration.fErrorHandlerWrapper.fCurrentNode = node; 670 fCurrentNode = node; 671 fValidationHandler.characterData(node.getNodeValue(), null); 672 if (DEBUG_ND) { 673 System.out.println("=====>characterData(),"+nextType); 674 675 } 676 } 677 678 if(fDTDValidator != null){ 679 fCurrentNode = node; 680 String st = node.getNodeValue(); 681 XMLString str = new XMLString(); 682 if(st!=null) 683 str.setValues(st.toCharArray(),0,st.length()); 684 fDTDValidator.characters(str, null); 685 if(isWhitespace) 686 ((TextImpl)node).setIgnorableWhitespace(true); 687 } 688 } 689 else { 690 if (DEBUG_ND) { 691 System.out.println("=====>don't send characters(),"+nextType); 692 693 } 694 } 695 } 696 break; 697 } 698 case Node.PROCESSING_INSTRUCTION_NODE: { 699 700 if((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0 ){ 702 ProcessingInstruction pinode = (ProcessingInstruction )node ; 703 704 String target = pinode.getTarget(); 705 if(fDocument.isXML11Version()){ 707 wellformed = XML11Char.isXML11ValidName(target); 708 } 709 else{ 710 wellformed = XMLChar.isValidName(target); 711 } 712 713 if (!wellformed) { 714 String msg = DOMMessageFormatter.formatMessage( 715 DOMMessageFormatter.DOM_DOMAIN, 716 "wf-invalid-character-in-node-name", 717 new Object []{"Element", node.getNodeName()}); 718 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 719 "wf-invalid-character-in-node-name"); 720 } 721 722 isXMLCharWF(fErrorHandler, fError, fLocator, pinode.getData(), fDocument.isXML11Version()); 726 } 727 } 729 } return null; 731 } 733 protected final void expandEntityRef(Node parent, Node reference){ 734 Node kid, next; 735 for (kid = reference.getFirstChild(); kid != null; kid = next) { 736 next = kid.getNextSibling(); 737 parent.insertBefore(kid, reference); 738 } 739 } 740 741 746 protected final void namespaceFixUp(ElementImpl element, AttributeMap attributes){ 747 if (DEBUG) { 748 System.out.println("[ns-fixup] element:" +element.getNodeName()+ 749 " uri: "+element.getNamespaceURI()); 750 } 751 752 762 String value, name, uri, prefix; 763 if (attributes != null) { 764 765 for (int k=0; k < attributes.getLength(); k++) { 767 Attr attr = (Attr )attributes.getItem(k); 768 769 if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0) && 772 fDocument.isXMLVersionChanged()){ 773 fDocument.checkQName(attr.getPrefix() , attr.getLocalName()) ; 775 } 776 777 uri = attr.getNamespaceURI(); 778 if (uri != null && uri.equals(NamespaceContext.XMLNS_URI)) { 779 value = attr.getNodeValue(); 781 if (value == null) { 782 value=XMLSymbols.EMPTY_STRING; 783 } 784 785 if (value.equals(NamespaceContext.XMLNS_URI)) { 787 fLocator.fRelatedNode = attr; 790 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,"CantBindXMLNS",null ); 791 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, "CantBindXMLNS"); 792 } else { 793 prefix = attr.getPrefix(); 796 prefix = (prefix == null || 797 prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); 798 String localpart = fSymbolTable.addSymbol( attr.getLocalName()); 799 if (prefix == XMLSymbols.PREFIX_XMLNS) { 801 value = fSymbolTable.addSymbol(value); 802 if (value.length() != 0) { 803 fNamespaceContext.declarePrefix(localpart, value); 804 } else { 805 808 } 809 continue; 811 } else { value = fSymbolTable.addSymbol(value); 814 fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, value); 815 continue; 817 } 818 } } } 821 } 822 823 824 825 840 uri = element.getNamespaceURI(); 841 prefix = element.getPrefix(); 842 if (uri != null) { uri = fSymbolTable.addSymbol(uri); 844 prefix = (prefix == null || 845 prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); 846 if (fNamespaceContext.getURI(prefix) == uri) { 847 } else { 850 addNamespaceDecl(prefix, uri, element); 854 fLocalNSBinder.declarePrefix(prefix, uri); 855 fNamespaceContext.declarePrefix(prefix, uri); 856 } 857 } else { if (element.getLocalName() == null) { 859 if (fNamespaceValidation) { 861 String msg = DOMMessageFormatter.formatMessage( 862 DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", 863 new Object []{element.getNodeName()}); 864 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR, 865 "NullLocalElementName"); 866 } else { 867 String msg = DOMMessageFormatter.formatMessage( 868 DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName", 869 new Object []{element.getNodeName()}); 870 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 871 "NullLocalElementName"); 872 } 873 } else { uri = fNamespaceContext.getURI(XMLSymbols.EMPTY_STRING); 875 if (uri !=null && uri.length() > 0) { 876 addNamespaceDecl(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING, element); 879 fLocalNSBinder.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); 880 fNamespaceContext.declarePrefix(XMLSymbols.EMPTY_STRING, XMLSymbols.EMPTY_STRING); 881 } 882 } 883 } 884 885 if (attributes != null) { 890 891 attributes.cloneMap(fAttributeList); 893 for (int i = 0; i < fAttributeList.size(); i++) { 894 Attr attr = (Attr ) fAttributeList.elementAt(i); 895 fLocator.fRelatedNode = attr; 896 897 if (DEBUG) { 898 System.out.println("==>[ns-fixup] process attribute: "+attr.getNodeName()); 899 } 900 attr.normalize(); 902 value = attr.getValue(); 903 name = attr.getNodeName(); 904 uri = attr.getNamespaceURI(); 905 906 if (value == null) { 908 value=XMLSymbols.EMPTY_STRING; 909 } 910 911 if (uri != null) { prefix = attr.getPrefix(); 913 prefix = (prefix == null || 914 prefix.length() == 0) ? XMLSymbols.EMPTY_STRING :fSymbolTable.addSymbol(prefix); 915 fSymbolTable.addSymbol( attr.getLocalName()); 916 917 if (uri != null && uri.equals(NamespaceContext.XMLNS_URI)) { 923 continue; 924 } 925 if ( ((fConfiguration.features & DOMConfigurationImpl.WELLFORMED) != 0)){ 929 isAttrValueWF(fErrorHandler, fError, fLocator, attributes, (AttrImpl)attr, attr.getValue(), fDocument.isXML11Version()); 930 if (fDocument.isXMLVersionChanged()){ 931 boolean wellformed=CoreDocumentImpl.isXMLName(attr.getNodeName() , fDocument.isXML11Version()); 932 if (!wellformed){ 933 String msg = DOMMessageFormatter.formatMessage( 934 DOMMessageFormatter.DOM_DOMAIN, 935 "wf-invalid-character-in-node-name", 936 new Object []{"Attribute", attr.getNodeName()}); 937 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character-in-node-name"); 938 } 939 } 940 } 941 942 950 953 ((AttrImpl)attr).setIdAttribute(false); 955 956 957 uri = fSymbolTable.addSymbol(uri); 958 959 String declaredURI = fNamespaceContext.getURI(prefix); 961 962 if (prefix == XMLSymbols.EMPTY_STRING || declaredURI != uri) { 963 970 name = attr.getNodeName(); 971 String declaredPrefix = fNamespaceContext.getPrefix(uri); 974 if (declaredPrefix !=null && declaredPrefix !=XMLSymbols.EMPTY_STRING) { 975 976 prefix = declaredPrefix; 978 } else { 979 if (prefix != XMLSymbols.EMPTY_STRING && fLocalNSBinder.getURI(prefix) == null) { 980 982 } else { 984 985 int counter = 1; 988 prefix = fSymbolTable.addSymbol(PREFIX +counter++); 989 while (fLocalNSBinder.getURI(prefix)!=null) { 990 prefix = fSymbolTable.addSymbol(PREFIX +counter++); 991 } 992 993 } 994 addNamespaceDecl(prefix, uri, element); 996 value = fSymbolTable.addSymbol(value); 997 fLocalNSBinder.declarePrefix(prefix, value); 998 fNamespaceContext.declarePrefix(prefix, uri); 999 } 1000 1001 attr.setPrefix(prefix); 1003 } 1004 } else { 1006 1009 ((AttrImpl)attr).setIdAttribute(false); 1011 1012 if (attr.getLocalName() == null) { 1013 if (fNamespaceValidation) { 1015 String msg = DOMMessageFormatter.formatMessage( 1016 DOMMessageFormatter.DOM_DOMAIN, 1017 "NullLocalAttrName", new Object []{attr.getNodeName()}); 1018 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR, "NullLocalAttrName"); 1019 } else { 1020 String msg = DOMMessageFormatter.formatMessage( 1021 DOMMessageFormatter.DOM_DOMAIN, 1022 "NullLocalAttrName", new Object []{attr.getNodeName()}); 1023 reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR, 1024 "NullLocalAttrName"); 1025 } 1026 } else { 1027 1030 } 1035 } 1036 } 1037 } } 1039 1040 1049 1050 protected final void addNamespaceDecl(String prefix, String uri, ElementImpl element){ 1051 if (DEBUG) { 1052 System.out.println("[ns-fixup] addNamespaceDecl ["+prefix+"]"); 1053 } 1054 if (prefix == XMLSymbols.EMPTY_STRING) { 1055 if (DEBUG) { 1056 System.out.println("=>add xmlns=\""+uri+"\" declaration"); 1057 } 1058 element.setAttributeNS(NamespaceContext.XMLNS_URI, XMLSymbols.PREFIX_XMLNS, uri); 1059 } else { 1060 if (DEBUG) { 1061 System.out.println("=>add xmlns:"+prefix+"=\""+uri+"\" declaration"); 1062 } 1063 element.setAttributeNS(NamespaceContext.XMLNS_URI, "xmlns:"+prefix, uri); 1064 } 1065 } 1066 1067 1068 1072 1073 1078 public static final void isCDataWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator, 1079 String datavalue, boolean isXML11Version) { 1080 if(datavalue == null || (datavalue.length() == 0) ) return ; 1081 1082 char [] dataarray = datavalue.toCharArray(); 1083 int datalength = dataarray.length ; 1084 1085 if(isXML11Version){ 1087 int i = 0 ; 1089 while(i < datalength){ 1090 char c = dataarray[i++]; 1091 if(XML11Char.isXML11Invalid(c)){ 1092 String msg = 1093 DOMMessageFormatter.formatMessage( 1094 DOMMessageFormatter.XML_DOMAIN, 1095 "InvalidCharInCDSect", 1096 new Object [] { Integer.toString(c, 16)}); 1097 reportDOMError( 1098 errorHandler, 1099 error, 1100 locator, 1101 msg, 1102 DOMError.SEVERITY_ERROR, 1103 "wf-invalid-character"); 1104 } 1105 else if (c==']'){ 1106 int count = i; 1107 if (count<datalength && dataarray[count]==']'){ 1108 while (++count <datalength && dataarray[count]==']'){ 1109 } 1111 if (count <datalength && dataarray[count]=='>'){ 1112 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1114 "CDEndInContent", null); 1115 reportDOMError(errorHandler, error, locator,msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1116 } 1117 } 1118 1119 } 1120 } 1121 } else{ 1123 int i = 0 ; 1125 while(i < datalength){ 1126 char c = dataarray[i++]; 1127 if( XMLChar.isInvalid(c) ){ 1128 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, "InvalidCharInCDSect", new Object []{Integer.toString(c, 16)}); 1133 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, 1134 "wf-invalid-character"); 1135 } 1136 else if (c==']'){ 1137 int count = i; 1138 if (count<datalength && dataarray[count]==']'){ 1139 while (++count <datalength && dataarray[count]==']'){ 1140 } 1142 if (count <datalength && dataarray[count]=='>'){ 1143 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,"CDEndInContent", null); 1144 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1145 } 1146 } 1147 1148 } 1149 } 1150 } 1152 } 1154 1159 public static final void isXMLCharWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator, 1160 String datavalue, boolean isXML11Version) { 1161 if(datavalue == null || (datavalue.length() == 0) ) return ; 1162 char [] dataarray = datavalue.toCharArray(); 1163 int datalength = dataarray.length ; 1164 1165 if(isXML11Version){ 1167 int i = 0 ; 1169 while(i < datalength){ 1170 if(XML11Char.isXML11Invalid(dataarray[i++])){ 1171 String msg = DOMMessageFormatter.formatMessage( 1172 DOMMessageFormatter.DOM_DOMAIN, "InvalidXMLCharInDOM", 1173 new Object []{Integer.toString(dataarray[i-1], 16)}); 1174 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, 1175 "wf-invalid-character"); 1176 }; 1177 } 1178 } else{ 1180 int i = 0 ; 1182 while(i < datalength){ 1183 if( XMLChar.isInvalid(dataarray[i++]) ){ 1184 String msg = DOMMessageFormatter.formatMessage( 1185 DOMMessageFormatter.DOM_DOMAIN, "InvalidXMLCharInDOM", 1186 new Object []{Integer.toString(dataarray[i-1], 16)}); 1187 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, 1188 "wf-invalid-character"); 1189 }; 1190 } 1191 } 1193 } 1195 1200 public static final void isCommentWF(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator, 1201 String datavalue, boolean isXML11Version) { 1202 if(datavalue == null || (datavalue.length() == 0) ) return ; 1203 1204 char [] dataarray = datavalue.toCharArray(); 1205 int datalength = dataarray.length ; 1206 1207 if(isXML11Version){ 1209 int i = 0 ; 1211 while(i < datalength){ 1212 char c = dataarray[i++]; 1213 1214 if(XML11Char.isXML11Invalid(c)){ 1215 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1216 "InvalidCharInComment", 1217 new Object [] {Integer.toString(dataarray[i-1], 16)}); 1218 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1219 } 1220 else if (c == '-' && i<datalength && dataarray[i]=='-'){ 1221 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1222 "DashDashInComment", null); 1223 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1225 } 1226 } 1227 } else{ 1229 int i = 0 ; 1231 while(i < datalength){ 1232 char c = dataarray[i++]; 1233 if( XMLChar.isInvalid(c) ){ 1234 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1235 "InvalidCharInComment", new Object [] {Integer.toString(dataarray[i-1], 16)}); 1236 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1237 } 1238 else if (c == '-' && i<datalength && dataarray[i]=='-'){ 1239 String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN, 1240 "DashDashInComment", null); 1241 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character"); 1243 } 1244 } 1245 1246 } 1248 } 1250 1255 public static final void isAttrValueWF(DOMErrorHandler errorHandler, DOMErrorImpl error, 1256 DOMLocatorImpl locator, AttributeMap attributes, AttrImpl a, String value, boolean xml11Version) { 1257 if (a.hasStringValue()) { 1258 isXMLCharWF(errorHandler, error, locator, value, xml11Version); 1259 } else { 1260 NodeList children = a.getChildNodes(); 1261 for (int j = 0; j < children.getLength(); j++) { 1263 Node child = children.item(j); 1264 if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) { 1266 Document owner = a.getOwnerDocument(); 1267 Entity ent = null; 1268 if (owner != null) { 1271 DocumentType docType = owner.getDoctype(); 1272 if (docType != null) { 1273 NamedNodeMap entities = docType.getEntities(); 1274 ent = (Entity ) entities.getNamedItemNS( 1275 "*", 1276 child.getNodeName()); 1277 } 1278 } 1279 if (ent == null) { 1281 String msg = DOMMessageFormatter.formatMessage( 1282 DOMMessageFormatter.DOM_DOMAIN, "UndeclaredEntRefInAttrValue", 1283 new Object []{a.getNodeName()}); 1284 reportDOMError(errorHandler, error, locator, msg, DOMError.SEVERITY_ERROR, 1285 "UndeclaredEntRefInAttrValue"); 1286 } 1287 } 1288 else { 1289 isXMLCharWF(errorHandler, error, locator, child.getNodeValue(), xml11Version); 1291 } 1292 } 1293 } 1294 } 1295 1296 1297 1298 1303 public static final void reportDOMError(DOMErrorHandler errorHandler, DOMErrorImpl error, DOMLocatorImpl locator, String message, short severity, String type ) { 1304 if( errorHandler!=null ) { 1305 error.reset(); 1306 error.fMessage = message; 1307 error.fSeverity = severity; 1308 error.fLocator = locator; 1309 error.fType = type; 1310 error.fRelatedData = locator.fRelatedNode; 1311 1312 if(!errorHandler.handleError(error)) 1313 throw abort; 1314 } 1315 if( severity==DOMError.SEVERITY_FATAL_ERROR ) 1316 throw abort; 1317 } 1318 1319 protected final void updateQName(Node node, QName qname){ 1320 1321 String prefix = node.getPrefix(); 1322 String namespace = node.getNamespaceURI(); 1323 String localName = node.getLocalName(); 1324 qname.prefix = (prefix!=null && prefix.length()!=0)?fSymbolTable.addSymbol(prefix):null; 1327 qname.localpart = (localName != null)?fSymbolTable.addSymbol(localName):null; 1328 qname.rawname = fSymbolTable.addSymbol(node.getNodeName()); 1329 qname.uri = (namespace != null)?fSymbolTable.addSymbol(namespace):null; 1330 } 1331 1332 1333 1334 1352 final String normalizeAttributeValue(String value, Attr attr) { 1353 if (!attr.getSpecified()){ 1354 return value; 1357 } 1358 int end = value.length(); 1359 if (fNormalizedValue.ch.length < end) { 1361 fNormalizedValue.ch = new char[end]; 1362 } 1363 fNormalizedValue.length = 0; 1364 boolean normalized = false; 1365 for (int i = 0; i < end; i++) { 1366 char c = value.charAt(i); 1367 if (c==0x0009 || c==0x000A) { 1368 fNormalizedValue.ch[fNormalizedValue.length++] = ' '; 1369 normalized = true; 1370 } 1371 else if(c==0x000D){ 1372 normalized = true; 1373 fNormalizedValue.ch[fNormalizedValue.length++] = ' '; 1374 int next = i+1; 1375 if (next < end && value.charAt(next)==0x000A) i=next; } 1377 else { 1378 fNormalizedValue.ch[fNormalizedValue.length++] = c; 1379 } 1380 } 1381 if (normalized){ 1382 value = fNormalizedValue.toString(); 1383 attr.setValue(value); 1384 } 1385 return value; 1386 } 1387 1388 protected final class XMLAttributesProxy 1389 implements XMLAttributes { 1390 protected AttributeMap fAttributes; 1391 protected CoreDocumentImpl fDocument; 1392 protected ElementImpl fElement; 1393 1394 protected final Vector fAugmentations = new Vector (5); 1395 1396 1397 public void setAttributes(AttributeMap attributes, CoreDocumentImpl doc, ElementImpl elem) { 1398 fDocument = doc; 1399 fAttributes = attributes; 1400 fElement = elem; 1401 if (attributes != null) { 1402 int length = attributes.getLength(); 1403 1404 fAugmentations.setSize(length); 1405 for (int i = 0; i < length; i++) { 1409 fAugmentations.setElementAt(new AugmentationsImpl(), i); 1410 } 1411 } else { 1412 fAugmentations.setSize(0); 1413 } 1414 } 1415 1416 1417 1421 public int addAttribute(QName qname, String attrType, String attrValue) { 1422 int index = fElement.getXercesAttribute(qname.uri, qname.localpart); 1423 if (index < 0) { 1425 AttrImpl attr = (AttrImpl) 1428 ((CoreDocumentImpl) fElement.getOwnerDocument()).createAttributeNS( 1429 qname.uri, 1430 qname.rawname, 1431 qname.localpart); 1432 index = fElement.setXercesAttributeNode(attr); 1434 attr.setNodeValue(attrValue); 1435 fAugmentations.insertElementAt(new AugmentationsImpl(), index); 1436 attr.setSpecified(false); 1437 } 1438 else { 1439 1445 } 1446 return index; 1447 } 1448 1449 1450 public void removeAllAttributes(){ 1451 } 1453 1454 1455 public void removeAttributeAt(int attrIndex){ 1456 } 1458 1459 1460 public int getLength(){ 1461 return(fAttributes != null)?fAttributes.getLength():0; 1462 } 1463 1464 1465 public int getIndex(String qName){ 1466 return -1; 1468 } 1469 1470 public int getIndex(String uri, String localPart){ 1471 return -1; 1473 } 1474 1475 public void setName(int attrIndex, QName attrName){ 1476 } 1478 1479 public void getName(int attrIndex, QName attrName){ 1480 if (fAttributes !=null) { 1481 updateQName((Node )fAttributes.getItem(attrIndex), attrName); 1482 } 1483 } 1484 1485 public String getPrefix(int index){ 1486 return null; 1488 } 1489 1490 1491 public String getURI(int index){ 1492 return null; 1494 } 1495 1496 1497 public String getLocalName(int index){ 1498 Object ob = fAttributes.item(index); 1499 if( ob instanceof AttrNSImpl) 1500 return ((AttrNSImpl)ob).getLocalName(); 1501 else 1502 return ((AttrImpl)ob).getNodeName(); 1503 } 1504 1505 1506 public String getQName(int index){ 1507 return fAttributes.item(index).getNodeName(); 1508 } 1509 1510 1511 public void setType(int attrIndex, String attrType){ 1512 } 1514 1515 1516 public String getType(int index){ 1517 return "CDATA"; 1518 } 1519 1520 1521 public String getType(String qName){ 1522 return "CDATA"; 1523 } 1524 1525 1526 public String getType(String uri, String localName){ 1527 return "CDATA"; 1528 } 1529 1530 1531 public void setValue(int attrIndex, String attrValue){ 1532 1536 if (fAttributes != null){ 1537 AttrImpl attr = (AttrImpl)fAttributes.getItem(attrIndex); 1538 boolean specified = attr.getSpecified(); 1539 attr.setValue(attrValue); 1540 attr.setSpecified(specified); 1541 1542 } 1543 } 1544 1545 1546 public String getValue(int index){ 1547 return (fAttributes !=null)?fAttributes.item(index).getNodeValue():""; 1548 1549 } 1550 1551 1552 public String getValue(String qName){ 1553 return null; 1555 } 1556 1557 1558 public String getValue(String uri, String localName){ 1559 if (fAttributes != null) { 1560 Node node = fAttributes.getNamedItemNS(uri, localName); 1561 return(node != null)? node.getNodeValue():null; 1562 } 1563 return null; 1564 } 1565 1566 1567 public void setNonNormalizedValue(int attrIndex, String attrValue){ 1568 1570 } 1571 1572 1573 public String getNonNormalizedValue(int attrIndex){ 1574 return null; 1576 } 1577 1578 1579 public void setSpecified(int attrIndex, boolean specified){ 1580 AttrImpl attr = (AttrImpl)fAttributes.getItem(attrIndex); 1581 attr.setSpecified(specified); 1582 } 1583 1584 public boolean isSpecified(int attrIndex){ 1585 return((Attr )fAttributes.getItem(attrIndex)).getSpecified(); 1586 } 1587 1588 public Augmentations getAugmentations(int attributeIndex){ 1589 return(Augmentations)fAugmentations.elementAt(attributeIndex); 1590 } 1591 1592 public Augmentations getAugmentations(String uri, String localPart){ 1593 return null; 1595 } 1596 1597 public Augmentations getAugmentations(String qName){ 1598 return null; 1600 } 1601 1602 1608 public void setAugmentations(int attrIndex, Augmentations augs) { 1609 fAugmentations.setElementAt(augs, attrIndex); 1610 } 1611 } 1612 1613 1617 1644 public void startDocument(XMLLocator locator, String encoding, 1645 NamespaceContext namespaceContext, 1646 Augmentations augs) 1647 throws XNIException{ 1648 } 1649 1650 1664 public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) 1665 throws XNIException{ 1666 } 1667 1668 1682 public void doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs) 1683 throws XNIException{ 1684 } 1685 1686 1695 public void comment(XMLString text, Augmentations augs) throws XNIException{ 1696 } 1697 1698 1716 public void processingInstruction(String target, XMLString data, Augmentations augs) 1717 throws XNIException{ 1718 } 1719 1720 1730 public void startElement(QName element, XMLAttributes attributes, Augmentations augs) 1731 throws XNIException { 1732 Element currentElement = (Element ) fCurrentNode; 1733 int attrCount = attributes.getLength(); 1734 if (DEBUG_EVENTS) { 1735 System.out.println("==>startElement: " +element+ 1736 " attrs.length="+attrCount); 1737 } 1738 1739 for (int i = 0; i < attrCount; i++) { 1740 attributes.getName(i, fAttrQName); 1741 Attr attr = null; 1742 1743 attr = currentElement.getAttributeNodeNS(fAttrQName.uri, fAttrQName.localpart); 1744 AttributePSVI attrPSVI = 1745 (AttributePSVI) attributes.getAugmentations(i).getItem(Constants.ATTRIBUTE_PSVI); 1746 1747 if (attrPSVI != null) { 1748 XSTypeDefinition decl = attrPSVI.getMemberTypeDefinition(); 1751 boolean id = false; 1752 if (decl != null){ 1753 id = ((XSSimpleType)decl).isIDType(); 1754 } else{ 1755 decl = attrPSVI.getTypeDefinition(); 1756 if (decl !=null){ 1757 id = ((XSSimpleType)decl).isIDType(); 1758 } 1759 } 1760 if (id){ 1761 ((ElementImpl)currentElement).setIdAttributeNode(attr, true); 1762 } 1763 1764 if (fPSVI) { 1765 ((PSVIAttrNSImpl) attr).setPSVI(attrPSVI); 1766 } 1767 if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) { 1768 boolean specified = attr.getSpecified(); 1774 attr.setValue(attrPSVI.getSchemaNormalizedValue()); 1775 if (!specified) { 1776 ((AttrImpl) attr).setSpecified(specified); 1777 } 1778 } 1779 } 1780 } 1781 } 1782 1783 1784 1794 public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) 1795 throws XNIException { 1796 if (DEBUG_EVENTS) { 1797 System.out.println("==>emptyElement: " +element); 1798 } 1799 if(true) 1800 return; 1801 1802 startElement(element, attributes, augs); 1803 endElement(element, augs); 1804 } 1805 1806 1823 public void startGeneralEntity(String name, 1824 XMLResourceIdentifier identifier, 1825 String encoding, 1826 Augmentations augs) throws XNIException{ 1827 } 1828 1829 1847 public void textDecl(String version, String encoding, Augmentations augs) throws XNIException{ 1848 } 1849 1850 1862 public void endGeneralEntity(String name, Augmentations augs) throws XNIException{ 1863 } 1864 1865 1874 public void characters(XMLString text, Augmentations augs) throws XNIException{ 1875 } 1876 1877 1891 public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException{ 1892 if(docTypeFound){ 1893 isWhitespace = true; 1894 } 1895 } 1896 1897 1906 public void endElement(QName element, Augmentations augs) throws XNIException { 1907 if (DEBUG_EVENTS) { 1908 System.out.println("==>endElement: " + element); 1909 } 1910 if(augs == null) 1911 return; 1912 ElementPSVI elementPSVI = (ElementPSVI) augs.getItem(Constants.ELEMENT_PSVI); 1913 if (elementPSVI != null) { 1914 ElementImpl elementNode = (ElementImpl) fCurrentNode; 1915 if (fPSVI) { 1916 ((PSVIElementNSImpl) fCurrentNode).setPSVI(elementPSVI); 1917 } 1918 String normalizedValue = elementPSVI.getSchemaNormalizedValue(); 1920 if ((fConfiguration.features & DOMConfigurationImpl.DTNORMALIZATION) != 0) { 1921 if (normalizedValue !=null) 1922 elementNode.setTextContent(normalizedValue); 1923 } 1924 else { 1925 String text = elementNode.getTextContent(); 1929 if (text.length() == 0) { 1930 if (normalizedValue !=null) 1932 elementNode.setTextContent(normalizedValue); 1933 } 1934 } 1935 } 1936 } 1937 1938 1939 1947 public void startCDATA(Augmentations augs) throws XNIException{ 1948 } 1949 1950 1958 public void endCDATA(Augmentations augs) throws XNIException{ 1959 } 1960 1961 1969 public void endDocument(Augmentations augs) throws XNIException{ 1970 } 1971 1972 1973 1974 public void setDocumentSource(XMLDocumentSource source){ 1975 } 1976 1977 1978 1979 public XMLDocumentSource getDocumentSource(){ 1980 return null; 1981 } 1982 1983 public XMLGrammarPoolImpl getGrammarPool(String systemId, String internalSubset){ 1984 try{ 1985 1986 XMLGrammarPreparser preparser = new XMLGrammarPreparser(fSymbolTable); 1987 XMLGrammarPoolImpl grammarPool = new XMLGrammarPoolImpl(); 1988 preparser.registerPreparser(XMLGrammarDescription.XML_DTD, null); 1989 preparser.setProperty(GRAMMAR_POOL, grammarPool); 1990 preparser.setFeature(NAMESPACES_FEATURE_ID, true); 1991 preparser.setFeature(VALIDATION_FEATURE_ID, true); 1992 1993 Grammar g = null; 1994 1995 if(systemId != null){ 1996 g = preparser.preparseGrammar(XMLGrammarDescription.XML_DTD,new XMLInputSource(null, systemId, null)); 1997 } 1998 1999 if(internalSubset != null && !internalSubset.equals("")){ 2000 XMLInputSource xs = new XMLInputSource(null,systemId,null); 2001 xs.setCharacterStream(new StringReader(internalSubset)); 2002 g = preparser.preparseGrammar(XMLGrammarDescription.XML_DTD,xs); 2003 } 2004 return grammarPool; 2005 }catch(Exception ex){ 2006 if(DEBUG_ND) 2007 ex.printStackTrace(); 2008 } 2009 return null; 2010 } 2011} | Popular Tags |