Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 35334 invoked from network); 12 Dec 2006 11:19:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Dec 2006 11:19:26 -0000 Received: (qmail 8857 invoked by uid 500); 12 Dec 2006 11:19:34 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 8830 invoked by uid 500); 12 Dec 2006 11:19:33 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 8818 invoked by uid 99); 12 Dec 2006 11:19:33 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Dec 2006 03:19:33 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Dec 2006 03:19:24 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 53A571A981A; Tue, 12 Dec 2006 03:18:40 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r486099 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ query/ query/lucene/ Date: Tue, 12 Dec 2006 11:18:39 -0000 To: commits@jackrabbit.apache.org From: mreutegg@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061212111840.53A571A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mreutegg Date: Tue Dec 12 03:18:37 2006 New Revision: 486099 URL: http://svn.apache.org/viewvc?view=rev&rev=486099 Log: JCR-669: Move NamespaceMappings/Index from lucene to namespace registry Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FileBasedNamespaceMappings.java (with props) jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NSRegistryBasedNamespaceMappings.java (with props) Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NamespaceMappings.java jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java 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?view=diff&rev=486099&r1=486098&r2=486099 ============================================================================== --- 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 Tue Dec 12 03:18:37 2006 @@ -30,8 +30,6 @@ import org.apache.jackrabbit.core.state.ItemStateManager; import org.apache.jackrabbit.core.state.NodeState; import org.apache.jackrabbit.core.state.NodeStateIterator; -import org.apache.jackrabbit.name.AbstractNamespaceResolver; -import org.apache.jackrabbit.name.NamespaceResolver; import org.apache.jackrabbit.name.NoPrefixDeclaredException; import org.apache.jackrabbit.name.Path; import org.apache.jackrabbit.name.PathFormat; @@ -39,7 +37,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.jcr.NamespaceException; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.observation.Event; @@ -150,9 +147,9 @@ private final QueryHandler parentHandler; /** - * Namespace resolver that is based on the namespace registry itself. + * The namespace registry of the repository. */ - private final NamespaceResolver nsResolver; + private final NamespaceRegistryImpl nsReg; /** * ID of the node that should be excluded from indexing or null @@ -223,27 +220,11 @@ } this.config = config; this.ntReg = ntReg; + this.nsReg = nsReg; this.itemMgr = itemMgr; this.rootNodeId = rootNodeId; this.parentHandler = (parentMgr != null) ? parentMgr.handler : null; this.excludedNodeId = excludedNodeId; - this.nsResolver = new AbstractNamespaceResolver() { - public String getURI(String prefix) throws NamespaceException { - try { - return nsReg.getURI(prefix); - } catch (RepositoryException e) { - throw new NamespaceException(e.getMessage()); - } - } - - public String getPrefix(String uri) throws NamespaceException { - try { - return nsReg.getPrefix(uri); - } catch (RepositoryException e) { - throw new NamespaceException(e.getMessage()); - } - } - }; // register namespaces nsReg.safeRegisterNamespace(NS_XS_PREFIX, NS_XS_URI); @@ -259,7 +240,7 @@ } if (excludedNodeId != null) { - HierarchyManagerImpl hmgr = new HierarchyManagerImpl(rootNodeId, itemMgr, nsResolver); + HierarchyManagerImpl hmgr = new HierarchyManagerImpl(rootNodeId, itemMgr, nsReg); excludePath = hmgr.getPath(excludedNodeId); } @@ -363,7 +344,7 @@ String exclude = ""; if (excludePath != null) { try { - exclude = PathFormat.format(excludePath, nsResolver); + exclude = PathFormat.format(excludePath, nsReg); } catch (NoPrefixDeclaredException e) { log.error("Error filtering events.", e); } @@ -519,7 +500,7 @@ handler = (QueryHandler) config.newInstance(); QueryHandlerContext context = new QueryHandlerContext(fs, itemMgr, rootNodeId, - ntReg, parentHandler, excludedNodeId); + ntReg, nsReg, parentHandler, excludedNodeId); handler.init(context); } catch (Exception e) { throw new RepositoryException(e.getMessage(), e); Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java?view=diff&rev=486099&r1=486098&r2=486099 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java Tue Dec 12 03:18:37 2006 @@ -20,6 +20,7 @@ import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry; import org.apache.jackrabbit.core.state.ItemStateManager; import org.apache.jackrabbit.core.NodeId; +import org.apache.jackrabbit.core.NamespaceRegistryImpl; /** * Acts as an argument for the {@link QueryHandler} to keep the interface @@ -44,6 +45,11 @@ private final NodeTypeRegistry ntRegistry; /** + * The namespace registry of the repository. + */ + private final NamespaceRegistryImpl nsRegistry; + + /** * The id of the root node. */ private NodeId rootId; @@ -73,6 +79,7 @@ * @param stateMgr provides persistent item states. * @param rootId the id of the root node. * @param ntRegistry the node type registry. + * @param nsRegistry the namespace registry. * @param parentHandler the parent query handler or null it * there is no parent handler. * @param excludedNodeId id of the node that should be excluded from @@ -83,12 +90,14 @@ ItemStateManager stateMgr, NodeId rootId, NodeTypeRegistry ntRegistry, + NamespaceRegistryImpl nsRegistry, QueryHandler parentHandler, NodeId excludedNodeId) { this.fs = fs; this.stateMgr = stateMgr; this.rootId = rootId; this.ntRegistry = ntRegistry; + this.nsRegistry = nsRegistry; propRegistry = new PropertyTypeRegistry(ntRegistry); this.parentHandler = parentHandler; this.excludedNodeId = excludedNodeId; @@ -140,6 +149,14 @@ */ public NodeTypeRegistry getNodeTypeRegistry() { return ntRegistry; + } + + /** + * Returns the NamespaceRegistryImpl for this repository. + * @return the NamespaceRegistryImpl for this repository. + */ + public NamespaceRegistryImpl getNamespaceRegistry() { + return nsRegistry; } /** Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FileBasedNamespaceMappings.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FileBasedNamespaceMappings.java?view=auto&rev=486099 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FileBasedNamespaceMappings.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FileBasedNamespaceMappings.java Tue Dec 12 03:18:37 2006 @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.core.query.lucene; + +import org.apache.jackrabbit.name.IllegalNameException; +import org.apache.jackrabbit.name.NamespaceResolver; +import org.apache.jackrabbit.name.NoPrefixDeclaredException; +import org.apache.jackrabbit.name.QName; +import org.apache.jackrabbit.name.UnknownPrefixException; +import org.apache.jackrabbit.name.AbstractNamespaceResolver; +import org.apache.jackrabbit.name.NameFormat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jcr.NamespaceException; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +/** + * The class NamespaceMappings implements a {@link + * org.apache.jackrabbit.core.NamespaceResolver} that holds a namespace + * mapping that is used internally in the search index. Storing paths with the + * full uri of a namespace would require too much space in the search index. + *

