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 05:36:34 UTC

svn commit: r645355 - /xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.java

Author: mrglavas
Date: Sun Apr  6 20:36:33 2008
New Revision: 645355

URL: http://svn.apache.org/viewvc?rev=645355&view=rev
Log:
Performance: Reduce MalformedURIExceptions thrown while
resolving xml:base. The URI class previously only accepted
absolute URIs so at least one exception was always being
thrown for relative URIs.

Modified:
    xerces/java/trunk/src/org/apache/xerces/dom/ElementImpl.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=645355&r1=645354&r2=645355&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 20:36:33 2008
@@ -172,32 +172,36 @@
         // 1. The base URI specified by an xml:base attribute on the element, 
         // if one exists
         if (attributes != null) {
-            Attr attrNode = getXMLBaseAttribute();
+            final Attr attrNode = getXMLBaseAttribute();
             if (attrNode != null) {
-                String uri =  attrNode.getNodeValue();
+                final 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.
-
+                        URI _uri = new URI(uri, true);
+                        // If the URI is already absolute return it; otherwise it's relative and we need to resolve it.
+                        if (_uri.isAbsoluteURI()) {
+                            return _uri.toString();
+                        }
+                        
                         // 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();
+                        if (parentBaseURI != null) {
+                            try {
+                                URI _parentBaseURI = new URI(parentBaseURI);
+                                _uri.absolutize(_parentBaseURI);
+                                return _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; 
+                    }
+                    catch (org.apache.xerces.util.URI.MalformedURIException ex) {
                         return null;
                     }
-                    return uri;
                 }
             }
         }



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