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 2008/04/07 04:52:10 UTC

svn commit: r645345 - in /xerces/java/trunk/src/org/apache/xerces/dom: ElementImpl.java ElementNSImpl.java

Author: mrglavas
Date: Sun Apr  6 19:52:06 2008
New Revision: 645345

URL: http://svn.apache.org/viewvc?rev=645345&view=rev
Log:
Fixing JIRA Issue #1296:
http://issues.apache.org/jira/browse/XERCESJ-1296

It was possible for getBaseURI() called on namespace-aware Element nodes
to have an exponential execution time relative to the depth of the node.
This would occur when the Document node had no URI or one of the ancestors
had a a base URI which isn't valid. Thanks to Ludger Bünger for pointing
out this issue.

Modified:
    xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java
    xerces/java/trunk/src/org/apache/xerces/dom/ElementNSImpl.java

Modified: xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java?rev=645345&r1=645344&r2=645345&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java Sun Apr  6 19:52:06 2008
@@ -158,7 +158,7 @@
 
     } // cloneNode(boolean):Node
 
-   /**
+    /**
      * DOM Level 3 WD - Experimental.
      * Retrieve baseURI
      */
@@ -172,28 +172,29 @@
         // 1. The base URI specified by an xml:base attribute on the element, 
         // if one exists
         if (attributes != null) {
-            Attr attrNode = (Attr)attributes.getNamedItem("xml:base");
+            Attr attrNode = getXMLBaseAttribute();
             if (attrNode != null) {
                 String uri =  attrNode.getNodeValue();
-                if (uri.length() != 0 ) {// attribute value is always empty string
+                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) {
                         // 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){
+                            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;
                     }
                     return uri;
@@ -203,25 +204,32 @@
 
         // 2.the base URI of the element's parent element within the 
         // document or external entity, if one exists 
-		// 3. the base URI of the document entity or external entity 
-		// containing the element
-		
-		// ownerNode serves as a parent or as document
-		String baseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null ;
-        //base URI of parent element is not null
-        if(baseURI != null){
+        // 3. the base URI of the document entity or external entity 
+        // containing the element
+
+        // ownerNode serves as a parent or as document
+        String baseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null;
+        // base URI of parent element is not null
+        if (baseURI != null) {
             try {
-                //return valid absolute base URI
-               return new URI(baseURI).toString();
+                // return valid absolute base URI
+                return new URI(baseURI).toString();
             }
-            catch (org.apache.xerces.util.URI.MalformedURIException e){
+            catch (org.apache.xerces.util.URI.MalformedURIException e) {
+                // REVISIT: what should happen in this case?
                 return null;
             }
         }
         return null;
     } //getBaseURI
-
-
+    
+    /**
+     * NON-DOM
+     * Returns the xml:base attribute.
+     */
+    protected Attr getXMLBaseAttribute() {
+        return (Attr) attributes.getNamedItem("xml:base");
+    } // getXMLBaseAttribute():Attr
 
     /**
      * NON-DOM

Modified: xerces/java/trunk/src/org/apache/xerces/dom/ElementNSImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/dom/ElementNSImpl.java?rev=645345&r1=645344&r2=645345&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/dom/ElementNSImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/dom/ElementNSImpl.java Sun Apr  6 19:52:06 2008
@@ -336,89 +336,14 @@
         }
         return localName;
     }
-
-
-   /**
-     * DOM Level 3 WD - Experimental.
-     * Retrieve baseURI
+    
+    /**
+     * NON-DOM
+     * Returns the xml:base attribute.
      */
-    public String getBaseURI() {
-
-        if (needsSyncData()) {
-            synchronizeData();
-        }
-        // 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
-
-        if (attributes != null) {
-            Attr attrNode = (Attr)attributes.getNamedItemNS("http://www.w3.org/XML/1998/namespace", "base");
-            if (attrNode != null) {
-                String uri =  attrNode.getNodeValue();
-                if (uri.length() != 0 ) {// attribute value is always empty string
-                    try {
-                        uri = new URI(uri).toString();
-                    }
-                    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;
-                    }
-                    return uri;
-                }
-            }
-        }
-
-        //2.the base URI of the element's parent element within the document or external entity,
-        //if one exists
-        String parentElementBaseURI = (this.parentNode() != null) ? this.parentNode().getBaseURI() : null ;
-        //base URI of parent element is not null
-        if(parentElementBaseURI != null){
-            try {
-                //return valid absolute base URI
-               return new URI(parentElementBaseURI).toString();
-            }
-            catch (org.apache.xerces.util.URI.MalformedURIException e){
-                // REVISIT: what should happen in this case?
-                return null;
-            }
-        }
-        //3. the base URI of the document entity or external entity containing the element
-
-        String baseURI = (this.ownerNode != null) ? this.ownerNode.getBaseURI() : null ;
-
-        if(baseURI != null){
-            try {
-                //return valid absolute base URI
-               return new URI(baseURI).toString();
-            }
-            catch (org.apache.xerces.util.URI.MalformedURIException e){
-                // REVISIT: what should happen in this case?
-                return null;
-            }
-        }
-
-        return null;
-
-    }
-
+    protected Attr getXMLBaseAttribute() {
+        return (Attr) attributes.getNamedItemNS("http://www.w3.org/XML/1998/namespace", "base");
+    } // getXMLBaseAttribute():Attr
 
     /**
      * @see org.w3c.dom.TypeInfo#getTypeName()



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