mrglavas    2004/11/04 12:42:20

  Modified:    java/src/org/apache/xerces/dom CharacterDataImpl.java
  Log:
  DOM Level 3 specifies an attribute called strictErrorChecking [1] which when set to 
false
  allows an implementation to not test every possible error case. Reducing the amount
  of checking performed when strictErrorChecking is false. This patch is thanks to
  Naela Nissar.
  
  [1] 
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-strictErrorChecking
  
  Revision  Changes    Path
  1.24      +85 -82    xml-xerces/java/src/org/apache/xerces/dom/CharacterDataImpl.java
  
  Index: CharacterDataImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CharacterDataImpl.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- CharacterDataImpl.java    21 Oct 2004 21:51:05 -0000      1.23
  +++ CharacterDataImpl.java    4 Nov 2004 20:42:20 -0000       1.24
  @@ -105,26 +105,28 @@
        *  type if the client simply calls setNodeValue(value).
        */
       protected void setNodeValueInternal(String value, boolean replace) {
  -     if (isReadOnly()) {
  +        
  +        CoreDocumentImpl ownerDocument = ownerDocument();
  +        
  +        if (ownerDocument.errorChecking && isReadOnly()) {
               String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"NO_MODIFICATION_ALLOWED_ERR", null);
               throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
           }
  +        
           // revisit: may want to set the value in ownerDocument.
  -     // Default behavior, overridden in some subclasses
  +        // Default behavior, overridden in some subclasses
           if (needsSyncData()) {
               synchronizeData();
           }
  -
  +        
           // keep old value for document notification
           String oldvalue = this.data;
  -
  -        CoreDocumentImpl ownerDocument = ownerDocument();
  -
  +        
           // notify document
           ownerDocument.modifyingCharacterData(this, replace);
  -
  -     this.data = value;
  -
  +        
  +        this.data = value;
  +        
           // notify document
           ownerDocument.modifiedCharacterData(this, oldvalue, value, replace);
       }
  @@ -221,43 +223,40 @@
        * for use by application programs.
        */
       void internalDeleteData (int offset, int count, boolean replace)
  -     throws DOMException {
  -     
  -     if (isReadOnly()) {
  -             String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"NO_MODIFICATION_ALLOWED_ERR", null);
  -             throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
  -     }
  -
  -     if (count < 0) {
  -             String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", 
null);
  -             throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
  -     }
  -
  -     if (needsSyncData()) {
  -             synchronizeData();
  -     }
  -     int tailLength = Math.max(data.length() - count - offset, 0);
  -     try {
  -             String value = data.substring(0, offset) +
  -             (tailLength > 0
  -                             ? data.substring(offset + count, offset + count + 
tailLength) 
  -                             : "");
  -
  -        
  -             setNodeValueInternal(value, replace);      
  -
  -             // notify document
  -             ownerDocument().deletedText(this, offset, count);
  -     }
  -     catch (StringIndexOutOfBoundsException e) {
  -             String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", 
null);
  -             throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
  -     }
  -     
  +    throws DOMException {
  +        
  +        CoreDocumentImpl ownerDocument = ownerDocument();
  +        if (ownerDocument.errorChecking) {
  +            if (isReadOnly()) {
  +                String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"NO_MODIFICATION_ALLOWED_ERR", null);
  +                throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, 
msg);
  +            }
  +            
  +            if (count < 0) {
  +                String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", 
null);
  +                throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
  +            }
  +        }
  +        
  +        if (needsSyncData()) {
  +            synchronizeData();
  +        }
  +        int tailLength = Math.max(data.length() - count - offset, 0);
  +        try {
  +            String value = data.substring(0, offset) +
  +            (tailLength > 0 ? data.substring(offset + count, offset + count + 
tailLength) : "");            
  +            
  +            setNodeValueInternal(value, replace);      
  +            
  +            // notify document
  +            ownerDocument.deletedText(this, offset, count);
  +        }
  +        catch (StringIndexOutOfBoundsException e) {
  +            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", 
null);
  +            throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
  +        }
  +        
       } // internalDeleteData(int,int,boolean)
  -     
  -
  -    
   
       /**
        * Insert additional characters into the data stored in this node,
  @@ -283,31 +282,33 @@
        * for use by application programs.
        */
       void internalInsertData (int offset, String data, boolean replace)
  -     throws DOMException {
  -     
  -     if (isReadOnly()) {
  -             String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"NO_MODIFICATION_ALLOWED_ERR", null);
  -             throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
  -     }
  -
  -     if (needsSyncData()) {
  -             synchronizeData();
  -     }
  -     try {
  -             String value =
  -                     new StringBuffer(this.data).insert(offset, data).toString();
  -
  -        
  -             setNodeValueInternal(value, replace);
  -      
  -             // notify document
  -             ownerDocument().insertedText(this, offset, data.length());
  -     }
  -     catch (StringIndexOutOfBoundsException e) {
  -             String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", 
null);
  -             throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
  -     }
  -
  +    throws DOMException {
  +        
  +        CoreDocumentImpl ownerDocument = ownerDocument();
  +        
  +        if (ownerDocument.errorChecking && isReadOnly()) {
  +            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"NO_MODIFICATION_ALLOWED_ERR", null);
  +            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
  +        }
  +        
  +        if (needsSyncData()) {
  +            synchronizeData();
  +        }
  +        try {
  +            String value =
  +                new StringBuffer(this.data).insert(offset, data).toString();
  +            
  +            
  +            setNodeValueInternal(value, replace);
  +            
  +            // notify document
  +            ownerDocument.insertedText(this, offset, data.length());
  +        }
  +        catch (StringIndexOutOfBoundsException e) {
  +            String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", 
null);
  +            throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
  +        }
  +        
       } // internalInsertData(int,String,boolean)
   
       
  @@ -337,34 +338,36 @@
        * readonly.  
        */
       public void replaceData(int offset, int count, String data) 
  -        throws DOMException {
  -
  +    throws DOMException {
  +        
  +        CoreDocumentImpl ownerDocument = ownerDocument();
  +        
           // The read-only check is done by deleteData()
           // ***** This could be more efficient w/r/t Mutation Events,
           // specifically by aggregating DOMAttrModified and
           // DOMSubtreeModified. But mutation events are 
           // underspecified; I don't feel compelled
           // to deal with it right now.
  -        if (isReadOnly()) {
  +        if (ownerDocument.errorChecking && isReadOnly()) {
               String msg = 
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, 
"NO_MODIFICATION_ALLOWED_ERR", null);
  -                throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, 
msg);
  +            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
           }
           
           if (needsSyncData()) {
               synchronizeData();
           }
  -       
  +        
           //notify document
  -        ownerDocument().replacingData(this);
  -
  +        ownerDocument.replacingData(this);
  +        
           // keep old value for document notification
           String oldvalue = this.data;
  -               
  +        
           internalDeleteData(offset, count, true);
           internalInsertData(offset, data, true);
  -                
  -        ownerDocument().replacedCharacterData(this, oldvalue, this.data);
  -
  +        
  +        ownerDocument.replacedCharacterData(this, oldvalue, this.data);
  +        
       } // replaceData(int,int,String)
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to