jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r165316 - in /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: SessionImpl.java lock/LockManagerImpl.java state/obj/ObjectPersistenceManager.java xml/AbstractSAXEventGenerator.java xml/DocViewSAXEventGenerator.java xml/SysViewSAXEventGenerator.java
Date Fri, 29 Apr 2005 16:32:33 GMT
Author: stefan
Date: Fri Apr 29 09:32:30 2005
New Revision: 165316

URL: http://svn.apache.org/viewcvs?rev=165316&view=rev
Log:
- improved reusability of sax event generators
- some javadoc corrections 

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java

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?rev=165316&r1=165315&r2=165316&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Fri Apr
29 09:32:30 2005
@@ -16,45 +16,6 @@
  */
 package org.apache.jackrabbit.core;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.security.AccessControlException;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.AccessDeniedException;
-import javax.jcr.Credentials;
-import javax.jcr.InvalidItemStateException;
-import javax.jcr.InvalidSerializedDataException;
-import javax.jcr.Item;
-import javax.jcr.ItemExistsException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.LoginException;
-import javax.jcr.NamespaceException;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-import javax.jcr.Workspace;
-import javax.jcr.ValueFactory;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.nodetype.NoSuchNodeTypeException;
-import javax.jcr.version.VersionException;
-import javax.security.auth.Subject;
-
 import org.apache.commons.collections.ReferenceMap;
 import org.apache.jackrabbit.core.config.AccessManagerConfig;
 import org.apache.jackrabbit.core.config.WorkspaceConfig;
@@ -69,12 +30,12 @@
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.SessionItemStateManager;
 import org.apache.jackrabbit.core.state.UpdatableItemStateManager;
+import org.apache.jackrabbit.core.value.ValueFactoryImpl;
 import org.apache.jackrabbit.core.version.VersionManager;
 import org.apache.jackrabbit.core.xml.DocViewSAXEventGenerator;
 import org.apache.jackrabbit.core.xml.ImportHandler;
 import org.apache.jackrabbit.core.xml.SessionImporter;
 import org.apache.jackrabbit.core.xml.SysViewSAXEventGenerator;
-import org.apache.jackrabbit.core.value.ValueFactoryImpl;
 import org.apache.log4j.Logger;
 import org.apache.xml.serialize.OutputFormat;
 import org.apache.xml.serialize.XMLSerializer;
@@ -84,6 +45,44 @@
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 
+import javax.jcr.AccessDeniedException;
+import javax.jcr.Credentials;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.InvalidSerializedDataException;
+import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.LoginException;
+import javax.jcr.NamespaceException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.ValueFactory;
+import javax.jcr.Workspace;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.version.VersionException;
+import javax.security.auth.Subject;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.security.AccessControlException;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * A <code>SessionImpl</code> ...
  */
@@ -126,7 +125,7 @@
     protected final String userId;
 
     /**
-     * the attibutes of this session
+     * the attributes of this session
      */
     protected final HashMap attributes = new HashMap();
 
@@ -1033,8 +1032,8 @@
             // there's a property, though not a node at the specified path
             throw new PathNotFoundException(absPath);
         }
-        new DocViewSAXEventGenerator((NodeImpl) item, noRecurse, skipBinary,
-                this, contentHandler).serialize();
+        new DocViewSAXEventGenerator((Node) item, noRecurse, skipBinary,
+                contentHandler).serialize();
     }
 
     /**
@@ -1068,8 +1067,8 @@
             // there's a property, though not a node at the specified path
             throw new PathNotFoundException(absPath);
         }
-        new SysViewSAXEventGenerator((NodeImpl) item, noRecurse, skipBinary,
-                this, contentHandler).serialize();
+        new SysViewSAXEventGenerator((Node) item, noRecurse, skipBinary,
+                contentHandler).serialize();
     }
 
     /**
@@ -1150,7 +1149,7 @@
     /**
      * {@inheritDoc}
      */
