jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r681088 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ test/java/org/apache/jackrabbit/core/
Date Wed, 30 Jul 2008 15:48:01 GMT
Author: jukka
Date: Wed Jul 30 08:48:00 2008
New Revision: 681088

URL: http://svn.apache.org/viewvc?rev=681088&view=rev
Log:
JCR-1612: Reintroduce NamespaceStorage and namespace-caching

Preparing for NamespaceStorage by simplifying NamespaceRegistryImpl.

The safeRegisterNamespace method was only used by SearchManagerImpl,
so moved it to there as a private utility method.

Removed:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/NamespaceRegistryImplTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java?rev=681088&r1=681087&r2=681088&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
Wed Jul 30 08:48:00 2008
@@ -277,71 +277,6 @@
     }
 
     /**
-     * Returns a prefix that is unique among the already registered prefixes.
-     *
-     * @param uriHint namespace uri that serves as hint for the prefix generation
-     * @return a unique prefix
-     */
-    public String getUniquePrefix(String uriHint) {
-        // @todo smarter unique prefix generation
-/*
-        int number;
-        if (uriHint == null || uriHint.length() == 0) {
-            number = prefixToURI.size() + 1;
-        } else {
-            number = uriHint.hashCode();
-        }
-        return "_pre" + number;
-*/
-        return "_pre" + (prefixToURI.size() + 1);
-    }
-
-    /**
-     * Registers a namespace using the given prefix hint. Does nothing
-     * if the namespace is already registered. If the given prefix hint
-     * is not yet registered as a prefix, then it is used as the prefix
-     * of the registered namespace. Otherwise a unique prefix is generated
-     * based on the given hint.
-     *
-     * @param prefixHint the prefix hint
-     * @param uri the namespace URI
-     * @throws NamespaceException if an illegal attempt is made to register
-     *                            a mapping
-     * @throws RepositoryException if an unexpected error occurs
-     * @see #registerNamespace(String, String)
-     */
-    public synchronized void safeRegisterNamespace(String prefixHint, String uri)
-            throws NamespaceException, RepositoryException {
-        try {
-            // Check if the namespace is already registered
-            getPrefix(uri);
-            // ... it is, so do nothing.
-        } catch (NamespaceException e1) {
-            // ... it is not, try to find a unique prefix.
-
-            // First, check and replace troublesome prefix hints.
-            if (prefixHint.toLowerCase().startsWith(Name.NS_XML_PREFIX)
-                    || !XMLChar.isValidNCName(prefixHint)) {
-                prefixHint = "_pre";
-            }
-
-            // Then, find an appropriate prefix based on the hint
-            String prefix = prefixHint;
-            try {
-                for (int suffix = 2; true; suffix++) {
-                    // Is this prefix already registered?
-                    getURI(prefix);
-                    // ... it is, generate a new prefix and try again.
-                    prefix = prefixHint + suffix;
-                }
-            } catch (NamespaceException e2) {
-                // ... it is not, register the namespace with this prefix.
-                registerNamespace(prefix, uri);
-            }
-        }
-    }
-
-    /**
      * Set an event channel to inform about changes.
      *
      * @param eventChannel event channel

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=681088&r1=681087&r2=681088&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Wed Jul 30 08:48:00 2008
@@ -202,27 +202,28 @@
         this.excludedNodeId = excludedNodeId;
 
         // register namespaces
-        nsReg.safeRegisterNamespace(NS_XS_PREFIX, NS_XS_URI);
+        safeRegisterNamespace(NS_XS_PREFIX, NS_XS_URI);
         try {
             if (nsReg.getPrefix(NS_FN_OLD_URI).equals(NS_FN_PREFIX)) {
                 // old uri is mapped to 'fn' prefix -> re-map
-                String prefix = null;
-                for (int i = 0; prefix == null; i++) {
-                    try {
-                        nsReg.getURI(NS_FN_OLD_PREFIX + i);
-                    } catch (NamespaceException e) {
-                        // not mapped to uri
+                String prefix = NS_FN_OLD_PREFIX;
+                try {
+                    // Find a free prefix
+                    for (int i = 2; true; i++) {
+                        nsReg.getURI(prefix);
                         prefix = NS_FN_OLD_PREFIX + i;
                     }
+                } catch (NamespaceException e) {
+                    // Re-map the old fn URI to that prefix
+                    nsReg.registerNamespace(prefix, NS_FN_OLD_URI);
                 }
-                nsReg.registerNamespace(prefix, NS_FN_OLD_URI);
             }
         } catch (NamespaceException e) {
             // does not yet exist
-            nsReg.safeRegisterNamespace(NS_FN_OLD_PREFIX, NS_FN_OLD_URI);
+            safeRegisterNamespace(NS_FN_OLD_PREFIX, NS_FN_OLD_URI);
         }
         // at this point the 'fn' prefix shouldn't be assigned anymore
-        nsReg.safeRegisterNamespace(NS_FN_PREFIX, NS_FN_URI);
+        safeRegisterNamespace(NS_FN_PREFIX, NS_FN_URI);
 
         Properties params = config.getParameters();
         queryImplClassName = params.getProperty(PARAM_QUERY_IMPL, DEFAULT_QUERY_IMPL_CLASS);
@@ -243,6 +244,43 @@
     }
 
     /**
+     * Registers a namespace using the given prefix hint. Does nothing
+     * if the namespace is already registered. If the given prefix hint
+     * is not yet registered as a prefix, then it is used as the prefix
+     * of the registered namespace. Otherwise a unique prefix is generated
+     * based on the given hint.
+     *
+     * @param prefixHint the prefix hint
+     * @param uri the namespace URI
+     * @throws NamespaceException if an illegal attempt is made to register
+     *                            a mapping
+     * @throws RepositoryException if an unexpected error occurs
+     * @see #registerNamespace(String, String)
+     */
+    private void safeRegisterNamespace(String prefixHint, String uri)
+            throws NamespaceException, RepositoryException {
+        try {
+            // Check if the namespace is already registered
+            nsReg.getPrefix(uri);
+            // ... it is, so do nothing.
+        } catch (NamespaceException e1) {
+            // ... it is not, try to find a unique prefix.
+            String prefix = prefixHint;
+            try {
+                for (int suffix = 2; true; suffix++) {
+                    // Is this prefix already registered?
+                    nsReg.getURI(prefix);
+                    // ... it is, generate a new prefix and try again.
+                    prefix = prefixHint + suffix;
+                }
+            } catch (NamespaceException e2) {
+                // ... it is not, register the namespace with this prefix.
+                nsReg.registerNamespace(prefix, uri);
+            }
+        }
+    }
+
+    /**
      * Closes this <code>SearchManager</code> and also closes the
      * {@link FileSystem} configured in {@link SearchConfig}.
      */

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java?rev=681088&r1=681087&r2=681088&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/TestAll.java
Wed Jul 30 08:48:00 2008
@@ -33,7 +33,6 @@
         TestSuite suite = new TestSuite("Core tests");
 
         suite.addTestSuite(CachingHierarchyManagerTest.class);
-        suite.addTestSuite(NamespaceRegistryImplTest.class);
         suite.addTestSuite(ShareableNodeTest.class);
         suite.addTestSuite(TransientRepositoryTest.class);
         suite.addTestSuite(XATest.class);



Mime
View raw message