You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2003/11/17 11:53:07 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom CoreDocumentImpl.java DOMNormalizer.java NodeImpl.java

neeraj      2003/11/17 02:53:07

  Modified:    java/src/org/apache/xerces/dom CoreDocumentImpl.java
                        DOMNormalizer.java NodeImpl.java
  Log:
  Further changes for support of well-formed feature
  
  Revision  Changes    Path
  1.58      +14 -6     xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java
  
  Index: CoreDocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- CoreDocumentImpl.java	14 Nov 2003 11:19:37 -0000	1.57
  +++ CoreDocumentImpl.java	17 Nov 2003 10:53:07 -0000	1.58
  @@ -827,11 +827,12 @@
           if(value.equals("1.0") || value.equals("1.1")){
               //we need to change the flag value only --
               // when the version set is different than already set.
  -            if(!getXmlVersion().equals(version)){
  +            if(!getXmlVersion().equals(value)){
                   xmlVersionChanged = true ;
  -            }
  -            version = value;
  -
  +                //change the normalization value back to false
  +                isNormalized(false);
  +                version = value;
  +            }            
           }
           else{
               //NOT_SUPPORTED_ERR: Raised if the vesion is set to a value that is not supported by
  @@ -841,8 +842,12 @@
               throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
               
           }
  -        if((getXmlVersion()).equals("1.1"))
  +        if((getXmlVersion()).equals("1.1")){
               xml11Version = true;
  +        }
  +        else{
  +            xml11Version = false;
  +        }
       }
       
       /**
  @@ -1070,6 +1075,9 @@
           
           domNormalizer.normalizeDocument(this, fConfiguration);
           isNormalized(true);
  +        //set the XMLversion changed value to false -- once we have finished
  +        //doing normalization
  +        xmlVersionChanged = false ;        
       }
       
       
  
  
  
  1.40      +122 -6    xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java
  
  Index: DOMNormalizer.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- DOMNormalizer.java	15 Nov 2003 00:26:11 -0000	1.39
  +++ DOMNormalizer.java	17 Nov 2003 10:53:07 -0000	1.40
  @@ -89,12 +89,15 @@
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   import org.w3c.dom.Text;
  +import org.w3c.dom.ProcessingInstruction;
  +import org.apache.xerces.util.XML11Char;
  +import org.apache.xerces.util.XMLChar;
   import org.w3c.dom.Document;
   import org.w3c.dom.DocumentType;
   import org.w3c.dom.Entity;
   import org.w3c.dom.NamedNodeMap;
   import org.w3c.dom.NodeList;
  -
  +import org.w3c.dom.Comment;
   /**
    * This class adds implementation for normalizeDocument method.
    * It acts as if the document was going through a save and load cycle, putting
  @@ -479,8 +482,61 @@
                               return nextSibling;
                           }
                       }
  -                }
  -                break;
  +                }//if comment node need not be removed
  +                else {
  +                    //REVISIT: it is possible that bad XML characters
  +                    //enter into DOM when created in memory -- so we should
  +                    //still be doing these checks.
  +                    
  +                    //go ahead only if version didn't change.
  +                    if(!fDocument.isXMLVersionChanged()){
  +                        return null;
  +                    }
  +                    //check comments for invalid xml chracter as per the version
  +                    //of the document
  +                    String commentdata = ((Comment)node).getData();
  +                    char [] commentarray = null ;
  +                    if(commentdata != null && commentdata.length() > 0){
  +                        commentarray = commentdata.toCharArray();
  +                    }
  +                    else{
  +                        return null ;
  +                    }
  +                    if (DEBUG_ND) {
  +                    }
  +                    
  +                    //version of the document is XML 1.1
  +                    if(fDocument.isXML11Version()){
  +                        
  +                        // check  comment data
  +                        //we need to check all chracters as per production rules
  +                        //of XML11
  +                        int i = 0 ;
  +                        while(i < commentarray.length){                            
  +                            if(XML11Char.isXML11Invalid(commentarray[i++])){
  +                                String msg = "Invalid XML Character " + Integer.toString(commentarray[i-1], 16) ;
  +                                //REVISIT: As per DOM it is error but as per XML spec. it is fatal error
  +                                reportDOMError(msg,
  +                                    DOMError.SEVERITY_FATAL_ERROR, node,  "wf-invalid-character");
  +                            };
  +                        }
  +                    }//version of the document is XML 1.0
  +                    else{
  +                        
  +                        // check comment data
  +                        //we need to check all chracters as per production rules
  +                        //of XML 1.0
  +                        int i = 0 ;
  +                        while(i < commentarray.length){                            
  +                            if( XMLChar.isInvalid(commentarray[i++]) ){                                
  +                                String msg = "Invalid XML Character " + Integer.toString(commentarray[i-1], 16) ;
  +                                //REVISIT: As per DOM it is error but as per XML spec. it is fatal error                               
  +                                reportDOMError(msg, 
  +                                    DOMError.SEVERITY_FATAL_ERROR, node,  "wf-invalid-character");
  +                            };
  +                        }            
  +                    }//end-else fDocument.isXMLVersion()
  +                }//end-else if comment node is not to be removed.                                                
               }
           case Node.ENTITY_REFERENCE_NODE: { 
                   if (DEBUG_ND) {
  @@ -618,10 +674,70 @@
                       }
                   }
                   break;
  +            }        
  +        case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE: {
  +            //REVISIT: DOM created in memory may contain invalid            
  +            // xml characters which we should be checking -- so 
  +            //we should also be checking in the case when document
  +            //is created in memory and after that application calls
  +            //normalizeDocument()
  +            if(!fDocument.isXMLVersionChanged()){
  +                break ;
  +            }
  +            //processing isntruction data may have certain characters
  +            //which may not be valid XML character
  +            ProcessingInstruction pinode = (ProcessingInstruction)node ;
  +            
  +            String target = pinode.getTarget();
  +            String pidata = pinode.getData() ;
  +            char [] pidataarray = pidata.toCharArray() ;
  +            if(fDocument.isXML11Version()){
  +                //1. check pi targetname 
  +                if(!XML11Char.isXML11ValidName(target)){
  +                        //REVISIT: As per DOM it is error but as per XML spec. it is fatal error
  +                        reportDOMError("Invalid Character in node name",
  +                            DOMError.SEVERITY_FATAL_ERROR, node,  "wf-invalid-character-in-node-name");                
  +                }
  +                //2. check pi data
  +                //we need to check all chracters as per production rules
  +                //of XML11
  +                int i = 0 ;
  +                while(i < pidataarray.length){
  +                    if(XML11Char.isXML11Invalid(pidataarray[i++])){
  +                        //REVISIT: As per DOM it is error but as per XML spec. it is fatal error
  +                        reportDOMError("Invalid Character",
  +                            DOMError.SEVERITY_FATAL_ERROR, node,  "wf-invalid-character");
  +                    };
  +                }
               }
  -        }
  +            else{
  +                //1. check pi targetname 
  +                if(!XMLChar.isValidName(target)){
  +                        //REVISIT: As per DOM it is error but as per XML spec. it is fatal error
  +                        reportDOMError("Invalid Character in node name",
  +                            DOMError.SEVERITY_FATAL_ERROR, node,  "wf-invalid-character-in-node-name");                
  +                }
  +                //2. check pi data
  +                //we need to check all chracters as per production rules
  +                //of XML 1.0
  +                
  +                //we need to check all chracters as per production rules
  +                //of XML1.0
  +                int i = 0 ;
  +                while(i < pidataarray.length){
  +                    if( XMLChar.isValid(pidataarray[i++]) ){
  +                        //REVISIT: As per DOM it is error but as per XML spec. it is fatal error
  +                        reportDOMError("Invalid Character",
  +                            DOMError.SEVERITY_FATAL_ERROR, node,  "wf-invalid-character");
  +                    };
  +                }            
  +            }
  +            
  +        }//end case Node.PROCESSING_INSTRUCTION_NODE
  +        
  +        }//end of switch
           return null;
  -    }
  +    }//normalizeNode
   
       protected final void expandEntityRef (Node node, Node parent, Node reference){
           Node kid, next;
  
  
  
  1.69      +8 -6      xml-xerces/java/src/org/apache/xerces/dom/NodeImpl.java
  
  Index: NodeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/NodeImpl.java,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- NodeImpl.java	10 Jun 2003 18:09:38 -0000	1.68
  +++ NodeImpl.java	17 Nov 2003 10:53:07 -0000	1.69
  @@ -195,7 +195,7 @@
       protected final static short SPECIFIED    = 0x1<<5;
       protected final static short IGNORABLEWS  = 0x1<<6;
       protected final static short HASSTRING    = 0x1<<7;
  -    protected final static short UNNORMALIZED = 0x1<<8;
  +    protected final static short NORMALIZED = 0x1<<8;
       protected final static short ID           = 0x1<<9;
   
       //
  @@ -1035,7 +1035,8 @@
           // and have an implementation dependent order 
           if (thisOwnerDoc != otherOwnerDoc && 
               thisOwnerDoc !=null && 
  -            otherOwnerDoc !=null) 
 {
  +            otherOwnerDoc !=null) 
  + {
             int otherDocNum = ((CoreDocumentImpl)otherOwnerDoc).getNodeNumber();
             int thisDocNum = ((CoreDocumentImpl)thisOwnerDoc).getNodeNumber();
             if (otherDocNum > thisDocNum)  
  @@ -1218,7 +1219,8 @@
             // Check if the node we have reached is in fact "otherNode". This can
             // happen in the case of attributes.  In this case, otherNode 
             // "precedes" this.
  -          if (thisNode == otherNode) 
{
  +          if (thisNode == otherNode) 
  +{
               return DOCUMENT_POSITION_PRECEDING;
             }
           }
  @@ -2012,7 +2014,7 @@
       }
   
       final boolean isNormalized() {
  -        return (flags & UNNORMALIZED) == 0;
  +        return (flags & NORMALIZED) != 0;
       }
   
       final void isNormalized(boolean value) {
  @@ -2020,7 +2022,7 @@
           if (!value && isNormalized() && ownerNode != null) {
               ownerNode.isNormalized(false);
           }
  -        flags = (short) (value ? flags & ~UNNORMALIZED : flags | UNNORMALIZED);
  +        flags = (short) (value ?  flags | NORMALIZED : flags & ~NORMALIZED);
       }
   
       final boolean isIdAttribute() {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org