You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2004/07/09 00:02:58 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom ElementImpl.java ElementNSImpl.java

mrglavas    2004/07/08 15:02:58

  Modified:    java/src/org/apache/xerces/dom ElementImpl.java
                        ElementNSImpl.java
  Log:
  Fixing Jira Bug #926:
  http://nagoya.apache.org/jira/browse/XERCESJ-926
  
  If an element node specified an xml:base attribute
  whose value is a relative URI, calling getBaseURI()
  on such a node would always return null, because
  we weren't resolving it against the base URI of the
  parent.
  
  Committing the patch from Lucian Holland with some
  modifications to avoid searching up the parent
  chain unless the URI is relative.
  
  Revision  Changes    Path
  1.67      +16 -2     xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java
  
  Index: ElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- ElementImpl.java	28 May 2004 02:43:35 -0000	1.66
  +++ ElementImpl.java	8 Jul 2004 22:02:58 -0000	1.67
  @@ -176,7 +176,21 @@
                       try {
                          uri = new URI(uri).toString();
                       }
  -                    catch (org.apache.xerces.util.URI.MalformedURIException e){
  +                    catch (org.apache.xerces.util.URI.MalformedURIException e) {
  +                        // This may be a relative URI.
  +                        
  +                        // Make any parentURI into a URI object to use with the URI(URI, String) constructor
  +                        String parentBaseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null;
  +                        if (parentBaseURI != null){
  +                            try{
  +                                uri = new URI(new URI(parentBaseURI), uri).toString();
  +                            }
  +                            catch (org.apache.xerces.util.URI.MalformedURIException ex){
  +                                // This should never happen: parent should have checked the URI and returned null if invalid.
  +                                return null;
  +                            }
  +                            return uri;
  +                        }
                           return null;
                       }
                       return uri;
  
  
  
  1.43      +23 -5     xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java
  
  Index: ElementNSImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- ElementNSImpl.java	24 Feb 2004 23:23:17 -0000	1.42
  +++ ElementNSImpl.java	8 Jul 2004 22:02:58 -0000	1.43
  @@ -336,9 +336,9 @@
           if (needsSyncData()) {
               synchronizeData();
           }
  -        //Absolute base URI is computed according to XML Base (http://www.w3.org/TR/xmlbase/#granularity)
  +        // Absolute base URI is computed according to XML Base (http://www.w3.org/TR/xmlbase/#granularity)
   
  -        //1.  the base URI specified by an xml:base attribute on the element, if one exists
  +        // 1.  the base URI specified by an xml:base attribute on the element, if one exists
   
           if (attributes != null) {
               Attr attrNode = (Attr)attributes.getNamedItemNS("http://www.w3.org/XML/1998/namespace", "base");
  @@ -346,9 +346,27 @@
                   String uri =  attrNode.getNodeValue();
                   if (uri.length() != 0 ) {// attribute value is always empty string
                       try {
  -                       uri = new URI(uri).toString();
  +                        uri = new URI(uri).toString();
                       }
  -                    catch (org.apache.xerces.util.URI.MalformedURIException e){
  +                    catch (org.apache.xerces.util.URI.MalformedURIException e) {
  +                        // This may be a relative URI.
  +                        
  +                        // Start from the base URI of the parent, or if this node has no parent, the owner node.
  +                        NodeImpl parentOrOwner = (parentNode() != null) ? parentNode() : ownerNode;
  +                        
  +                        // Make any parentURI into a URI object to use with the URI(URI, String) constructor.
  +                        String parentBaseURI = (parentOrOwner != null) ? parentOrOwner.getBaseURI() : null;
  +                        
  +                        if (parentBaseURI != null) {
  +                            try {
  +                                uri = new URI(new URI(parentBaseURI), uri).toString();
  +                            }
  +                            catch (org.apache.xerces.util.URI.MalformedURIException ex){
  +                                // This should never happen: parent should have checked the URI and returned null if invalid.
  +                                return null;
  +                            }
  +                            return uri;
  +                        }                       
                           // REVISIT: what should happen in this case?
                           return null;
                       }
  
  
  

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