Author: tripod Date: Fri Sep 9 06:43:17 2005 New Revision: 279772 URL: http://svn.apache.org/viewcvs?rev=279772&view=rev Log: - adding helper SessionNamespaceResolver to jackrabbit commons Added: incubator/jackrabbit/trunk/commons/src/java/org/apache/jackrabbit/util/SessionNamespaceResolver.java (with props) Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java Added: incubator/jackrabbit/trunk/commons/src/java/org/apache/jackrabbit/util/SessionNamespaceResolver.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/commons/src/java/org/apache/jackrabbit/util/SessionNamespaceResolver.java?rev=279772&view=auto ============================================================================== --- incubator/jackrabbit/trunk/commons/src/java/org/apache/jackrabbit/util/SessionNamespaceResolver.java (added) +++ incubator/jackrabbit/trunk/commons/src/java/org/apache/jackrabbit/util/SessionNamespaceResolver.java Fri Sep 9 06:43:17 2005 @@ -0,0 +1,67 @@ +/* + * Copyright 2004-2005 The Apache Software Foundation or its licensors, + * as applicable. + * + * Licensed 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.util; + +import org.apache.jackrabbit.name.NamespaceResolver; + +import javax.jcr.NamespaceException; +import javax.jcr.RepositoryException; +import javax.jcr.Session; + +/** + * helper class that exposes the NamespaceResolver + * interface on a Session + */ +public class SessionNamespaceResolver implements NamespaceResolver { + + /** + * the session for the namespace lookups + */ + private final Session session; + + /** + * Creates a new namespace resolver based on a session + * @param session + */ + public SessionNamespaceResolver(Session session) { + this.session = session; + } + + /** + * {@inheritDoc} + */ + public String getPrefix(String uri) throws NamespaceException { + try { + return session.getNamespacePrefix(uri); + } catch (RepositoryException e) { + // should never get here... + throw new NamespaceException("internal error: failed to resolve namespace uri", e); + } + } + + /** + * {@inheritDoc} + */ + public String getURI(String prefix) throws NamespaceException { + try { + return session.getNamespaceURI(prefix); + } catch (RepositoryException e) { + // should never get here... + throw new NamespaceException("internal error: failed to resolve namespace prefix", e); + } + } +} Propchange: incubator/jackrabbit/trunk/commons/src/java/org/apache/jackrabbit/util/SessionNamespaceResolver.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/jackrabbit/trunk/commons/src/java/org/apache/jackrabbit/util/SessionNamespaceResolver.java ------------------------------------------------------------------------------ svn:keywords = author date id revision Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java?rev=279772&r1=279771&r2=279772&view=diff ============================================================================== --- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java (original) +++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java Fri Sep 9 06:43:17 2005 @@ -18,12 +18,12 @@ import org.apache.jackrabbit.BaseException; import org.apache.jackrabbit.Constants; +import org.apache.jackrabbit.util.SessionNamespaceResolver; import org.apache.jackrabbit.name.NamespaceResolver; import org.apache.log4j.Logger; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; -import javax.jcr.NamespaceException; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.Property; @@ -111,7 +111,7 @@ throws RepositoryException { startNode = node; session = node.getSession(); - nsResolver = new SessionNamespaceResolver(); + nsResolver = new SessionNamespaceResolver(session); this.contentHandler = contentHandler; this.skipBinary = skipBinary; @@ -322,39 +322,4 @@ protected abstract void leaving(Property prop, int level) throws RepositoryException, SAXException; - //--------------------------------------------------------< inner classes > - /** - * internal helper class that exposes the NamespaceResolver - * interface on a Session - */ - private class SessionNamespaceResolver implements NamespaceResolver { - - /** - * {@inheritDoc} - */ - public String getPrefix(String uri) throws NamespaceException { - try { - return session.getNamespacePrefix(uri); - } catch (RepositoryException re) { - // should never get here... - String msg = "internal error: failed to resolve namespace uri"; - log.error(msg, re); - throw new NamespaceException(msg, re); - } - } - - /** - * {@inheritDoc} - */ - public String getURI(String prefix) throws NamespaceException { - try { - return session.getNamespaceURI(prefix); - } catch (RepositoryException re) { - // should never get here... - String msg = "internal error: failed to resolve namespace prefix"; - log.error(msg, re); - throw new NamespaceException(msg, re); - } - } - } }