+ * Whenever a yet unknown namespace uri to prefix mapping is requested, a new + * prefix is created on the fly and associated with the namespace. Known + * namespace mappings are stored in a properties file. + */ +public class FileBasedNamespaceMappings + extends AbstractNamespaceResolver + implements NamespaceMappings { + + /** + * Default logger instance for this class + */ + private static Logger log = LoggerFactory.getLogger(NamespaceMappings.class); + + /** + * Location of the file that persists the uri / prefix mappings + */ + private final File storage; + + /** + * Map of uris indexed by prefixes + */ + private Map prefixToURI = new HashMap(); + + /** + * Map of prefixes indexed by uris + */ + private Map uriToPrefix = new HashMap(); + + /** + * Current prefix count. + */ + private int prefixCount; + + /** + * Creates NamespaceMappings instance. Initial mappings are + * loaded from file. + * + * @param file the File to load initial mappings. + * @throws IOException if an error occurs while reading initial namespace + * mappings from file. + */ + public FileBasedNamespaceMappings(File file) throws IOException { + storage = file; + load(); + } + + /** + * Returns a namespace uri for a prefix. + * + * @param prefix the namespace prefix. + * @return the namespace uri. + * @throws NamespaceException if no namespace uri is registered for + * prefix. + */ + public synchronized String getURI(String prefix) throws NamespaceException { + if (!prefixToURI.containsKey(prefix)) { + throw new NamespaceException(prefix + ": is not a registered namespace prefix."); + } + return (String) prefixToURI.get(prefix); + } + + /** + * Returns a prefix for the namespace uri. If a namespace + * mapping exists, the already known prefix is returned; otherwise a new + * prefix is created and assigned to the namespace uri. + * + * @param uri the namespace uri. + * @return the prefix for the namespace uri. + * @throws NamespaceException if an yet unknown namespace uri / prefix + * mapping could not be stored. + */ + public synchronized String getPrefix(String uri) throws NamespaceException { + String prefix = (String) uriToPrefix.get(uri); + if (prefix == null) { + // make sure prefix is not taken + while (prefixToURI.get(String.valueOf(prefixCount)) != null) { + prefixCount++; + } + prefix = String.valueOf(prefixCount); + prefixToURI.put(prefix, uri); + uriToPrefix.put(uri, prefix); + log.debug("adding new namespace mapping: " + prefix + " -> " + uri); + try { + store(); + } catch (IOException e) { + throw new NamespaceException("Could not obtain a prefix for uri: " + uri, e); + } + } + return prefix; + } + + //----------------------------< NamespaceMappings >------------------------- + + /** + * Translates a property name from a session local namespace mapping + * into a search index private namespace mapping. + * + * @param name the property name to translate + * @param resolver the NamespaceResolver of the local session. + * @return the translated property name + */ + public String translatePropertyName(String name, NamespaceResolver resolver) + throws IllegalNameException, UnknownPrefixException { + QName qName = NameFormat.parse(name, resolver); + try { + return NameFormat.format(qName, this); + } catch (NoPrefixDeclaredException e) { + // should never happen actually, because we create yet unknown + // uri mappings on the fly. + throw new IllegalNameException("Internal error.", e); + } + } + + //-----------------------< internal >--------------------------------------- + + /** + * Loads currently known mappings from a .properties file. + * + * @throws IOException if an error occurs while reading from the file. + */ + private void load() throws IOException { + if (storage.exists()) { + InputStream in = new FileInputStream(storage); + try { + Properties props = new Properties(); + log.debug("loading namespace mappings..."); + props.load(in); + + // read mappings from properties + Iterator iter = props.keySet().iterator(); + while (iter.hasNext()) { + String prefix = (String) iter.next(); + String uri = props.getProperty(prefix); + log.debug(prefix + " -> " + uri); + prefixToURI.put(prefix, uri); + uriToPrefix.put(uri, prefix); + } + prefixCount = props.size(); + log.debug("namespace mappings loaded."); + } finally { + in.close(); + } + } + } + + /** + * Writes the currently known mappings into a .properties file. + * + * @throws IOException if an error occurs while writing the file. + */ + private void store() throws IOException { + Properties props = new Properties(); + + // store mappings in properties + Iterator iter = prefixToURI.keySet().iterator(); + while (iter.hasNext()) { + String prefix = (String) iter.next(); + String uri = (String) prefixToURI.get(prefix); + props.setProperty(prefix, uri); + } + + OutputStream out = new FileOutputStream(storage); + try { + out = new BufferedOutputStream(out); + props.store(out, null); + } finally { + // make sure stream is closed + out.close(); + } + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FileBasedNamespaceMappings.java ------------------------------------------------------------------------------ svn:eol-style = native Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NSRegistryBasedNamespaceMappings.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NSRegistryBasedNamespaceMappings.java?view=auto&rev=486099 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NSRegistryBasedNamespaceMappings.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NSRegistryBasedNamespaceMappings.java Tue Dec 12 03:18:37 2006 @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jackrabbit.core.query.lucene; + +import org.apache.jackrabbit.name.AbstractNamespaceResolver; +import org.apache.jackrabbit.name.NamespaceResolver; +import org.apache.jackrabbit.name.IllegalNameException; +import org.apache.jackrabbit.name.UnknownPrefixException; +import org.apache.jackrabbit.name.QName; +import org.apache.jackrabbit.name.NameFormat; +import org.apache.jackrabbit.name.NoPrefixDeclaredException; +import org.apache.jackrabbit.core.NamespaceRegistryImpl; + +import javax.jcr.NamespaceException; + +/** + * NSRegistryBasedNamespaceMappings implements a namespace mapping + * based on the stable index prefix provided by the namespace registry. + */ +public class NSRegistryBasedNamespaceMappings + extends AbstractNamespaceResolver + implements NamespaceMappings { + + /** + * The namespace registry. + */ + private final NamespaceRegistryImpl nsReg; + + /** + * Creates a new NSRegistryBasedNamespaceMappings. + * + * @param nsReg the namespace registry of the repository. + */ + NSRegistryBasedNamespaceMappings(NamespaceRegistryImpl nsReg) { + this.nsReg = nsReg; + } + + //-------------------------------< NamespaceResolver >---------------------- + + /** + * {@inheritDoc} + */ + public String getURI(String prefix) throws NamespaceException { + try { + int index = Integer.parseInt(prefix); + return nsReg.getURI(index); + } catch (NumberFormatException e) { + throw new NamespaceException("Unknown prefix: " + prefix); + } + } + + /** + * {@inheritDoc} + */ + public String getPrefix(String uri) throws NamespaceException { + return String.valueOf(nsReg.getURIIndex(uri)); + } + + //-------------------------------< NamespaceMappings >---------------------- + + /** + * {@inheritDoc} + */ + public String translatePropertyName(String name, + NamespaceResolver resolver) + throws IllegalNameException, UnknownPrefixException { + QName qName = NameFormat.parse(name, resolver); + try { + return NameFormat.format(qName, this); + } catch (NoPrefixDeclaredException e) { + // should never happen actually, there is always a stable index + // prefix for a known namespace uri + throw new IllegalNameException("Internal error.", e); + } + } +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NSRegistryBasedNamespaceMappings.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NamespaceMappings.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NamespaceMappings.java?view=diff&rev=486099&r1=486098&r2=486099 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NamespaceMappings.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NamespaceMappings.java Tue Dec 12 03:18:37 2006 @@ -18,197 +18,24 @@ import org.apache.jackrabbit.name.IllegalNameException; import org.apache.jackrabbit.name.NamespaceResolver; -import org.apache.jackrabbit.name.NoPrefixDeclaredException; -import org.apache.jackrabbit.name.QName; import org.apache.jackrabbit.name.UnknownPrefixException; -import org.apache.jackrabbit.name.AbstractNamespaceResolver; -import org.apache.jackrabbit.name.NameFormat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.jcr.NamespaceException; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; /** - * The class NamespaceMappings implements a {@link - * org.apache.jackrabbit.core.NamespaceResolver} that holds a namespace - * mapping that is used internally in the search index. Storing paths with the - * full uri of a namespace would require too much space in the search index. - *

- * Whenever a yet unknown namespace uri to prefix mapping is requested, a new - * prefix is created on the fly and associated with the namespace. Known - * namespace mappings are stored in a properties file. + * The class NamespaceMappings holds a namespace mapping that is + * used internally in the search index. Storing paths with the full uri of a + * namespace would require too much space in the search index. */ -public class NamespaceMappings extends AbstractNamespaceResolver { - - /** - * Default logger instance for this class - */ - private static Logger log = LoggerFactory.getLogger(NamespaceMappings.class); - - /** - * Location of the file that persists the uri / prefix mappings - */ - private final File storage; - - /** - * Map of uris indexed by prefixes - */ - private Map prefixToURI = new HashMap(); - - /** - * Map of prefixes indexed by uris - */ - private Map uriToPrefix = new HashMap(); - - /** - * Current prefix count. - */ - private int prefixCount; - - /** - * Creates NamespaceMappings instance. Initial mappings are - * loaded from file. - * - * @param file the File to load initial mappings. - * @throws IOException if an error occurs while reading initial namespace - * mappings from file. - */ - public NamespaceMappings(File file) throws IOException { - storage = file; - load(); - } +public interface NamespaceMappings extends NamespaceResolver { /** - * Returns a namespace uri for a prefix. - * - * @param prefix the namespace prefix. - * @return the namespace uri. - * @throws NamespaceException if no namespace uri is registered for - * prefix. - */ - public synchronized String getURI(String prefix) throws NamespaceException { - if (!prefixToURI.containsKey(prefix)) { - throw new NamespaceException(prefix + ": is not a registered namespace prefix."); - } - return (String) prefixToURI.get(prefix); - } - - /** - * Returns a prefix for the namespace uri. If a namespace - * mapping exists, the already known prefix is returned; otherwise a new - * prefix is created and assigned to the namespace uri. - * - * @param uri the namespace uri. - * @return the prefix for the namespace uri. - * @throws NamespaceException if an yet unknown namespace uri / prefix - * mapping could not be stored. - */ - public synchronized String getPrefix(String uri) throws NamespaceException { - String prefix = (String) uriToPrefix.get(uri); - if (prefix == null) { - // make sure prefix is not taken - while (prefixToURI.get(String.valueOf(prefixCount)) != null) { - prefixCount++; - } - prefix = String.valueOf(prefixCount); - prefixToURI.put(prefix, uri); - uriToPrefix.put(uri, prefix); - log.debug("adding new namespace mapping: " + prefix + " -> " + uri); - try { - store(); - } catch (IOException e) { - throw new NamespaceException("Could not obtain a prefix for uri: " + uri, e); - } - } - return prefix; - } - - /** - * Translates a property name from a session local namespace mapping - * into a search index private namespace mapping. + * Translates a property name from a session local namespace mapping into a + * search index private namespace mapping. * * @param name the property name to translate * @param resolver the NamespaceResolver of the local session. * @return the translated property name */ - public String translatePropertyName(String name, NamespaceResolver resolver) - throws IllegalNameException, UnknownPrefixException { - QName qName = NameFormat.parse(name, resolver); - try { - return NameFormat.format(qName, this); - } catch (NoPrefixDeclaredException e) { - // should never happen actually, because we create yet unknown - // uri mappings on the fly. - throw new IllegalNameException("Internal error.", e); - } - } - - //-----------------------< internal >--------------------------------------- - - /** - * Loads currently known mappings from a .properties file. - * - * @throws IOException if an error occurs while reading from the file. - */ - private void load() throws IOException { - if (storage.exists()) { - InputStream in = new FileInputStream(storage); - try { - Properties props = new Properties(); - log.debug("loading namespace mappings..."); - props.load(in); - - // read mappings from properties - Iterator iter = props.keySet().iterator(); - while (iter.hasNext()) { - String prefix = (String) iter.next(); - String uri = props.getProperty(prefix); - log.debug(prefix + " -> " + uri); - prefixToURI.put(prefix, uri); - uriToPrefix.put(uri, prefix); - } - prefixCount = props.size(); - log.debug("namespace mappings loaded."); - } finally { - in.close(); - } - } - } - - /** - * Writes the currently known mappings into a .properties file. - * - * @throws IOException if an error occurs while writing the file. - */ - private void store() throws IOException { - Properties props = new Properties(); - - // store mappings in properties - Iterator iter = prefixToURI.keySet().iterator(); - while (iter.hasNext()) { - String prefix = (String) iter.next(); - String uri = (String) prefixToURI.get(prefix); - props.setProperty(prefix, uri); - } - - OutputStream out = new FileOutputStream(storage); - try { - out = new BufferedOutputStream(out); - props.store(out, null); - } finally { - // make sure stream is closed - out.close(); - } - } + public String translatePropertyName(String name, + NamespaceResolver resolver) + throws IllegalNameException, UnknownPrefixException; } Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?view=diff&rev=486099&r1=486098&r2=486099 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Tue Dec 12 03:18:37 2006 @@ -230,7 +230,16 @@ } else { // read local namespace mappings File mapFile = new File(indexDir, NS_MAPPING_FILE); - nsMappings = new NamespaceMappings(mapFile); + if (mapFile.exists()) { + // be backward compatible and use ns_mappings.properties from + // index folder + nsMappings = new FileBasedNamespaceMappings(mapFile); + } else { + // otherwise use repository wide stable index prefix from + // namespace registry + nsMappings = new NSRegistryBasedNamespaceMappings( + context.getNamespaceRegistry()); + } } index = new MultiIndex(indexDir, this, context.getItemStateManager(),