You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2005/02/03 18:00:35 UTC

svn commit: r151183 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: NamespaceRegistryImpl.java SessionImpl.java

Author: stefan
Date: Thu Feb  3 09:00:35 2005
New Revision: 151183

URL: http://svn.apache.org/viewcvs?view=rev&rev=151183
Log:
fixing namespace registry/mapping bugs

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java?view=diff&r1=151182&r2=151183
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java Thu Feb  3 09:00:35 2005
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.log4j.Logger;
+import org.apache.xerces.util.XMLChar;
 
 import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
@@ -241,9 +242,14 @@
                     + prefix + " -> " + uri + ": reserved prefix");
         }
         // special case: prefixes xml*
-        if (prefix.startsWith(NS_XML_PREFIX)) {
+        if (prefix.toLowerCase().startsWith(NS_XML_PREFIX)) {
             throw new NamespaceException("failed to register namespace "
                     + prefix + " -> " + uri + ": reserved prefix");
+        }
+        // check if the prefix is a valid XML prefix
+        if (!XMLChar.isValidNCName(prefix)) {
+            throw new NamespaceException("failed to register namespace "
+                    + prefix + " -> " + uri + ": invalid prefix");
         }
 
         String oldPrefix = (String) uriToPrefix.get(uri);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java?view=diff&r1=151182&r2=151183
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Thu Feb  3 09:00:35 2005
@@ -28,6 +28,7 @@
 import org.apache.log4j.Logger;
 import org.apache.xml.serialize.OutputFormat;
 import org.apache.xml.serialize.XMLSerializer;
+import org.apache.xerces.util.XMLChar;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -829,7 +830,7 @@
         }
         NodeImpl parent = (NodeImpl) item;
 
-        // verify that parent node is checked-out 
+        // verify that parent node is checked-out
         if (!parent.internalIsCheckedOut()) {
             String msg = parentAbsPath + ": cannot add a child to a checked-in node";
             log.error(msg);
@@ -878,7 +879,13 @@
     /**
      * @see Session#exportDocView(String, ContentHandler, boolean, boolean)
      */
-    public void exportDocView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse) throws InvalidSerializedDataException, PathNotFoundException, SAXException, RepositoryException {
+    public void exportDocView(String absPath, ContentHandler contentHandler,
+                              boolean skipBinary, boolean noRecurse)
+            throws InvalidSerializedDataException, PathNotFoundException,
+            SAXException, RepositoryException {
+        // check sanity of this session
+        sanityCheck();
+
         // @todo implement Session#exportDocView(String, ContentHandler, boolean, boolean)
         throw new RepositoryException("not yet implemented");
 /*
@@ -904,7 +911,6 @@
         new DocViewSAXEventGenerator(state, name.getName(), noRecurse, binaryAsLink,
                 stateMgr, rep.getNamespaceRegistry(),
                 session.getAccessManager(), hierMgr, contentHandler).serialize();
-    }
 */
     }
 
@@ -930,6 +936,9 @@
     public void exportSysView(String absPath, ContentHandler contentHandler,
                               boolean skipBinary, boolean noRecurse)
             throws PathNotFoundException, SAXException, RepositoryException {
+        // check sanity of this session
+        sanityCheck();
+
         // @todo implement Session#exportSysView(String, ContentHandler, boolean, boolean)
         throw new RepositoryException("not yet implemented");
 /*
@@ -1110,6 +1119,15 @@
                     || NamespaceRegistryImpl.NS_DEFAULT_URI.equals(uri)) {
                 throw new NamespaceException("default namespace is reserved and can not be changed");
             }
+            // special case: prefixes xml*
+            if (prefix.toLowerCase().startsWith(NamespaceRegistryImpl.NS_XML_PREFIX)) {
+                throw new NamespaceException("reserved prefix: " + prefix);
+            }
+            // check if the prefix is a valid XML prefix
+            if (!XMLChar.isValidNCName(prefix)) {
+                throw new NamespaceException("invalid prefix: " + prefix);
+            }
+
             // check if namespace exists (the following call will
             // trigger a NamespaceException if it doesn't)
             String globalPrefix = nsReg.getPrefix(uri);
@@ -1123,9 +1141,13 @@
             }
             if (globalURI != null) {
                 // prefix is already mapped in global namespace registry;
-                // check if it refers to a namespace that has been locally
-                // remapped, thus hiding it
+                // check if it is redundant or if it refers to a namespace
+                // that has been locally remapped, thus hiding it
                 if (!hiddenPrefixes.contains(prefix)) {
+                    if (uri.equals(globalURI) && prefix.equals(globalPrefix)) {
+                        // redundant mapping, silently ignore
+                        return;
+                    }
                     // we don't allow to hide a namespace because we can't
                     // guarantee that there are no references to it
                     // (in names of nodes/properties/node types etc.)
@@ -1136,6 +1158,10 @@
             // check if namespace is already locally mapped
             String oldPrefix = (String) uriToPrefix.get(uri);
             if (oldPrefix != null) {
+                if (oldPrefix.equals(prefix)) {
+                    // redundant mapping, silently ignore
+                    return;
+                }
                 // resurrect hidden global prefix
                 hiddenPrefixes.remove(nsReg.getPrefix(uri));
                 // remove old mapping