You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2010/06/02 19:33:42 UTC
svn commit: r950680 -
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.java
Author: jukka
Date: Wed Jun 2 17:33:41 2010
New Revision: 950680
URL: http://svn.apache.org/viewvc?rev=950680&view=rev
Log:
JCR-888: javax.jcr.NamespaceException: : is not a registered namespace uri
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/NamespaceRegistryImpl.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=950680&r1=950679&r2=950680&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 Jun 2 17:33:41 2010
@@ -47,6 +47,17 @@ public class NamespaceRegistryImpl imple
private static Logger log = LoggerFactory.getLogger(NamespaceRegistryImpl.class);
+ /**
+ * Special property key string to be used instead of an empty key to
+ * avoid problems with Java implementations that have problems with
+ * empty keys in property files. The selected value ({@value}) would be
+ * invalid as either a namespace prefix or a URI, so there's little fear
+ * of accidental collisions.
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/JCR-888">JCR-888</a>
+ */
+ private static final String EMPTY_KEY = ".empty.key";
+
private static final String NS_REG_RESOURCE = "ns_reg.properties";
private static final String NS_IDX_RESOURCE = "ns_idx.properties";
@@ -198,11 +209,15 @@ public class NamespaceRegistryImpl imple
for (Object p : props.keySet()) {
String prefix = (String) p;
String uri = props.getProperty(prefix);
- String idx = indexes.getProperty(uri);
+ String idx = indexes.getProperty(escapePropertyKey(uri));
+ // JCR-888: Backwards compatibility check
+ if (idx == null && uri.equals("")) {
+ idx = indexes.getProperty(uri);
+ }
if (idx != null) {
- map(prefix, uri, Integer.decode(idx));
+ map(unescapePropertyKey(prefix), uri, Integer.decode(idx));
} else {
- map(prefix, uri);
+ map(unescapePropertyKey(prefix), uri);
}
}
} finally {
@@ -229,7 +244,7 @@ public class NamespaceRegistryImpl imple
// store mappings in properties
for (String prefix : prefixToURI.keySet()) {
String uri = prefixToURI.get(prefix);
- props.setProperty(prefix, uri);
+ props.setProperty(escapePropertyKey(prefix), uri);
}
try {
@@ -254,7 +269,7 @@ public class NamespaceRegistryImpl imple
// store mappings in properties
for (String uri : uriToIndex.keySet()) {
String index = uriToIndex.get(uri).toString();
- props.setProperty(uri, index);
+ props.setProperty(escapePropertyKey(uri), index);
}
try {
@@ -271,6 +286,36 @@ public class NamespaceRegistryImpl imple
}
/**
+ * Replaces an empty string with the special {@link #EMPTY_KEY} value.
+ *
+ * @see #unescapePropertyKey(String)
+ * @param key property key
+ * @return escaped property key
+ */
+ private String escapePropertyKey(String key) {
+ if (key.equals("")) {
+ return EMPTY_KEY;
+ } else {
+ return key;
+ }
+ }
+
+ /**
+ * Converts the special {@link #EMPTY_KEY} value back to an empty string.
+ *
+ * @see #escapePropertyKey(String)
+ * @param key property key
+ * @return escaped property key
+ */
+ private String unescapePropertyKey(String key) {
+ if (key.equals(EMPTY_KEY)) {
+ return "";
+ } else {
+ return key;
+ }
+ }
+
+ /**
* Set an event channel to inform about changes.
*
* @param eventChannel event channel