incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r771223 - in /incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal: JcrResourceResolver2.java helper/MapEntries.java
Date Mon, 04 May 2009 07:46:45 GMT
Author: fmeschbe
Date: Mon May  4 07:46:45 2009
New Revision: 771223

URL: http://svn.apache.org/viewvc?rev=771223&view=rev
Log:
SLING-951 Don't cache namespace prefixes any more

Modified:
    incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
    incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java

Modified: incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java?rev=771223&r1=771222&r2=771223&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
(original)
+++ incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver2.java
Mon May  4 07:46:45 2009
@@ -29,6 +29,7 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
@@ -756,15 +757,34 @@
 
     private String unmangleNamespaces(String absPath) {
         if (factory.isMangleNamespacePrefixes() && absPath.contains(MANGLE_NAMESPACE_IN_PREFIX))
{
-            Set<String> namespaces = resourceMapper.getNamespacePrefixes();
             Pattern p = Pattern.compile(MANGLE_NAMESPACE_IN);
             Matcher m = p.matcher(absPath);
             StringBuffer buf = new StringBuffer();
             while (m.find()) {
                 String namespace = m.group(1);
-                if (namespaces.contains(namespace)) {
-                    String replacement = MANGLE_NAMESPACE_OUT_PREFIX + namespace + MANGLE_NAMESPACE_OUT_SUFFIX;
+                try {
+
+                    // throws if "namespace" is not a registered
+                    // namespace prefix
+                    getSession().getNamespaceURI(namespace);
+                    
+                    String replacement = MANGLE_NAMESPACE_OUT_PREFIX
+                        + namespace + MANGLE_NAMESPACE_OUT_SUFFIX;
                     m.appendReplacement(buf, replacement);
+                    
+                } catch (NamespaceException ne) {
+                    
+                    // not a valid prefix
+                    log.debug(
+                        "unmangleNamespaces: '{}' is not a prefix, not unmangling",
+                        namespace);
+                    
+                } catch (RepositoryException re) {
+                    
+                    log.warn(
+                        "unmangleNamespaces: Problem checking namespace '{}'",
+                        namespace, re);
+                    
                 }
             }
             m.appendTail(buf);

Modified: incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java?rev=771223&r1=771222&r2=771223&view=diff
==============================================================================
--- incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
(original)
+++ incubator/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
Mon May  4 07:46:45 2009
@@ -72,8 +72,6 @@
 
     private Collection<MapEntry> mapMaps;
 
-    private Set<String> namespaces;
-
     private boolean initializing = false;
 
     private MapEntries() {
@@ -83,7 +81,6 @@
 
         resolveMaps = Collections.<MapEntry> emptyList();
         mapMaps = Collections.<MapEntry> emptyList();
-        namespaces = Collections.<String> emptySet();
     }
 
     public MapEntries(JcrResourceResolverFactoryImpl factory,
@@ -193,23 +190,6 @@
         return mapMaps;
     }
 
-    public Set<String> getNamespacePrefixes() {
-        if (namespaces == null) {
-
-            // get the current set of namespaces, we cache throughout our
-            // life time..
-            String[] namespaceList;
-            try {
-                namespaceList = getSession().getNamespacePrefixes();
-            } catch (RepositoryException re) {
-                namespaceList = new String[0];
-            }
-
-            namespaces = new HashSet<String>(Arrays.asList(namespaceList));
-        }
-        return namespaces;
-    }
-
     public Session getSession() {
         return session;
     }



Mime
View raw message