jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r680135 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java
Date Sun, 27 Jul 2008 16:03:51 GMT
Author: jukka
Date: Sun Jul 27 09:03:51 2008
New Revision: 680135

URL: http://svn.apache.org/viewvc?rev=680135&view=rev
Log:
JCR-1644: make NamespaceContext#getPrefix(java.lang.String) iterative instead of recursive

Applied patch by Fabrizio Giustina.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java?rev=680135&r1=680134&r2=680135&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/xml/NamespaceContext.java
Sun Jul 27 09:03:51 2008
@@ -90,14 +90,15 @@
      * @throws NamespaceException if the prefix is not mapped
      */
     public String getURI(String prefix) throws NamespaceException {
-        String uri = (String) prefixToURI.get(prefix);
-        if (uri != null) {
-            return uri;
-        } else if (parent != null) {
-            return parent.getURI(prefix);
-        } else {
-            throw new NamespaceException("Unknown prefix: " + prefix);
+        NamespaceContext current = this;
+        while (current != null) {
+            String uri = (String) current.prefixToURI.get(prefix);
+            if (uri != null) {
+                return uri;
+            }
+            current = current.parent;
         }
+        throw new NamespaceException("Unknown prefix: " + prefix);
     }
 
     /**
@@ -108,13 +109,14 @@
      * @throws NamespaceException if the URI is not mapped
      */
     public String getPrefix(String uri) throws NamespaceException {
-        String prefix = (String) uriToPrefix.get(uri);
-        if (prefix != null) {
-            return prefix;
-        } else if (parent != null) {
-            return parent.getPrefix(uri);
-        } else {
-            throw new NamespaceException("Unknown URI: " + uri);
+        NamespaceContext current = this;
+        while (current != null) {
+            String prefix = (String) current.uriToPrefix.get(uri);
+            if (prefix != null) {
+                return prefix;
+            }
+            current = current.parent;
         }
+        throw new NamespaceException("Unknown URI: " + uri);
     }
 }



Mime
View raw message