elena       2003/02/04 14:21:34

  Modified:    java/src/org/apache/xerces/dom EntityReferenceImpl.java
                        AttrImpl.java
  Log:
  Value of attribute should take into consideration entity reference nodes (appended 
as children)
  
  Revision  Changes    Path
  1.22      +55 -1     
xml-xerces/java/src/org/apache/xerces/dom/EntityReferenceImpl.java
  
  Index: EntityReferenceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/dom/EntityReferenceImpl.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- EntityReferenceImpl.java  20 May 2002 17:14:48 -0000      1.21
  +++ EntityReferenceImpl.java  4 Feb 2003 22:21:34 -0000       1.22
  @@ -139,6 +139,7 @@
       protected String name;
       /** Base URI*/
       protected String baseURI;
  +    
   
       /** Entity changes. */
       //protected int entityChanges = -1;      
  @@ -218,6 +219,59 @@
               synchronizeData();
           }
           baseURI = uri;
  +    }
  +    
  +     /**
  +      * NON-DOM: compute string representation of the entity reference.
  +     * This method is used to retrieve a string value for an attribute node that 
has child nodes. 
  +      * @return String representing a value of this entity ref. or 
  +     *          null if any node other than EntityReference, Text is encountered
  +     *          during computation
  +      */
  +    protected String getEntityRefValue (){
  +        if (needsSyncChildren()){
  +            synchronizeChildren();
  +        }
  +       
  +        String value = "";
  +        if (firstChild != null){
  +          if (firstChild.getNodeType() == Node.ENTITY_REFERENCE_NODE){
  +              value = ((EntityReferenceImpl)firstChild).getEntityRefValue();
  +          }
  +          else if (firstChild.getNodeType() == Node.TEXT_NODE){
  +            value = firstChild.getNodeValue();
  +          }
  +          else {
  +             // invalid to have other types of nodes in attr value
  +            return null;
  +          }
  +          
  +          if (firstChild.nextSibling == null){
  +            return value;
  +          }
  +          else {
  +            StringBuffer buff = new StringBuffer(value);
  +            ChildNode next = firstChild.nextSibling;
  +            while (next != null){   
  +            
  +                if (next.getNodeType() == Node.ENTITY_REFERENCE_NODE){
  +                   value = ((EntityReferenceImpl)next).getEntityRefValue();
  +                }
  +                else if (next.getNodeType() == Node.TEXT_NODE){
  +                  value = next.getNodeValue();
  +                }
  +                else {
  +                    // invalid to have other types of nodes in attr value
  +                    return null;
  +                }
  +                buff.append(value);
  +                next = next.nextSibling;
  +
  +            }
  +            return buff.toString();  
  +          }   
  +        } 
  +        return "";
       }
   
       /**
  
  
  
  1.50      +25 -7     xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java
  
  Index: AttrImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- AttrImpl.java     16 Jan 2003 22:53:44 -0000      1.49
  +++ AttrImpl.java     4 Feb 2003 22:21:34 -0000       1.50
  @@ -474,20 +474,38 @@
           if (hasStringValue()) {
               return (String) value;
           }
  +        
           ChildNode firstChild = ((ChildNode) value);
  -        ChildNode node = firstChild.nextSibling;
  -        if (node == null) {
  -            return firstChild.getNodeValue();
  +
  +        String data = null;
  +        if (firstChild.getNodeType() == Node.ENTITY_REFERENCE_NODE){
  +                data = ((EntityReferenceImpl)firstChild).getEntityRefValue();
  +        }
  +        else {
  +                data =  firstChild.getNodeValue();
           }
  -     StringBuffer value = new StringBuffer(firstChild.getNodeValue());
  +        
  +        ChildNode node = firstChild.nextSibling;
  +        
  +        if (node == null || data == null)  return (data == null)?"":data;
  +        
  +        StringBuffer value = new StringBuffer(data);
        while (node != null) {
  -            value.append(node.getNodeValue());
  +            if (node.getNodeType()  == Node.ENTITY_REFERENCE_NODE){
  +                data = ((EntityReferenceImpl)node).getEntityRefValue();
  +                if (data == null) return "";
  +                value.append(data);
  +            }
  +            else {
  +                value.append(node.getNodeValue());
  +            }
               node = node.nextSibling;
        }
        return value.toString();
   
       } // getValue():String
  -
  +    
  +    
       /**
        * The "specified" flag is true if and only if this attribute's
        * value was explicitly specified in the original document. Note that
  
  
  

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

Reply via email to