-    public ValueFactory getValueFactory() 
+    public ValueFactory getValueFactory()
             throws UnsupportedRepositoryOperationException, RepositoryException {
         if (valueFactory == null) {
             valueFactory = new ValueFactoryImpl();

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java?rev=165316&r1=165315&r2=165316&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
Fri Apr 29 09:32:30 2005
@@ -98,7 +98,7 @@
         this.nsResolver = session.getNamespaceResolver();
         this.locksFile = locksFile;
 
-        ((WorkspaceImpl) session.getWorkspace()).getObservationManager().
+        session.getWorkspace().getObservationManager().
                 addEventListener(this, Event.NODE_ADDED | Event.NODE_REMOVED,
                         "/", true, null, null, true);
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java?rev=165316&r1=165315&r2=165316&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/obj/ObjectPersistenceManager.java
Fri Apr 29 09:32:30 2005
@@ -425,16 +425,17 @@
 
     //------------------------------------------------------------< BLOBStore >
     /**
-     * @see BLOBStore#get
+     * {@inheritDoc}
      */
     public FileSystemResource get(String blobId) throws Exception {
         return new FileSystemResource(blobFS, blobId);
     }
 
     /**
-     * @see BLOBStore#put
+     * {@inheritDoc}
      */
-    public String put(PropertyId id, int index, InputStream in, long size) throws Exception
{
+    public String put(PropertyId id, int index, InputStream in, long size)
+            throws Exception {
         String path = buildBlobFilePath(id.getParentUUID(), id.getName(), index);
         OutputStream out = null;
         FileSystemResource internalBlobFile = new FileSystemResource(blobFS, path);
@@ -453,7 +454,7 @@
     }
 
     /**
-     * @see BLOBStore#remove
+     * {@inheritDoc}
      */
     public boolean remove(String blobId) throws Exception {
         FileSystemResource res = new FileSystemResource(blobFS, blobId);
@@ -467,7 +468,7 @@
 
     //---------------------------------------------------< PersistenceManager >
     /**
-     * @see PersistenceManager#init
+     * {@inheritDoc}
      */
     public void init(PMContext context) throws Exception {
         if (initialized) {
@@ -490,7 +491,7 @@
     }
 
     /**
-     * @see PersistenceManager#close
+     * {@inheritDoc}
      */
     public synchronized void close() throws Exception {
         if (!initialized) {
@@ -512,7 +513,7 @@
     }
 
     /**
-     * @see PersistenceManager#load
+     * {@inheritDoc}
      */
     public synchronized NodeState load(NodeId id)
             throws NoSuchItemStateException, ItemStateException {
@@ -554,7 +555,7 @@
     }
 
     /**
-     * @see PersistenceManager#load
+     * {@inheritDoc}
      */
     public synchronized PropertyState load(PropertyId id)
             throws NoSuchItemStateException, ItemStateException {
@@ -592,7 +593,7 @@
     }
 
     /**
-     * @see PersistenceManager#load
+     * {@inheritDoc}
      */
     public synchronized NodeReferences load(NodeReferencesId id)
             throws NoSuchItemStateException, ItemStateException {
@@ -631,7 +632,7 @@
     }
 
     /**
-     * @see AbstractPersistenceManager#store
+     * {@inheritDoc}
      */
     protected void store(NodeState state) throws ItemStateException {
         if (!initialized) {
@@ -659,7 +660,7 @@
     }
 
     /**
-     * @see AbstractPersistenceManager#store
+     * {@inheritDoc}
      */
     protected void store(PropertyState state) throws ItemStateException {
         if (!initialized) {
@@ -686,7 +687,7 @@
     }
 
     /**
-     * @see AbstractPersistenceManager#store
+     * {@inheritDoc}
      */
     protected void store(NodeReferences refs) throws ItemStateException {
         if (!initialized) {
@@ -712,7 +713,7 @@
     }
 
     /**
-     * @see AbstractPersistenceManager#destroy
+     * {@inheritDoc}
      */
     protected void destroy(NodeState state) throws ItemStateException {
         if (!initialized) {
@@ -735,7 +736,7 @@
     }
 
     /**
-     * @see AbstractPersistenceManager#destroy
+     * {@inheritDoc}
      */
     protected void destroy(PropertyState state) throws ItemStateException {
         if (!initialized) {
@@ -772,7 +773,7 @@
     }
 
     /**
-     * @see AbstractPersistenceManager#destroy
+     * {@inheritDoc}
      */
     protected void destroy(NodeReferences refs) throws ItemStateException {
         if (!initialized) {
@@ -795,7 +796,7 @@
     }
 
     /**
-     * @see PersistenceManager#exists(PropertyId id)
+     * {@inheritDoc}
      */
     public synchronized boolean exists(PropertyId id) throws ItemStateException {
         if (!initialized) {
@@ -814,7 +815,7 @@
     }
 
     /**
-     * @see PersistenceManager#exists(NodeId)
+     * {@inheritDoc}
      */
     public synchronized boolean exists(NodeId id) throws ItemStateException {
         if (!initialized) {
@@ -833,7 +834,7 @@
     }
 
     /**
-     * @see PersistenceManager#exists(NodeReferencesId)
+     * {@inheritDoc}
      */
     public synchronized boolean exists(NodeReferencesId id)
             throws ItemStateException {

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java?rev=165316&r1=165315&r2=165316&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/AbstractSAXEventGenerator.java
Fri Apr 29 09:32:30 2005
@@ -16,18 +16,20 @@
  */
 package org.apache.jackrabbit.core.xml;
 
+import org.apache.jackrabbit.core.BaseException;
 import org.apache.jackrabbit.core.Constants;
-import org.apache.jackrabbit.core.NodeImpl;
-import org.apache.jackrabbit.core.PropertyImpl;
-import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.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;
 import javax.jcr.PropertyIterator;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 
 /**
  * <code>AbstractSAXEventGenerator</code> serves as the base class for
@@ -36,12 +38,12 @@
  * It traverses a tree of <code>Node</code> & <code>Property</code>
  * instances, and calls the abstract methods
  * <ul>
- * <li><code>{@link #entering(NodeImpl, int)}</code></li>
- * <li><code>{@link #enteringProperties(NodeImpl, int)}</code></li>
- * <li><code>{@link #leavingProperties(NodeImpl, int)}</code></li>
- * <li><code>{@link #leaving(NodeImpl, int)}</code></li>
- * <li><code>{@link #entering(PropertyImpl, int)}</code></li>
- * <li><code>{@link #leaving(PropertyImpl, int)}</code></li>
+ * <li><code>{@link #entering(Node, int)}</code></li>
+ * <li><code>{@link #enteringProperties(Node, int)}</code></li>
+ * <li><code>{@link #leavingProperties(Node, int)}</code></li>
+ * <li><code>{@link #leaving(Node, int)}</code></li>
+ * <li><code>{@link #entering(Property, int)}</code></li>
+ * <li><code>{@link #leaving(Property, int)}</code></li>
  * </ul>
  * for every item it encounters.
  */
@@ -49,13 +51,50 @@
 
     private static Logger log = Logger.getLogger(AbstractSAXEventGenerator.class);
 
-    protected final SessionImpl session;
+    /**
+     * the session to be used for resolving namespace mappings
+     */
+    protected final Session session;
+    /**
+     * the session's namespace resolver
+     */
+    protected final NamespaceResolver nsResolver;
+
+    /**
+     * the content handler to feed the SAX events to
+     */
     protected final ContentHandler contentHandler;
-    protected final NodeImpl startNode;
+
+    protected final Node startNode;
     protected final boolean skipBinary;
     protected final boolean noRecurse;
 
     /**
+     * The jcr:primaryType property name (allowed for session-local prefix mappings)
+     */
+    protected final String jcrPrimaryType;
+    /**
+     * The jcr:mixinTypes property name (allowed for session-local prefix mappings)
+     */
+    protected final String jcrMixinTypes;
+    /**
+     * The jcr:uuid property name (allowed for session-local prefix mappings)
+     */
+    protected final String jcrUUID;
+    /**
+     * The jcr:root node name (allowed for session-local prefix mappings)
+     */
+    protected final String jcrRoot;
+    /**
+     * The jcr:xmltext node name (allowed for session-local prefix mappings)
+     */
+    protected final String jcrXMLText;
+    /**
+     * The jcr:xmlCharacters property name (allowed for session-local prefix mappings)
+     */
+    protected final String jcrXMLCharacters;
+
+    /**
      * Constructor
      *
      * @param node           the node state which should be serialized
@@ -63,18 +102,36 @@
      *                       be serialized; otherwise the entire hierarchy starting with
      *                       <code>node</code> will be serialized.
      * @param skipBinary     flag governing whether binary properties are to be serialized.
-     * @param session        the session to be used for resolving namespace mappings
      * @param contentHandler the content handler to feed the SAX events to
+     * @throws RepositoryException if an error occurs
      */
-    protected AbstractSAXEventGenerator(NodeImpl node, boolean noRecurse,
+    protected AbstractSAXEventGenerator(Node node, boolean noRecurse,
                                         boolean skipBinary,
-                                        SessionImpl session,
-                                        ContentHandler contentHandler) {
-        this.session = session;
+                                        ContentHandler contentHandler)
+            throws RepositoryException {
         startNode = node;
+        session = node.getSession();
+        nsResolver = new SessionNamespaceResolver();
+
         this.contentHandler = contentHandler;
         this.skipBinary = skipBinary;
         this.noRecurse = noRecurse;
+
+        // resolve the names of some wellknown properties
+        // allowing for session-local prefix mappings
+        try {
+            jcrPrimaryType = JCR_PRIMARYTYPE.toJCRName(nsResolver);
+            jcrMixinTypes = JCR_MIXINTYPES.toJCRName(nsResolver);
+            jcrUUID = JCR_UUID.toJCRName(nsResolver);
+            jcrRoot = JCR_ROOT.toJCRName(nsResolver);
+            jcrXMLText = JCR_XMLTEXT.toJCRName(nsResolver);
+            jcrXMLCharacters = JCR_XMLCHARACTERS.toJCRName(nsResolver);
+        } catch (BaseException e) {
+            // should never get here...
+            String msg = "internal error: failed to resolve namespace mappings";
+            log.error(msg, e);
+            throw new RepositoryException(msg, e);
+        }
     }
 
     /**
@@ -140,7 +197,7 @@
      * @throws RepositoryException
      * @throws SAXException
      */
-    protected void process(NodeImpl node, int level)
+    protected void process(Node node, int level)
             throws RepositoryException, SAXException {
         // enter node
         entering(node, level);
@@ -150,30 +207,31 @@
 
         // serialize jcr:primaryType, jcr:mixinTypes & jcr:uuid first:
         // jcr:primaryType
-        if (node.hasProperty(JCR_PRIMARYTYPE)) {
-            process(node.getProperty(JCR_PRIMARYTYPE), level + 1);
+        if (node.hasProperty(jcrPrimaryType)) {
+            process(node.getProperty(jcrPrimaryType), level + 1);
         } else {
-            String msg = "internal error: missing jcr:primaryType property on node " + node.safeGetJCRPath();
+            String msg = "internal error: missing jcr:primaryType property on node "
+                    + node.getPath();
             log.debug(msg);
             throw new RepositoryException(msg);
         }
         // jcr:mixinTypes
-        if (node.hasProperty(JCR_MIXINTYPES)) {
-            process(node.getProperty(JCR_MIXINTYPES), level + 1);
+        if (node.hasProperty(jcrMixinTypes)) {
+            process(node.getProperty(jcrMixinTypes), level + 1);
         }
         // jcr:uuid
-        if (node.hasProperty(JCR_UUID)) {
-            process(node.getProperty(JCR_UUID), level + 1);
+        if (node.hasProperty(jcrUUID)) {
+            process(node.getProperty(jcrUUID), level + 1);
         }
 
         // serialize remaining properties
         PropertyIterator propIter = node.getProperties();
         while (propIter.hasNext()) {
-            PropertyImpl prop = (PropertyImpl) propIter.nextProperty();
-            QName name = prop.getQName();
-            if (JCR_PRIMARYTYPE.equals(name)
-                    || JCR_MIXINTYPES.equals(name)
-                    || JCR_UUID.equals(name)) {
+            Property prop = propIter.nextProperty();
+            String name = prop.getName();
+            if (jcrPrimaryType.equals(name)
+                    || jcrMixinTypes.equals(name)
+                    || jcrUUID.equals(name)) {
                 continue;
             }
             // serialize property
@@ -187,7 +245,7 @@
             // child nodes
             NodeIterator nodeIter = node.getNodes();
             while (nodeIter.hasNext()) {
-                NodeImpl childNode = (NodeImpl) nodeIter.nextNode();
+                Node childNode = nodeIter.nextNode();
                 // recurse
                 process(childNode, level + 1);
             }
@@ -203,7 +261,7 @@
      * @throws RepositoryException
      * @throws SAXException
      */
-    protected void process(PropertyImpl prop, int level)
+    protected void process(Property prop, int level)
             throws RepositoryException, SAXException {
         // serialize property
         entering(prop, level);
@@ -216,7 +274,7 @@
      * @throws RepositoryException
      * @throws SAXException
      */
-    protected abstract void entering(NodeImpl node, int level)
+    protected abstract void entering(Node node, int level)
             throws RepositoryException, SAXException;
 
     /**
@@ -225,7 +283,7 @@
      * @throws RepositoryException
      * @throws SAXException
      */
-    protected abstract void enteringProperties(NodeImpl node, int level)
+    protected abstract void enteringProperties(Node node, int level)
             throws RepositoryException, SAXException;
 
     /**
@@ -234,7 +292,7 @@
      * @throws RepositoryException
      * @throws SAXException
      */
-    protected abstract void leavingProperties(NodeImpl node, int level)
+    protected abstract void leavingProperties(Node node, int level)
             throws RepositoryException, SAXException;
 
     /**
@@ -243,7 +301,7 @@
      * @throws RepositoryException
      * @throws SAXException
      */
-    protected abstract void leaving(NodeImpl node, int level)
+    protected abstract void leaving(Node node, int level)
             throws RepositoryException, SAXException;
 
     /**
@@ -252,7 +310,7 @@
      * @throws RepositoryException
      * @throws SAXException
      */
-    protected abstract void entering(PropertyImpl prop, int level)
+    protected abstract void entering(Property prop, int level)
             throws RepositoryException, SAXException;
 
     /**
@@ -261,6 +319,42 @@
      * @throws RepositoryException
      * @throws SAXException
      */
-    protected abstract void leaving(PropertyImpl prop, int level)
+    protected abstract void leaving(Property prop, int level)
             throws RepositoryException, SAXException;
+
+    //--------------------------------------------------------< inner classes >
+    /**
+     * internal helper class that exposes the <code>NamespaceResolver</code>
+     * interface on a <code>Session</code>
+     */
+    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);
+            }
+        }
+    }
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java?rev=165316&r1=165315&r2=165316&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocViewSAXEventGenerator.java
Fri Apr 29 09:32:30 2005
@@ -16,18 +16,17 @@
  */
 package org.apache.jackrabbit.core.xml;
 
-import org.apache.jackrabbit.core.NoPrefixDeclaredException;
-import org.apache.jackrabbit.core.NodeImpl;
-import org.apache.jackrabbit.core.PropertyImpl;
-import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.util.ISO9075;
 import org.apache.jackrabbit.core.value.ValueHelper;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.BaseException;
 import org.apache.log4j.Logger;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
+import javax.jcr.Node;
+import javax.jcr.Property;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
@@ -57,23 +56,33 @@
      *                       starting with <code>node</code> will be serialized.
      * @param skipBinary     flag governing whether binary properties are to be
      *                       serialized.
-     * @param session        the session to be used for resolving namespace
-     *                       mappings
      * @param contentHandler the content handler to feed the SAX events to
+     * @throws RepositoryException if an error occurs
      */
-    public DocViewSAXEventGenerator(NodeImpl node, boolean noRecurse,
+    public DocViewSAXEventGenerator(Node node, boolean noRecurse,
                                     boolean skipBinary,
-                                    SessionImpl session,
-                                    ContentHandler contentHandler) {
-        super(node, noRecurse, skipBinary, session, contentHandler);
+                                    ContentHandler contentHandler)
+            throws RepositoryException {
+        super(node, noRecurse, skipBinary, contentHandler);
 
         props = new ArrayList();
     }
 
+    private QName getQName(String rawName) throws RepositoryException {
+        try {
+            return QName.fromJCRName(rawName, nsResolver);
+        } catch (BaseException e) {
+            // should never get here...
+            String msg = "internal error: failed to resolve namespace mappings";
+            log.error(msg, e);
+            throw new RepositoryException(msg, e);
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
-    protected void entering(NodeImpl node, int level)
+    protected void entering(Node node, int level)
             throws RepositoryException, SAXException {
         // nop
     }
@@ -81,7 +90,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void enteringProperties(NodeImpl node, int level)
+    protected void enteringProperties(Node node, int level)
             throws RepositoryException, SAXException {
         // reset list of properties
         props.clear();
@@ -90,16 +99,16 @@
     /**
      * {@inheritDoc}
      */
-    protected void leavingProperties(NodeImpl node, int level)
+    protected void leavingProperties(Node node, int level)
             throws RepositoryException, SAXException {
-        QName name = node.getQName();
-        if (name.equals(JCR_XMLTEXT)) {
+        String name = node.getName();
+        if (name.equals(jcrXMLText)) {
             // the node represents xml character data
             Iterator iter = props.iterator();
             while (iter.hasNext()) {
-                PropertyImpl prop = (PropertyImpl) iter.next();
-                QName propName = prop.getQName();
-                if (propName.equals(JCR_XMLCHARACTERS)) {
+                Property prop = (Property) iter.next();
+                String propName = prop.getName();
+                if (propName.equals(jcrXMLCharacters)) {
                     // assume jcr:xmlcharacters is single-valued
                     char[] chars = prop.getValue().getString().toCharArray();
                     contentHandler.characters(chars, 0, chars.length);
@@ -108,48 +117,31 @@
         } else {
             // regular node
 
-            // encode node name to make sure it's a valid xml name
-            name = ISO9075.encode(name);
             // element name
             String elemName;
-            try {
-                if (node.getDepth() == 0) {
-                    // root node needs a name
-                    elemName = JCR_ROOT.toJCRName(session.getNamespaceResolver());
-                } else {
-                    elemName = name.toJCRName(session.getNamespaceResolver());
-                }
-            } catch (NoPrefixDeclaredException npde) {
-                // should never get here...
-                String msg = "internal error: encountered unregistered namespace";
-                log.debug(msg);
-                throw new RepositoryException(msg, npde);
+            if (node.getDepth() == 0) {
+                // root node needs a name
+                elemName = jcrRoot;
+            } else {
+                // encode node name to make sure it's a valid xml name
+                elemName = ISO9075.encode(name);
             }
 
             // attributes (properties)
             AttributesImpl attrs = new AttributesImpl();
             Iterator iter = props.iterator();
             while (iter.hasNext()) {
-                PropertyImpl prop = (PropertyImpl) iter.next();
-                QName propName = prop.getQName();
-                // encode property name to make sure it's a valid xml name
-                propName = ISO9075.encode(propName);
-                // attribute name
-                String attrName;
-                try {
-                    attrName = propName.toJCRName(session.getNamespaceResolver());
-                } catch (NoPrefixDeclaredException npde) {
-                    // should never get here...
-                    String msg =
-                            "internal error: encountered unregistered namespace";
-                    log.debug(msg);
-                    throw new RepositoryException(msg, npde);
-                }
+                Property prop = (Property) iter.next();
+                String propName = prop.getName();
+                // attribute name (encode property name to make sure it's a valid xml name)
+                String attrName = ISO9075.encode(propName);
+                QName qName = getQName(attrName);
+
                 // attribute value
                 if (prop.getType() == PropertyType.BINARY && skipBinary) {
                     // add empty attribute
-                    attrs.addAttribute(propName.getNamespaceURI(),
-                            propName.getLocalName(), attrName, CDATA_TYPE, "");
+                    attrs.addAttribute(qName.getNamespaceURI(),
+                            qName.getLocalName(), attrName, CDATA_TYPE, "");
                 } else {
                     StringBuffer attrValue = new StringBuffer();
                     // process property value(s)
@@ -167,53 +159,51 @@
                         }
                         attrValue.append(ValueHelper.serialize(vals[i], true));
                     }
-                    attrs.addAttribute(propName.getNamespaceURI(),
-                            propName.getLocalName(), attrName, CDATA_TYPE,
+                    attrs.addAttribute(qName.getNamespaceURI(),
+                            qName.getLocalName(), attrName, CDATA_TYPE,
                             attrValue.toString());
                 }
             }
             // start element (node)
-            contentHandler.startElement(name.getNamespaceURI(),
-                    name.getLocalName(), elemName, attrs);
+            QName qName = getQName(elemName);
+            contentHandler.startElement(qName.getNamespaceURI(),
+                    qName.getLocalName(), elemName, attrs);
         }
     }
 
     /**
      * {@inheritDoc}
      */
-    protected void leaving(NodeImpl node, int level)
+    protected void leaving(Node node, int level)
             throws RepositoryException, SAXException {
-        QName name = node.getQName();
-        if (name.equals(JCR_XMLTEXT)) {
+        String name = node.getName();
+        if (name.equals(jcrXMLText)) {
             // the node represents xml character data
             // (already processed in leavingProperties(NodeImpl, int)
             return;
         }
+        // encode node name to make sure it's a valid xml name
+        name = ISO9075.encode(name);
         // element name
         String elemName;
-        try {
-            if (node.getDepth() == 0) {
-                // root node needs a name
-                elemName = JCR_ROOT.toJCRName(session.getNamespaceResolver());
-            } else {
-                elemName = name.toJCRName(session.getNamespaceResolver());
-            }
-        } catch (NoPrefixDeclaredException npde) {
-            // should never get here...
-            String msg = "internal error: encountered unregistered namespace";
-            log.debug(msg);
-            throw new RepositoryException(msg, npde);
+        if (node.getDepth() == 0) {
+            // root node needs a name
+            elemName = jcrRoot;
+        } else {
+            // encode node name to make sure it's a valid xml name
+            elemName = ISO9075.encode(name);
         }
 
         // end element (node)
-        contentHandler.endElement(name.getNamespaceURI(), name.getLocalName(),
+        QName qName = getQName(elemName);
+        contentHandler.endElement(qName.getNamespaceURI(), qName.getLocalName(),
                 elemName);
     }
 
     /**
      * {@inheritDoc}
      */
-    protected void entering(PropertyImpl prop, int level)
+    protected void entering(Property prop, int level)
             throws RepositoryException, SAXException {
         props.add(prop);
     }
@@ -221,7 +211,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void leaving(PropertyImpl prop, int level)
+    protected void leaving(Property prop, int level)
             throws RepositoryException, SAXException {
         // nop
     }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java?rev=165316&r1=165315&r2=165316&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysViewSAXEventGenerator.java
Fri Apr 29 09:32:30 2005
@@ -16,17 +16,13 @@
  */
 package org.apache.jackrabbit.core.xml;
 
-import org.apache.jackrabbit.core.NoPrefixDeclaredException;
-import org.apache.jackrabbit.core.NodeImpl;
-import org.apache.jackrabbit.core.PropertyImpl;
-import org.apache.jackrabbit.core.QName;
-import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.value.ValueHelper;
-import org.apache.log4j.Logger;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
+import javax.jcr.Node;
+import javax.jcr.Property;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
@@ -39,8 +35,6 @@
  */
 public class SysViewSAXEventGenerator extends AbstractSAXEventGenerator {
 
-    private static Logger log = Logger.getLogger(SysViewSAXEventGenerator.class);
-
     /**
      * The XML elements and attributes used in serialization
      */
@@ -75,38 +69,30 @@
      *                       be serialized; otherwise the entire hierarchy starting with
      *                       <code>node</code> will be serialized.
      * @param skipBinary     flag governing whether binary properties are to be serialized.
-     * @param session        the session to be used for resolving namespace mappings
      * @param contentHandler the content handler to feed the SAX events to
+     * @throws RepositoryException if an error occurs
      */
-    public SysViewSAXEventGenerator(NodeImpl node, boolean noRecurse,
+    public SysViewSAXEventGenerator(Node node, boolean noRecurse,
                                     boolean skipBinary,
-                                    SessionImpl session,
-                                    ContentHandler contentHandler) {
-        super(node, noRecurse, skipBinary, session, contentHandler);
+                                    ContentHandler contentHandler)
+            throws RepositoryException {
+        super(node, noRecurse, skipBinary, contentHandler);
     }
 
     /**
      * {@inheritDoc}
      */
-    protected void entering(NodeImpl node, int level)
+    protected void entering(Node node, int level)
             throws RepositoryException, SAXException {
-        QName name = node.getQName();
-
         AttributesImpl attrs = new AttributesImpl();
         // name attribute
         String nodeName;
-        try {
-            if (node.getDepth() == 0) {
-                // root node needs a name
-                nodeName = JCR_ROOT.toJCRName(session.getNamespaceResolver());
-            } else {
-                nodeName = name.toJCRName(session.getNamespaceResolver());
-            }
-        } catch (NoPrefixDeclaredException npde) {
-            // should never get here...
-            String msg = "internal error: encountered unregistered namespace";
-            log.debug(msg);
-            throw new RepositoryException(msg, npde);
+        if (node.getDepth() == 0) {
+            // root node needs a name
+            nodeName = jcrRoot;
+        } else {
+            // encode node name to make sure it's a valid xml name
+            nodeName = node.getName();
         }
 
         attrs.addAttribute(NS_SV_URI, NAME_ATTRIBUTE, PREFIXED_NAME_ATTRIBUTE,
@@ -119,7 +105,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void enteringProperties(NodeImpl node, int level)
+    protected void enteringProperties(Node node, int level)
             throws RepositoryException, SAXException {
         // nop
     }
@@ -127,7 +113,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void leavingProperties(NodeImpl node, int level)
+    protected void leavingProperties(Node node, int level)
             throws RepositoryException, SAXException {
         // nop
     }
@@ -135,7 +121,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void leaving(NodeImpl node, int level)
+    protected void leaving(Node node, int level)
             throws RepositoryException, SAXException {
         // end node element
         contentHandler.endElement(NS_SV_URI, NODE_ELEMENT, PREFIXED_NODE_ELEMENT);
@@ -144,18 +130,9 @@
     /**
      * {@inheritDoc}
      */
-    protected void entering(PropertyImpl prop, int level)
+    protected void entering(Property prop, int level)
             throws RepositoryException, SAXException {
-        QName name = prop.getQName();
-        String propName;
-        try {
-            propName = name.toJCRName(session.getNamespaceResolver());
-        } catch (NoPrefixDeclaredException npde) {
-            // should never get here...
-            String msg = "internal error: encountered unregistered namespace";
-            log.debug(msg);
-            throw new RepositoryException(msg, npde);
-        }
+        String propName = prop.getName();
         AttributesImpl attrs = new AttributesImpl();
         // name attribute
         attrs.addAttribute(NS_SV_URI, NAME_ATTRIBUTE, PREFIXED_NAME_ATTRIBUTE,
@@ -167,7 +144,8 @@
             typeName = PropertyType.nameFromValue(type);
         } catch (IllegalArgumentException iae) {
             // should never be getting here
-            throw new RepositoryException("unexpected property-type ordinal: " + type, iae);
+            throw new RepositoryException("unexpected property-type ordinal: "
+                    + type, iae);
         }
         attrs.addAttribute(NS_SV_URI, TYPE_ATTRIBUTE, PREFIXED_TYPE_ATTRIBUTE,
                 ENUMERATION_TYPE, typeName);
@@ -239,7 +217,7 @@
     /**
      * {@inheritDoc}
      */
-    protected void leaving(PropertyImpl prop, int level)
+    protected void leaving(Property prop, int level)
             throws RepositoryException, SAXException {
         contentHandler.endElement(NS_SV_URI, PROPERTY_ELEMENT,
                 PREFIXED_PROPERTY_ELEMENT);



Mime
View raw message