jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r180346 [8/9] - in /incubator/jackrabbit/trunk/contrib/jcr-server: ./ client/ client/src/java/org/apache/jackrabbit/client/ client/src/java/org/apache/jackrabbit/webdav/client/methods/ commons/ commons/src/ commons/src/java/ commons/src/java/org/ commons/src/java/org/apache/ commons/src/java/org/apache/jackrabbit/ commons/src/java/org/apache/jackrabbit/nodetype/ commons/src/java/org/apache/jackrabbit/nodetype/xml/ commons/src/java/org/apache/jackrabbit/util/ commons/src/java/org/apache/jackrabbit/util/uuid/ commons/src/java/org/apache/jackrabbit/value/ server/ server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/io/ server/src/java/org/apache/jackrabbit/server/jcr/ server/src/java/org/apache/jackrabbit/server/simple/ server/src/java/org/apache/jackrabbit/webdav/jcr/ server/src/java/org/apache/jackrabbit/webdav/jcr/lock/ server/src/java/org/apache/jackrabbit/webdav/jcr/nodetype/ server/src/java/org/apache/jackrabbit/webdav/jcr/observation/ server/src/java/org/apache/jackrabbit/webdav/jcr/property/ server/src/java/org/apache/jackrabbit/webdav/jcr/search/ server/src/java/org/apache/jackrabbit/webdav/jcr/transaction/ server/src/java/org/apache/jackrabbit/webdav/jcr/version/ server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ server/src/java/org/apache/jackrabbit/webdav/simple/ webapp/ webapp/src/java/ webapp/src/java/org/ webapp/src/java/org/apache/ webapp/src/java/org/apache/jackrabbit/ webapp/src/java/org/apache/jackrabbit/j2ee/ webapp/src/webapp/ webapp/src/webapp/WEB-INF/ webdav/ webdav/src/java/org/apache/jackrabbit/webdav/ webdav/src/java/org/apache/jackrabbit/webdav/jcr/ webdav/src/java/org/apache/jackrabbit/webdav/lock/ webdav/src/java/org/apache/jackrabbit/webdav/property/ webdav/src/java/org/apache/jackrabbit/webdav/util/ webdav/src/java/org/apache/jackrabbit/webdav/version/report/
Date Mon, 06 Jun 2005 17:36:13 GMT
Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/transaction/TxLockManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/transaction/TxLockManagerImpl.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/transaction/TxLockManagerImpl.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/transaction/TxLockManagerImpl.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,691 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.webdav.jcr.transaction;
+
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.WebdavResponse;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.lock.ActiveLock;
+import org.apache.jackrabbit.webdav.lock.LockInfo;
+import org.apache.jackrabbit.webdav.lock.LockManager;
+import org.apache.jackrabbit.webdav.lock.Scope;
+import org.apache.jackrabbit.webdav.lock.Type;
+import org.apache.jackrabbit.webdav.transaction.TransactionConstants;
+import org.apache.jackrabbit.webdav.transaction.TransactionInfo;
+import org.apache.jackrabbit.webdav.transaction.TransactionResource;
+import org.apache.jackrabbit.webdav.transaction.TxActiveLock;
+import org.apache.jackrabbit.webdav.transaction.TxLockManager;
+import org.apache.jackrabbit.util.Text;
+import org.apache.log4j.Logger;
+
+import javax.jcr.RepositoryException;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * <code>TxLockManagerImpl</code> manages locks with locktype
+ * '{@link TransactionConstants#TRANSACTION jcr:transaction}'.
+ * <p/>
+ * todo: removing all expired locks
+ * todo: 'local' and 'global' are not accurate terms in the given context > replace
+ * todo: the usage of the 'global' transaction is not according to the JTA specification,
+ * which explicitely requires any transaction present on a servlet to be completed before
+ * the service method returns. Starting/completing transactions on the session object,
+ * which is possible with the jackrabbit implementation is a hack.
+ * todo: review of this transaction part is therefore required. Is there a use-case
+ * for those 'global' transactions at all...
+ */
+public class TxLockManagerImpl implements TxLockManager {
+
+    private static Logger log = Logger.getLogger(TxLockManagerImpl.class);
+
+    private TransactionMap map = new TransactionMap();
+
+    /**
+     * Create a new lock.
+     *
+     * @param lockInfo as present in the request body.
+     * @param resource
+     * @return the lock
+     * @throws DavException             if the lock could not be obtained.
+     * @throws IllegalArgumentException if the resource is <code>null</code> or
+     *                                  does not implement {@link TransactionResource} interface.
+     * @see LockManager#createLock(org.apache.jackrabbit.webdav.lock.LockInfo, org.apache.jackrabbit.webdav.DavResource)
+     */
+    public ActiveLock createLock(LockInfo lockInfo, DavResource resource)
+            throws DavException {
+        if (resource == null || !(resource instanceof TransactionResource)) {
+            throw new IllegalArgumentException("Invalid resource");
+        }
+        return createLock(lockInfo, (TransactionResource) resource);
+    }
+
+    /**
+     * Create a new lock.
+     *
+     * @param lockInfo
+     * @param resource
+     * @return the lock
+     * @throws DavException if the request lock has the wrong lock type or if
+     *                      the lock could not be obtained for any reason.
+     */
+    private synchronized ActiveLock createLock(LockInfo lockInfo, TransactionResource resource)
+            throws DavException {
+        if (!lockInfo.isDeep() || !TransactionConstants.TRANSACTION.equals(lockInfo.getType())) {
+            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED);
+        }
+
+        ActiveLock existing = getLock(lockInfo.getType(), lockInfo.getScope(), resource);
+        if (existing != null) {
+            throw new DavException(DavServletResponse.SC_LOCKED);
+        }
+        // TODO: check for locks on member resources is required as well for lock is always deep!
+
+        Transaction tx = createTransaction(resource.getLocator(), lockInfo);
+        tx.start(resource);
+
+        // keep references to this lock
+        addReferences(tx, getMap(resource), resource);
+
+        return tx.getLock();
+    }
+
+    /**
+     * Build the transaction object associated by the lock.
+     *
+     * @param locator
+     * @param lockInfo
+     * @return
+     */
+    private Transaction createTransaction(DavResourceLocator locator, LockInfo lockInfo) {
+        if (TransactionConstants.GLOBAL.equals(lockInfo.getScope())) {
+            return new GlobalTransaction(locator, new TxActiveLock(lockInfo));
+        } else {
+            return new LocalTransaction(locator, new TxActiveLock(lockInfo));
+        }
+    }
+
+    /**
+     * Refresh the lock indentified by the given lock token.
+     *
+     * @param lockInfo
+     * @param lockToken
+     * @param resource
+     * @return the lock
+     * @throws DavException
+     * @throws IllegalArgumentException if the resource is <code>null</code> or
+     *                                  does not implement {@link TransactionResource} interface.
+     * @see LockManager#refreshLock(org.apache.jackrabbit.webdav.lock.LockInfo, String, org.apache.jackrabbit.webdav.DavResource)
+     */
+    public ActiveLock refreshLock(LockInfo lockInfo, String lockToken,
+                                  DavResource resource) throws DavException {
+        if (resource == null || !(resource instanceof TransactionResource)) {
+            throw new IllegalArgumentException("Invalid resource");
+        }
+        return refreshLock(lockInfo, lockToken, (TransactionResource) resource);
+    }
+
+    /**
+     * Reset the timeout of the lock identified by the given lock token.
+     *
+     * @param lockInfo
+     * @param lockToken
+     * @param resource
+     * @return
+     * @throws DavException if the lockdid not exist or is expired.
+     */
+    private synchronized ActiveLock refreshLock(LockInfo lockInfo, String lockToken,
+                                                TransactionResource resource) throws DavException {
+
+        TransactionMap responsibleMap = getMap(resource);
+        Transaction tx = responsibleMap.get(lockToken);
+        if (tx == null) {
+            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No valid transaction lock found for resource '" + resource.getResourcePath() + "'");
+        } else if (tx.getLock().isExpired()) {
+            removeExpired(tx, responsibleMap, resource);
+            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Transaction lock for resource '" + resource.getResourcePath() + "' was already expired.");
+        } else {
+            tx.getLock().setTimeout(lockInfo.getTimeout());
+        }
+        return tx.getLock();
+    }
+
+    /**
+     * Throws UnsupportedOperationException.
+     *
+     * @param lockToken
+     * @param resource
+     * @throws DavException
+     * @see LockManager#releaseLock(String, org.apache.jackrabbit.webdav.DavResource)
+     */
+    public void releaseLock(String lockToken, DavResource resource)
+            throws DavException {
+        throw new UnsupportedOperationException("A transaction lock can only be release with a TransactionInfo object and a lock token.");
+    }
+
+    /**
+     * Release the lock identified by the given lock token.
+     *
+     * @param lockInfo
+     * @param lockToken
+     * @param resource
+     * @throws DavException
+     */
+    public synchronized void releaseLock(TransactionInfo lockInfo, String lockToken,
+                                         TransactionResource resource) throws DavException {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        TransactionMap responsibleMap = getMap(resource);
+        Transaction tx = responsibleMap.get(lockToken);
+
+        if (tx == null) {
+            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No transaction lock found for resource '" + resource.getResourcePath() + "'");
+        } else if (tx.getLock().isExpired()) {
+            removeExpired(tx, responsibleMap, resource);
+            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Transaction lock for resource '" + resource.getResourcePath() + "' was already expired.");
+        } else {
+            if (TransactionConstants.XML_COMMIT.equals(lockInfo.getStatus())) {
+                tx.commit(resource);
+            } else {
+                tx.rollback(resource);
+            }
+            removeReferences(tx, responsibleMap, resource);
+        }
+    }
+
+    /**
+     * Always returns null
+     *
+     * @param type
+     * @param scope
+     * @param resource
+     * @return null
+     * @see #getLock(Type, Scope, TransactionResource)
+     * @see LockManager#getLock(org.apache.jackrabbit.webdav.lock.Type, org.apache.jackrabbit.webdav.lock.Scope, org.apache.jackrabbit.webdav.DavResource)
+     */
+    public ActiveLock getLock(Type type, Scope scope, DavResource resource) {
+        return null;
+    }
+
+    /**
+     * Return the lock applied to the given resource or <code>null</code>
+     *
+     * @param type
+     * @param scope
+     * @param resource
+     * @return lock applied to the given resource or <code>null</code>
+     * @see LockManager#getLock(Type, Scope, DavResource)
+     *      todo: is it correct to return one that specific lock, the current session is token-holder of?
+     */
+    public ActiveLock getLock(Type type, Scope scope, TransactionResource resource) {
+        ActiveLock lock = null;
+        if (TransactionConstants.TRANSACTION.equals(type)) {
+            String[] sessionTokens = resource.getSession().getRepositorySession().getLockTokens();
+            int i = 0;
+            while (lock == null && i < sessionTokens.length) {
+                String lockToken = sessionTokens[i];
+                lock = getLock(lockToken, scope, resource);
+                i++;
+            }
+        }
+        return lock;
+    }
+
+    /**
+     * @param lockToken
+     * @param resource
+     * @return
+     */
+    private ActiveLock getLock(String lockToken, Scope scope, DavResource resource) {
+        if (!(resource instanceof TransactionResource)) {
+            log.info("");
+            return null;
+        }
+
+        ActiveLock lock = null;
+        Transaction tx = null;
+        TransactionMap m = map;
+        // check if main-map contains that txId
+        if (m.containsKey(lockToken)) {
+            tx = m.get(lockToken);
+        } else {
+            // look through all the nested tx-maps (i.e. global txs) for the given txId
+            Iterator it = m.values().iterator();
+            while (it.hasNext() && tx == null) {
+                Transaction txMap = (Transaction) it.next();
+                if (!txMap.isLocal()) {
+                    m = ((TransactionMap) txMap);
+                    if (m.containsKey(lockToken)) {
+                        tx = ((TransactionMap) txMap).get(lockToken);
+                    }
+                }
+            }
+        }
+
+        if (tx != null) {
+            if (tx.getLock().isExpired()) {
+                removeExpired(tx, m, (TransactionResource) resource);
+            } else if (tx.appliesToResource(resource) && (scope == null || tx.getLock().getScope().equals(scope))) {
+                lock = tx.getLock();
+            }
+        }
+        return lock;
+    }
+
+    /**
+     * Returns true if the given lock token belongs to a lock that applies to
+     * the given resource, false otherwise. The token may either be retrieved
+     * from the {@link DavConstants#HEADER_LOCK_TOKEN Lock-Token header} or
+     * from the {@link TransactionConstants#HEADER_TRANSACTIONID TransactionId header}.
+     *
+     * @param token
+     * @param resource
+     * @return
+     * @see LockManager#hasLock(String token, DavResource resource)
+     */
+    public boolean hasLock(String token, DavResource resource) {
+        return getLock(token, null, resource) != null;
+    }
+
+    /**
+     * Return the map that may contain a transaction lock for the given resource.
+     * In case the resource provides a transactionId, the map must be a
+     * repository transaction that is identified by the given id and which in
+     * turn can act as map.
+     *
+     * @param resource
+     * @return responsible map.
+     * @throws DavException if no map could be retrieved.
+     */
+    private TransactionMap getMap(TransactionResource resource)
+            throws DavException {
+
+        String txKey = resource.getTransactionId();
+        if (txKey == null) {
+            return map;
+        } else {
+            if (!map.containsKey(txKey)) {
+                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Transaction map '" + map + " does not contain a transaction with TransactionId '" + txKey + "'.");
+            }
+            Transaction tx = map.get(txKey);
+            if (tx.isLocal()) {
+                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "TransactionId '" + txKey + "' points to a local transaction, that cannot act as transaction map");
+            } else if (tx.getLock() != null && tx.getLock().isExpired()) {
+                removeExpired(tx, map, resource);
+                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "Attempt to retrieve an expired global transaction.");
+            }
+            // tx is a global transaction that acts as map as well.
+            return (TransactionMap) tx;
+        }
+    }
+
+    /**
+     * Rollbacks the specified transaction and releases the lock. This includes
+     * the removal of all references.
+     *
+     * @param tx
+     * @param responsibleMap
+     * @param resource
+     */
+    private static void removeExpired(Transaction tx, TransactionMap responsibleMap,
+                                      TransactionResource resource) {
+        log.info("Removing expired transaction lock " + tx);
+        try {
+            tx.rollback(resource);
+            removeReferences(tx, responsibleMap, resource);
+        } catch (DavException e) {
+            log.error("Error while removing expired transaction lock: " + e.getMessage());
+        }
+    }
+
+    /**
+     * Create the required references to the new transaction specified by tx.
+     *
+     * @param tx
+     * @param responsibleMap
+     * @param resource
+     * @throws DavException
+     */
+    private static void addReferences(Transaction tx, TransactionMap responsibleMap,
+                                      TransactionResource resource) throws DavException {
+        log.info("Adding transactionId '" + tx.getId() + "' as session lock token.");
+        resource.getSession().getRepositorySession().addLockToken(tx.getId());
+
+        responsibleMap.put(tx.getId(), tx);
+        resource.getSession().addReference(tx.getId());
+    }
+
+    /**
+     * Remove all references to the specified transaction.
+     *
+     * @param tx
+     * @param responsibleMap
+     * @param resource
+     */
+    private static void removeReferences(Transaction tx, TransactionMap responsibleMap,
+                                         TransactionResource resource) {
+        log.info("Removing transactionId '" + tx.getId() + "' from session lock tokens.");
+        resource.getSession().getRepositorySession().removeLockToken(tx.getId());
+
+        responsibleMap.remove(tx.getId());
+        resource.getSession().removeReference(tx.getId());
+    }
+    //------------------------------------------< inner classes, interfaces >---
+    /**
+     * Internal <code>Transaction</code> interface
+     */
+    private interface Transaction {
+
+        TxActiveLock getLock();
+
+        /**
+         * @return the id of this transaction.
+         */
+        String getId();
+
+        /**
+         * @return path of the lock holding resource
+         */
+        String getResourcePath();
+
+        /**
+         * @param resource
+         * @return true if the lock defined by this transaction applies to the
+         *         given resource, either due to the resource holding that lock or due
+         *         to a deep lock hold by any ancestor resource.
+         */
+        boolean appliesToResource(DavResource resource);
+
+        /**
+         * @return true if this transaction is used to allow for transient changes
+         *         on the underlaying repository, that may be persisted with the final
+         *         UNLOCK request only.
+         */
+        boolean isLocal();
+
+        /**
+         * Start this transaction.
+         *
+         * @param resource
+         * @throws DavException if an error occurs.
+         */
+        void start(TransactionResource resource) throws DavException;
+
+        /**
+         * Commit this transaction
+         *
+         * @param resource
+         * @throws DavException if an error occurs.
+         */
+        void commit(TransactionResource resource) throws DavException;
+
+        /**
+         * Rollback this transaction.
+         *
+         * @param resource
+         * @throws DavException if an error occurs.
+         */
+        void rollback(TransactionResource resource) throws DavException;
+    }
+
+    /**
+     * Abstract transaction covering functionally to both implementations.
+     */
+    private abstract static class AbstractTransaction extends TransactionMap implements Transaction {
+
+        private final DavResourceLocator locator;
+        private final TxActiveLock lock;
+
+        private AbstractTransaction(DavResourceLocator locator, TxActiveLock lock) {
+            this.locator = locator;
+            this.lock = lock;
+        }
+
+        /**
+         * @see #getLock()
+         */
+        public TxActiveLock getLock() {
+            return lock;
+        }
+
+        /**
+         * @see #getId()
+         */
+        public String getId() {
+            return lock.getToken();
+        }
+
+        /**
+         * @see #getResourcePath()
+         */
+        public String getResourcePath() {
+            return locator.getResourcePath();
+        }
+
+        /**
+         * @see #appliesToResource(DavResource)
+         */
+        public boolean appliesToResource(DavResource resource) {
+            if (locator.isSameWorkspace(resource.getLocator())) {
+                String lockResourcePath = getResourcePath();
+                String resPath = resource.getResourcePath();
+
+                while (!"".equals(resPath)) {
+                    if (lockResourcePath.equals(resPath)) {
+                        return true;
+                    }
+                    resPath = Text.getRelativeParent(resPath, 1);
+                }
+            }
+            return false;
+        }
+    }
+
+    /**
+     *
+     */
+    private final static class LocalTransaction extends AbstractTransaction {
+
+        private LocalTransaction(DavResourceLocator locator, TxActiveLock lock) {
+            super(locator, lock);
+        }
+
+        public boolean isLocal() {
+            return true;
+        }
+
+        public void start(TransactionResource resource) throws DavException {
+            try {
+                // make sure, the given resource represents an existing repository item
+                if (!resource.getSession().getRepositorySession().itemExists(getResourcePath())) {
+                    throw new DavException(DavServletResponse.SC_CONFLICT, "Unable to start local transaction: no repository item present at " + getResourcePath());
+                }
+            } catch (RepositoryException e) {
+                log.error("Unexpected error: " + e.getMessage());
+                throw new JcrDavException(e);
+            }
+        }
+
+        public void commit(TransactionResource resource) throws DavException {
+            try {
+                DavSession session = resource.getSession();
+                session.getRepositorySession().getItem(getResourcePath()).save();
+            } catch (RepositoryException e) {
+                throw new JcrDavException(e);
+            }
+        }
+
+        public void rollback(TransactionResource resource) throws DavException {
+            try {
+                DavSession session = resource.getSession();
+                session.getRepositorySession().getItem(getResourcePath()).refresh(false);
+            } catch (RepositoryException e) {
+                throw new JcrDavException(e);
+            }
+        }
+
+        public Transaction put(String key, Transaction value) throws DavException {
+            throw new DavException(WebdavResponse.SC_PRECONDITION_FAILED, "Attempt to nest a new transaction into a local one.");
+        }
+    }
+
+    /**
+     *
+     */
+    private static class GlobalTransaction extends AbstractTransaction {
+
+        private Xid xid;
+
+        private GlobalTransaction(DavResourceLocator locator, TxActiveLock lock) {
+            super(locator, lock);
+            xid = new XidImpl(lock.getToken());
+        }
+
+        public boolean isLocal() {
+            return false;
+        }
+
+        public void start(TransactionResource resource) throws DavException {
+            XAResource xaRes = getXAResource(resource);
+            try {
+                xaRes.setTransactionTimeout((int) getLock().getTimeout() / 1000);
+                xaRes.start(xid, XAResource.TMNOFLAGS);
+            } catch (XAException e) {
+                throw new DavException(DavServletResponse.SC_FORBIDDEN, e.getMessage());
+            }
+        }
+
+        public void commit(TransactionResource resource) throws DavException {
+            XAResource xaRes = getXAResource(resource);
+            try {
+                xaRes.commit(xid, false);
+                removeLocalTxReferences(resource);
+            } catch (XAException e) {
+                throw new DavException(DavServletResponse.SC_FORBIDDEN, e.getMessage());
+            }
+        }
+
+        public void rollback(TransactionResource resource) throws DavException {
+            XAResource xaRes = getXAResource(resource);
+            try {
+                xaRes.rollback(xid);
+                removeLocalTxReferences(resource);
+            } catch (XAException e) {
+                throw new DavException(DavServletResponse.SC_FORBIDDEN, e.getMessage());
+            }
+        }
+
+        private XAResource getXAResource(TransactionResource resource) throws DavException {
+/*
+
+            currently commented, since server should be jackrabbit independant
+
+	    Session session = resource.getSession().getRepositorySession();
+	    if (session instanceof XASession) {
+		return ((XASession)session).getXAResource();
+	    } else {
+		throw new DavException(DavServletResponse.SC_FORBIDDEN);
+	    }
+            */
+            throw new DavException(DavServletResponse.SC_FORBIDDEN);
+        }
+
+        private void removeLocalTxReferences(TransactionResource resource) {
+            Iterator it = values().iterator();
+            while (it.hasNext()) {
+                Transaction tx = (Transaction) it.next();
+                removeReferences(tx, this, resource);
+            }
+        }
+
+        public Transaction put(String key, Transaction value) throws DavException {
+            if (!(value instanceof LocalTransaction)) {
+                throw new DavException(WebdavResponse.SC_PRECONDITION_FAILED, "Attempt to nest global transaction into a global one.");
+            }
+            return (Transaction) super.put(key, value);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TransactionMap extends HashMap {
+
+        public Transaction get(String key) {
+            Transaction tx = null;
+            if (containsKey(key)) {
+                tx = (Transaction) super.get(key);
+            }
+            return tx;
+        }
+
+        public Transaction put(String key, Transaction value) throws DavException {
+            // any global an local transactions allowed.
+            return (Transaction) super.put(key, value);
+        }
+    }
+
+    /**
+     * Private class implementing Xid interface.
+     */
+    private static class XidImpl implements Xid {
+
+        private final String id;
+
+        /**
+         * Create a new Xid
+         *
+         * @param id
+         */
+        private XidImpl(String id) {
+            this.id = id;
+        }
+
+        /**
+         * @return 1
+         * @see javax.transaction.xa.Xid#getFormatId()
+         */
+        public int getFormatId() {
+            // todo: define reasonable format id
+            return 1;
+        }
+
+        /**
+         * @return an empty byte array.
+         * @see javax.transaction.xa.Xid#getBranchQualifier()
+         */
+        public byte[] getBranchQualifier() {
+            return new byte[0];
+        }
+
+        /**
+         * @return id as byte array
+         * @see javax.transaction.xa.Xid#getGlobalTransactionId()
+         */
+        public byte[] getGlobalTransactionId() {
+            return id.getBytes();
+        }
+    }
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/transaction/TxLockManagerImpl.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/transaction/TxLockManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * 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.webdav.jcr.version;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.*;
+import org.apache.jackrabbit.webdav.property.HrefProperty;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.jcr.DefaultItemCollection;
+import org.apache.jackrabbit.webdav.*;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Item;
+import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
+import java.util.ArrayList;
+
+/**
+ * <code>VersionHistoryItemCollection</code> represents a JCR version history.
+ *
+ * @see VersionHistory
+ */
+public class VersionHistoryItemCollection extends DefaultItemCollection
+        implements VersionHistoryResource {
+
+    private static Logger log = Logger.getLogger(VersionHistoryItemCollection.class);
+
+    /**
+     * Create a new <code>VersionHistoryItemCollection</code> resource.
+     *
+     * @param resourcePath
+     * @param session
+     * @param factory
+     */
+    public VersionHistoryItemCollection(DavResourceLocator resourcePath,
+                                        DavSession session, DavResourceFactory factory,
+                                        Item item) {
+        super(resourcePath, session, factory, item);
+        if (item == null || !(item instanceof VersionHistory)) {
+            throw new IllegalArgumentException("VersionHistory item expected.");
+        }
+    }
+
+    //----------------------------------------------< DavResource interface >---
+    /**
+     * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
+     */
+    public String getSupportedMethods() {
+        StringBuffer sb = new StringBuffer(ItemResourceConstants.METHODS);
+        sb.append(", ").append(VersionHistoryResource.METHODS);
+        return sb.toString();
+    }
+
+    /**
+     * Removing a version resource is achieved by calling <code>removeVersion</code>
+     * on the versionhistory item this version belongs to.
+     *
+     * @throws DavException if the version does not exist or if an error occurs
+     * while deleting.
+     * @see DavResource#removeMember(org.apache.jackrabbit.webdav.DavResource)
+     */
+    public void removeMember(DavResource member) throws DavException {
+        if (exists()) {
+            VersionHistory versionHistory = (VersionHistory) item;
+            try {
+                versionHistory.removeVersion(getResourceName(member.getHref(), true));
+            } catch (RepositoryException e) {
+                throw new JcrDavException(e);
+            }
+        } else {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+    }
+    //-----------------------------------< VersionHistoryResource interface >---
+    /**
+     * Return an array of {@link VersionResource}s representing all versions
+     * present in the underlaying JCR version history.
+     *
+     * @return array of {@link VersionResource}s representing all versions
+     * present in the underlaying JCR version history.
+     * @throws DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
+     */
+    public VersionResource[] getVersions() throws DavException {
+        try {
+            VersionIterator vIter = ((VersionHistory)item).getAllVersions();
+            ArrayList l = new ArrayList();
+            while (vIter.hasNext()) {
+                DavResourceLocator versionLoc = getLocatorFromItem(vIter.nextVersion());
+                DavResource vr = createResourceFromLocator(versionLoc);
+                l.add(vr);
+            }
+            return (VersionResource[]) l.toArray(new VersionResource[l.size()]);
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+    
+    //--------------------------------------------------------------------------
+    /**
+     * Fill the property set for this resource.
+     */
+    protected void initProperties() {
+        super.initProperties();
+
+        // change resourcetype defined by default item collection
+        properties.add(new ResourceType(ResourceType.VERSION_HISTORY));
+
+        // required root-version property for version-history resource
+        try {
+            String rootVersionResourcePath = ((VersionHistory)item).getRootVersion().getPath();
+            properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, getLocatorFromResourcePath(rootVersionResourcePath).getHref(true), true));
+        } catch (RepositoryException e) {
+            log.error(e.getMessage());
+        }
+
+        // required, protected version-set property for version-history resource
+        try {
+            VersionIterator vIter = ((VersionHistory)item).getAllVersions();
+            addHrefProperty(VersionHistoryResource.VERSION_SET, vIter, true);
+        } catch (RepositoryException e) {
+            log.error(e.getMessage());
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionHistoryItemCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * 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.webdav.jcr.version;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.DefaultItemCollection;
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.property.*;
+import org.apache.jackrabbit.webdav.version.*;
+import org.apache.jackrabbit.webdav.version.report.ReportType;
+import org.apache.jackrabbit.JcrConstants;
+import org.jdom.Element;
+
+import javax.jcr.*;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * <code>VersionItemCollection</code> represents a JCR version.
+ *
+ * @see Version
+ */
+public class VersionItemCollection extends DefaultItemCollection
+        implements VersionResource {
+
+    private static Logger log = Logger.getLogger(VersionItemCollection.class);
+
+    /**
+     * Create a new <code>VersionItemCollection</code>.
+     *
+     * @param locator
+     * @param session
+     * @param factory
+     */
+    public VersionItemCollection(DavResourceLocator locator, DavSession session, DavResourceFactory factory, Item item) {
+        super(locator, session, factory, item);
+        if (item == null || !(item instanceof Version)) {
+            throw new IllegalArgumentException("Version item expected.");
+        }
+    }
+
+    //----------------------------------------------< DavResource interface >---
+    /**
+     * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
+     */
+    public String getSupportedMethods() {
+        StringBuffer sb = new StringBuffer(ItemResourceConstants.METHODS);
+        sb.append(", ").append(VersionResource.METHODS);
+        return sb.toString();
+    }
+
+    //------------------------------------------< VersionResource interface >---
+    /**
+     * Modify the labels defined for the underlaying repository version.
+     *
+     * @param labelInfo
+     * @throws DavException
+     * @see VersionResource#label(org.apache.jackrabbit.webdav.version.LabelInfo)
+     * @see VersionHistory#addVersionLabel(String, String, boolean)
+     * @see VersionHistory#removeVersionLabel(String)
+     */
+    public void label(LabelInfo labelInfo) throws DavException {
+        if (labelInfo == null) {
+            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Valid label request body required.");
+        }
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+        try {
+            VersionHistory vh = getVersionHistoryItem();
+            if (labelInfo.getType() == LabelInfo.TYPE_REMOVE) {
+                vh.removeVersionLabel(labelInfo.getLabelName());
+            } else if (labelInfo.getType() == LabelInfo.TYPE_ADD) {
+                // ADD: only add if not yet existing
+                vh.addVersionLabel(item.getName(), labelInfo.getLabelName(), false);
+            } else {
+                // SET: move label if already existing
+                vh.addVersionLabel(item.getName(), labelInfo.getLabelName(), true);
+            }
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Returns the {@link VersionHistory} associated with the repository version.
+     * Note: in contrast to a versionable node, the version history of a version
+     * item is always represented by its nearest ancestor.
+     *
+     * @return the {@link VersionHistoryResource} associated with this resource.
+     * @throws org.apache.jackrabbit.webdav.DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionResource#getVersionHistory()
+     * @see javax.jcr.Item#getParent()
+     */
+    public VersionHistoryResource getVersionHistory() throws DavException {
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+
+        try {
+            VersionHistory vh = getVersionHistoryItem();
+            DavResourceLocator loc = getLocatorFromItem(vh);
+            return (VersionHistoryResource) createResourceFromLocator(loc);
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Return the nearest ancestor of the underlaying repository item.
+     *
+     * @return nearest ancestor of the underlaying repository item.
+     * @throws RepositoryException
+     */
+    private VersionHistory getVersionHistoryItem() throws RepositoryException {
+        return (VersionHistory) item.getParent();
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     * Define the set of reports supported by this resource.
+     *
+     * @see org.apache.jackrabbit.webdav.version.report.SupportedReportSetProperty
+     */
+    protected void initSupportedReports() {
+        super.initSupportedReports();
+        if (exists()) {
+            supportedReports.addReportType(ReportType.VERSION_TREE);
+        }
+    }
+
+    /**
+     * Fill the property set for this resource.
+     */
+    protected void initProperties() {
+        super.initProperties();
+
+        if (exists()) {
+            Version v = (Version)item;
+            // created and creationDate properties
+            try {
+                String creationDate = DavConstants.creationDateFormat.format(v.getCreated().getTime());
+                // replace dummy creation date from default collection
+                properties.add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, creationDate));
+
+                // required, protected DAV:version-name property
+                properties.add(new DefaultDavProperty(VERSION_NAME, v.getName(), true));
+
+                // required, protected DAV:label-name-set property
+                String[] labels = getVersionHistoryItem().getVersionLabels(v);
+                Element[] labelElems = new Element[labels.length];
+                for (int i = 0; i < labels.length; i++) {
+                    labelElems[i] = new Element(DeltaVConstants.XML_LABEL_NAME, NAMESPACE).setText(labels[i]);
+                }
+                properties.add(new DefaultDavProperty(LABEL_NAME_SET, labelElems, true));
+
+                // required DAV:predecessor-set (protected) and DAV:successor-set (computed) properties
+                addHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true);
+                addHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true);
+
+                // required DAV:version-history (computed) property
+                String vhPath = getVersionHistoryItem().getPath();
+                properties.add(new HrefProperty(VersionResource.VERSION_HISTORY, getLocatorFromResourcePath(vhPath).getHref(true), true));
+
+                // required DAV:checkout-set (computed) property
+                PropertyIterator it = v.getReferences();
+                List nodeList = new ArrayList();
+                while (it.hasNext()) {
+                    Property p = it.nextProperty();
+                    if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
+                        Node n = p.getParent();
+                        if (n.isCheckedOut()) {
+                           nodeList.add(n);
+                        }
+                    }
+                }
+                addHrefProperty(CHECKOUT_SET, (Node[]) nodeList.toArray(new Node[nodeList.size()]), true);
+
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/VersionItemCollection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html Mon Jun  6 10:36:09 2005
@@ -0,0 +1,9 @@
+<body>
+Contains JCR specific implementations for the following interfaces:
+<ul>
+<li>VersionableResource</li>
+<li>VersionControlledResource</li>
+<li>VersionResource</li>
+<li>VersionHistoryResource</li>
+</ul>
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * 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.webdav.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.util.Text;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+import javax.jcr.Session;
+import javax.jcr.RepositoryException;
+import javax.jcr.PathNotFoundException;
+import java.io.*;
+
+/**
+ * <code>ExportViewReport</code> handles REPORT requests for the 'exportview'
+ * report. The 'exportview' report is used to export
+ * {@link Session#exportDocumentView(String, java.io.OutputStream, boolean, boolean) DocView}
+ * and {@link Session#exportSystemView(String, java.io.OutputStream, boolean, boolean) SysView}
+ * of the {@link javax.jcr.Item item} represented by the requested resource.
+ * <p/>
+ * The request body must contain a jcr:exportview element:
+ * <pre>
+ * &lt;!ELEMENT exportview  ( (sysview | docview)?, skipbinary?, norecurse ) &gt;
+ * &lt;!ELEMENT sysview EMPTY &gt;
+ * &lt;!ELEMENT docview EMPTY &gt;
+ * &lt;!ELEMENT skipbinary EMPTY &gt;
+ * &lt;!ELEMENT norecurse EMPTY &gt;
+ * </pre>
+ * If no view type is specified the DocView is generated.
+ */
+public class ExportViewReport implements Report {
+
+    private static Logger log = Logger.getLogger(ExportViewReport.class);
+
+    private static final String REPORT_NAME = "exportview";
+
+    /**
+     * The exportview report type
+     */
+    public static final ReportType EXPORTVIEW_REPORT = ReportType.register(REPORT_NAME, ItemResourceConstants.NAMESPACE, ExportViewReport.class);
+
+    private String absPath;
+    private Session session;
+    private ReportInfo info;
+
+    /**
+     * Returns {@link #EXPORTVIEW_REPORT} report type.
+     *
+     * @return {@link #EXPORTVIEW_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return EXPORTVIEW_REPORT;
+    }
+
+    /**
+     * @param resource The resource this report is generated from. NOTE: the
+     * {@link org.apache.jackrabbit.webdav.DavResource#getResourcePath() resource path}
+     * of the resource is used as 'absPath' argument for exporting the specified
+     * view.
+     * @throws IllegalArgumentException if the resource is <code>null</code> or
+     * if the session object provided with the resource is <code>null</code>.
+     * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        DavSession davSession = resource.getSession();
+        if (davSession == null || davSession.getRepositorySession() == null) {
+            throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+        }
+        session = davSession.getRepositorySession();
+        absPath = resource.getResourcePath();
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified {@link ReportInfo info}
+     * object does not contain a jcr:exportview element.
+     * @see Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !REPORT_NAME.equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:exportview element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Creates a Xml document from the generated view.
+     *
+     * @return Xml document representing the output of the specified view.
+     * @throws DavException if the report document could not be created.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        Element reportElem = info.getReportElement();
+        boolean skipBinary = reportElem.getChild("skipbinary", ItemResourceConstants.NAMESPACE) != null;
+        boolean noRecurse = reportElem.getChild("norecurse", ItemResourceConstants.NAMESPACE) != null;
+
+        try {
+            // create tmpFile in default system-tmp directory
+            String prefix = "_tmp_" + Text.getLabel(absPath);
+            File tmpfile = File.createTempFile(prefix, null, null);
+            tmpfile.deleteOnExit();
+            FileOutputStream out = new FileOutputStream(tmpfile);
+
+            if (reportElem.getChild("sysview", ItemResourceConstants.NAMESPACE) != null) {
+                session.exportSystemView(absPath, out, skipBinary, noRecurse);
+            } else {
+                // default is docview
+                session.exportDocumentView(absPath, out, skipBinary, noRecurse);
+            }
+            out.close();
+
+            SAXBuilder builder = new SAXBuilder(false);
+            InputStream in = new FileInputStream(tmpfile);
+            return builder.build(in);
+
+        } catch (FileNotFoundException e) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+        } catch (IOException e) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+        } catch (PathNotFoundException e) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        } catch (JDOMException e) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/ExportViewReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * 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.webdav.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.*;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.jdom.Document;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>LocateByUuidReport</code> handles REPORT requests for the 'locate-by-uuid'
+ * report.
+ * <p/>
+ * The request body must be a 'jcr:locate-by-uuid' XML element:
+ * <pre>
+ * &lt;!ELEMENT locate-by-uuid ( href , prop? ) &gt;
+ * </pre>
+ * The response to a successful report request will be a Multi-Status response.
+ */
+public class LocateByUuidReport implements Report {
+
+    private static Logger log = Logger.getLogger(LocateByUuidReport.class);
+
+    private static final String REPORT_NAME = "locate-by-uuid";
+
+    /**
+     * The exportview report type
+     */
+    public static final ReportType LOCATE_BY_UUID_REPORT = ReportType.register(REPORT_NAME, ItemResourceConstants.NAMESPACE, LocateByUuidReport.class);
+
+    private DeltaVResource resource;
+    private ReportInfo info;
+
+    /**
+     * Returns {@link #LOCATE_BY_UUID_REPORT} report type.
+     *
+     * @return {@link #LOCATE_BY_UUID_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return LOCATE_BY_UUID_REPORT;
+    }
+
+    /**
+     * @param resource
+     * @throws IllegalArgumentException if the resource is <code>null</code> or
+     * if the session object provided with the resource is <code>null</code>.
+     * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        DavSession davSession = resource.getSession();
+        if (davSession == null || davSession.getRepositorySession() == null) {
+            throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+        }
+        this.resource = resource;
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified {@link ReportInfo info}
+     * object does not contain a jcr:exportview element.
+     * @see Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !REPORT_NAME.equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:locate-by-uuid element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Creates a Xml document from the generated view.
+     *
+     * @return Xml document representing the output of the specified view.
+     * @throws DavException if the report document could not be created.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        String uuid = info.getReportElement().getChildText(DavConstants.XML_HREF, DavConstants.NAMESPACE);
+        DavPropertyNameSet propNameSet = info.getPropertyNameSet();
+
+        try {
+            DavSession session = resource.getSession();
+            DavResourceLocator resourceLoc = resource.getLocator();
+
+            Node n = session.getRepositorySession().getNodeByUUID(uuid);
+
+            DavResourceLocator loc = resourceLoc.getFactory().createResourceLocator(resourceLoc.getPrefix(), resourceLoc.getWorkspacePath(), n.getPath());
+            DavResource res = resource.getFactory().createResource(loc, session);
+
+            MultiStatus ms = new MultiStatus();
+            ms.addResourceProperties(res, propNameSet, info.getDepth());
+            return ms.toXml();
+
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/LocateByUuidReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * 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.webdav.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.jcr.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.webdav.jcr.nodetype.PropertyDefinitionImpl;
+import org.apache.jackrabbit.webdav.jcr.nodetype.NodeDefinitionImpl;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.util.IteratorHelper;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+import javax.jcr.nodetype.*;
+import javax.jcr.*;
+import java.util.*;
+
+/**
+ * <code>NodeTypesReport</code> allows to retrieve the definition of a single
+ * or multiple node types. The request body must be a 'jcr:nodetypes' element:
+ * <pre>
+ * &lt;!ELEMENT nodetypes ( nodetype+ | all-nodetypes | mixin-nodetypes | primary-nodetypes ) &gt;
+ *
+ * &lt;!ELEMENT nodetype ( nodetype-name ) &gt;
+ * &lt;!ELEMENT nodetype-name (#PCDATA) &gt;
+ *
+ * &lt;!ELEMENT all-nodetypes EMPTY &gt;
+ * &lt;!ELEMENT mixin-nodetypes EMPTY &gt;
+ * &lt;!ELEMENT primary-nodetypes EMPTY &gt;
+ * </pre>
+ *
+ * @todo currently the nodetype report is not consistent with the general way of representing nodetype names (with NodetypeElement) in order to be compatible with the jackrabbit nodetype registry...
+ * @todo for the same reason, not the complete nodetype-definition, but only the nodetype def as stored is represented.
+ * @todo no namespace definition with response (> jackrabbit)... and nodetype element has same name as the one used with dav-properties
+ */
+public class NodeTypesReport implements Report, NodeTypeConstants {
+
+    private static Logger log = Logger.getLogger(NodeTypesReport.class);
+
+    /**
+     * The registered type of this report.
+     */
+    public static final ReportType NODETYPES_REPORT = ReportType.register("nodetypes", NodeTypeConstants.NAMESPACE, NodeTypesReport.class);
+
+    private Session session;
+    private ReportInfo info;
+
+    /**
+     * Returns {@link #NODETYPES_REPORT} type.
+     * @return {@link #NODETYPES_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return NODETYPES_REPORT;
+    }
+
+    /**
+     * @param resource
+     * @throws IllegalArgumentException if the resource or the session retrieved
+     * from the specified resource is <code>null</code>
+     * @see Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        DavSession session = resource.getSession();
+        if (session == null || session.getRepositorySession() == null) {
+            throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+        }
+        this.session = session.getRepositorySession();
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified info does not contain
+     * a jcr:nodetypes element.
+     * @see Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !"nodetypes".equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:nodetypes element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Returns a Xml representation of the node type definition(s) according
+     * to the info object.
+     *
+     * @return Xml representation of the node type definition(s)
+     * @throws DavException if the specified nodetypes are not known or if another
+     * error occurs while retrieving the nodetype definitions.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        if (info == null || session == null) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Error while running jcr:nodetypes report");
+        }
+        try {
+            Element report = new Element(XML_NODETYPES);
+            // make sure all namespace declarations are present on the root element.
+            // since the nodetype-manager uses session-local jcr names, prefix/namespace
+            // pairs are retrieved from the session and not from the namespace registry.
+            String[] prefixes = session.getNamespacePrefixes();
+            for (int i = 0; i < prefixes.length; i++) {
+                report.addNamespaceDeclaration(Namespace.getNamespace(prefixes[i], session.getNamespaceURI(prefixes[i])));
+            }
+            // retrieve the requested nodetypes
+            NodeTypeIterator ntIter = getNodeTypes();
+            while (ntIter.hasNext()) {
+                NodeType nt = ntIter.nextNodeType();
+                Element ntDef = new Element(XML_NODETYPE);
+                ntDef.setAttribute(NAME_ATTRIBUTE, nt.getName());
+                ntDef.setAttribute(ISMIXIN_ATTRIBUTE, Boolean.toString(nt.isMixin()));
+                ntDef.setAttribute(HASORDERABLECHILDNODES_ATTRIBUTE, Boolean.toString(nt.hasOrderableChildNodes()));
+
+		// declared supertypes
+		NodeType[] snts = nt.getDeclaredSupertypes();
+                Element supertypes = new Element(SUPERTYPES_ELEMENT);
+		for (int i = 0; i < snts.length; i++) {
+		    supertypes.addContent(new Element(SUPERTYPE_ELEMENT).setText(snts[i].getName()));
+		}
+		ntDef.addContent(supertypes);
+
+		// declared childnode defs
+		NodeDefinition[] cnd = nt.getChildNodeDefinitions();
+		for (int i = 0; i < cnd.length; i++) {
+		    if (cnd[i].getDeclaringNodeType().getName().equals(nt.getName())) {
+			ntDef.addContent(NodeDefinitionImpl.create(cnd[i]).toXml());
+		    }
+		}
+
+		// declared propertyDefs
+		PropertyDefinition[] pd = nt.getPropertyDefinitions();
+		for (int i = 0; i < pd.length; i++) {
+		    if (pd[i].getDeclaringNodeType().getName().equals(nt.getName())) {
+			ntDef.addContent(PropertyDefinitionImpl.create(pd[i]).toXml());
+		    }
+		}
+
+                String primaryItemName = nt.getPrimaryItemName();
+                if (primaryItemName != null) {
+                    ntDef.setAttribute(PRIMARYITEMNAME_ATTRIBUTE, primaryItemName);
+                }
+                report.addContent(ntDef);
+            }
+
+            Document reportDoc = new Document(report);
+            return reportDoc;
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Parse the Xml element in the info object an return an interator over
+     * the specified node types.
+     *
+     * @return
+     * @throws RepositoryException
+     * @throws DavException
+     */
+    private NodeTypeIterator getNodeTypes() throws RepositoryException, DavException {
+        NodeTypeIterator ntIter = null;
+        NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
+        Iterator it = info.getReportElement().getChildren().iterator();
+        while (it.hasNext() && ntIter == null) {
+            Element elem = (Element) it.next();
+            if (elem.getNamespace().equals(NAMESPACE)) {
+                String name = elem.getName();
+                if (XML_REPORT_ALLNODETYPES.equals(name)) {
+                    ntIter = ntMgr.getAllNodeTypes();
+                } else if (XML_REPORT_MIXINNODETYPES.equals(name)) {
+                    ntIter = ntMgr.getMixinNodeTypes();
+                } else if (XML_REPORT_PRIMARYNODETYPES.equals(name)) {
+                    ntIter = ntMgr.getPrimaryNodeTypes();
+                }
+            }
+        }
+        // None of the simple types. test if a report for individual nodetypes
+        // was request. If not, the request body is not valid.
+        if (ntIter == null) {
+            List ntList = new ArrayList();
+            List elemList = info.getReportElement().getChildren(XML_NODETYPE, NAMESPACE);
+            if (elemList.isEmpty()) {
+                // throw exception if the request body does not contain a single jcr:nodetype element
+                throw new DavException(DavServletResponse.SC_BAD_REQUEST, "NodeTypes report: request body has invalid format.");
+            }
+            Iterator elemIter = elemList.iterator();
+            while (elemIter.hasNext()) {
+                String nodetypeName = ((Element)elemIter.next()).getChildText(XML_NODETYPENAME, NAMESPACE);
+                if (nodetypeName != null) {
+                    ntList.add(ntMgr.getNodeType(nodetypeName));
+                }
+            }
+            ntIter = new IteratorHelper(Collections.unmodifiableCollection(ntList));
+        }
+
+        return ntIter;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/NodeTypesReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * 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.webdav.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.jdom.Document;
+import org.jdom.Element;
+
+import javax.jcr.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <code>RegisteredNamespacesReport</code> let the client retrieve the namespaces
+ * registered on the repository.<p/>
+ *
+ * Request body:
+ * <pre>
+ * &lt;!ELEMENT registerednamespaces EMPTY &gt;
+ * </pre>
+ *
+ * Response body:
+ * <pre>
+ * &lt;!ELEMENT registerednamespaces-report (namespace)* &gt;
+ * &lt;!ELEMENT namespace (prefix, uri) &gt;
+ * &lt;!ELEMENT prefix (#PCDATA) &gt;
+ * &lt;!ELEMENT uri (#PCDATA) &gt;
+ * </pre>
+ *
+ * @see javax.jcr.Workspace#getNamespaceRegistry() 
+ */
+public class RegisteredNamespacesReport implements Report, ItemResourceConstants {
+
+    private static Logger log = Logger.getLogger(RegisteredNamespacesReport.class);
+
+    /**
+     * The registered type of this report.
+     */
+    public static final ReportType REGISTERED_NAMESPACES_REPORT = ReportType.register("registerednamespaces", ItemResourceConstants.NAMESPACE, RegisteredNamespacesReport.class);
+
+    private NamespaceRegistry nsReg;
+    private ReportInfo info;
+
+    /**
+     * Returns {@link #REGISTERED_NAMESPACES_REPORT} type.
+     * @return {@link #REGISTERED_NAMESPACES_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return REGISTERED_NAMESPACES_REPORT;
+    }
+
+    /**
+     * @param resource
+     * @throws IllegalArgumentException if the resource or the session retrieved
+     * from the specified resource is <code>null</code>
+     * @see org.apache.jackrabbit.webdav.version.report.Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        try {
+            DavSession session = resource.getSession();
+            if (session == null || session.getRepositorySession() == null) {
+                throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+            }
+            nsReg = session.getRepositorySession().getWorkspace().getNamespaceRegistry();
+        } catch (RepositoryException e) {
+            log.error(e.getMessage());
+        }
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified info does not contain
+     * a jcr:nodetypes element.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !"registerednamespaces".equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:registerednamespaces element expected.");
+        }
+        this.info = info;
+    }
+
+    /**
+     * Returns a Xml representation of the node type definition(s) according
+     * to the info object.
+     *
+     * @return Xml representation of the node type definition(s)
+     * @throws org.apache.jackrabbit.webdav.DavException if the specified nodetypes are not known or if another
+     * error occurs while retrieving the nodetype definitions.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        if (info == null || nsReg == null) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "Error while running jcr:registerednamespaces report");
+        }
+        try {
+	    String[] prefixes = nsReg.getPrefixes();
+	    List namespaceList = new ArrayList();
+	    for (int i = 0; i < prefixes.length; i++) {
+		Element elem = new Element(XML_NAMESPACE, NAMESPACE);
+		elem.addContent(new Element(XML_PREFIX, NAMESPACE).setText(prefixes[i]));
+		elem.addContent(new Element(XML_URI, NAMESPACE).setText(nsReg.getURI(prefixes[i])));
+		namespaceList.add(elem);
+	    }
+	    Element report = new Element("registerednamespaces-report", NAMESPACE).addContent(namespaceList);
+            Document reportDoc = new Document(report);
+            return reportDoc;
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RegisteredNamespacesReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RepositoryDescriptorsReport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RepositoryDescriptorsReport.java?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RepositoryDescriptorsReport.java (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RepositoryDescriptorsReport.java Mon Jun  6 10:36:09 2005
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * 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.webdav.jcr.version.report;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.version.report.*;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.jcr.ItemResourceConstants;
+import org.jdom.Document;
+import org.jdom.Element;
+
+import javax.jcr.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <code>RepositoryDescriptorsReport</code> allows to retrieve the repository
+ * descriptors. The request body must be an empty 'jcr:repositorydescriptors' element:
+ * <pre>
+ * &lt;!ELEMENT repositorydescriptors EMPTY &gt;
+ * </pre>
+ * <br>
+ * The response body must match the following format
+ *
+ * <pre>
+ * &lt;!ELEMENT repositorydescriptors-report ( descriptor )* &gt;
+ * &lt;!ELEMENT descriptor ( descriptorkey, descriptorvalue ) &gt;
+ * &lt;!ELEMENT descriptorkey (#PCDATA) &gt;
+ * &lt;!ELEMENT descriptorvalue (#PCDATA) &gt;
+ * </pre>
+ *
+ * @see javax.jcr.Repository#getDescriptorKeys()
+ * @see Repository#getDescriptor(String)
+ */
+public class RepositoryDescriptorsReport implements Report, ItemResourceConstants {
+
+    private static Logger log = Logger.getLogger(RepositoryDescriptorsReport.class);
+
+    /**
+     * The registered type of this report.
+     */
+    public static final ReportType REPOSITORY_DESCRIPTORS_REPORT = ReportType.register("repositorydescriptors", ItemResourceConstants.NAMESPACE, RepositoryDescriptorsReport.class);
+
+    private Repository repository;
+
+    /**
+     * Returns {@link #REPOSITORY_DESCRIPTORS_REPORT} type.
+     * @return {@link #REPOSITORY_DESCRIPTORS_REPORT}
+     * @see org.apache.jackrabbit.webdav.version.report.Report#getType()
+     */
+    public ReportType getType() {
+        return REPOSITORY_DESCRIPTORS_REPORT;
+    }
+
+    /**
+     * @param resource
+     * @throws IllegalArgumentException if the resource or the session retrieved
+     * from the specified resource is <code>null</code>
+     * @see org.apache.jackrabbit.webdav.version.report.Report#setResource(org.apache.jackrabbit.webdav.version.DeltaVResource)
+     */
+    public void setResource(DeltaVResource resource) {
+        if (resource == null) {
+            throw new IllegalArgumentException("Resource must not be null.");
+        }
+        DavSession session = resource.getSession();
+        if (session == null || session.getRepositorySession() == null) {
+            throw new IllegalArgumentException("The resource must provide a non-null session object in order to create the jcr:nodetypes report.");
+        }
+        repository = session.getRepositorySession().getRepository();
+    }
+
+    /**
+     * @param info
+     * @throws IllegalArgumentException if the specified info does not contain
+     * a jcr:nodetypes element.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#setInfo(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public void setInfo(ReportInfo info) {
+        if (info == null || !"repositorydescriptors".equals(info.getReportElement().getName())) {
+            throw new IllegalArgumentException("jcr:repositorydescriptors element expected.");
+        }
+    }
+
+    /**
+     * Returns a Xml representation of the node type definition(s) according
+     * to the info object.
+     *
+     * @return Xml representation of the node type definition(s)
+     * @throws org.apache.jackrabbit.webdav.DavException if the specified nodetypes are not known or if another
+     * error occurs while retrieving the nodetype definitions.
+     * @see org.apache.jackrabbit.webdav.version.report.Report#toXml()
+     */
+    public Document toXml() throws DavException {
+        String[] keys = repository.getDescriptorKeys();
+        List descList = new ArrayList();
+        for (int i = 0; i < keys.length; i++) {
+            Element elem = new Element(XML_DESCRIPTOR, NAMESPACE);
+            elem.addContent(new Element(XML_DESCRIPTORKEY, NAMESPACE).setText(keys[i]));
+            elem.addContent(new Element(XML_DESCRIPTORVALUE, NAMESPACE).setText(repository.getDescriptor(keys[i])));
+            descList.add(elem);
+        }
+        Element report = new Element("repositorydescriptors-report", NAMESPACE).addContent(descList);
+        Document reportDoc = new Document(report);
+        return reportDoc;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RepositoryDescriptorsReport.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/RepositoryDescriptorsReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html?rev=180346&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html (added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html Mon Jun  6 10:36:09 2005
@@ -0,0 +1,3 @@
+<body>
+Contains JCR specific reports.
+</body>
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/version/report/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java Mon Jun  6 10:36:09 2005
@@ -21,7 +21,6 @@
 import java.io.*;
 
 import org.apache.jackrabbit.webdav.*;
-import org.apache.jackrabbit.webdav.util.Text;
 import org.apache.jackrabbit.webdav.jcr.lock.JcrActiveLock;
 import org.apache.jackrabbit.webdav.jcr.JcrDavException;
 import org.apache.jackrabbit.webdav.lock.*;
@@ -30,6 +29,7 @@
 import org.apache.jackrabbit.server.io.ImportContext;
 import org.apache.jackrabbit.server.io.ImportResourceChain;
 import org.apache.jackrabbit.server.io.ImportCollectionChain;
+import org.apache.jackrabbit.util.Text;
 import org.apache.log4j.Logger;
 
 /**

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java?rev=180346&r1=180345&r2=180346&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java (original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java Mon Jun  6 10:36:09 2005
@@ -20,17 +20,38 @@
 
 import org.apache.jackrabbit.webdav.*;
 import org.apache.jackrabbit.webdav.jcr.JcrDavException;
-import org.apache.jackrabbit.client.RepositoryAccessServlet;
+import org.apache.jackrabbit.server.CredentialsProvider;
+import org.apache.jackrabbit.server.SessionProvider;
 
 /**
  * Simple implementation of the {@link DavSessionProvider}
- * interface that uses the {@link RepositoryAccessServlet} to locate
+ * interface that uses a {@link CredentialsProvider} to locate
  * credentials in the request, log into the respository, and provide
  * a {@link DavSession} to the request.
  */
 public class DavSessionProviderImpl implements DavSessionProvider {
 
     /**
+     * the repository
+     */
+    private final Repository repository;
+
+    /**
+     * the credentials provider
+     */
+    private final SessionProvider sesProvider;
+
+    /**
+     * Creates a new DavSessionProviderImpl
+     * @param rep
+     * @param sesProvider
+     */
+    public DavSessionProviderImpl(Repository rep, SessionProvider sesProvider) {
+        this.repository = rep;
+        this.sesProvider = sesProvider;
+    }
+
+    /**
      * Acquires a DavSession. Upon success, the WebdavRequest will
      * reference that session.
      *
@@ -38,20 +59,18 @@
      *
      * @param request
      * @throws DavException if a problem occurred while obtaining the session
-     * @see DavSessionProvider#acquireSession(org.apache.jackrabbit.webdav.WebdavRequest)
+     * @see DavSessionProvider#attachSession(org.apache.jackrabbit.webdav.WebdavRequest)
      */
-    public void acquireSession(WebdavRequest request) throws DavException {
+    public boolean attachSession(WebdavRequest request) throws DavException {
         try {
-            // extract credentials from the auth header. depending of the
-            // configuration of the RepositoryAccessServlet, this could also
-            // throw a login excetpion.
-            Credentials creds = RepositoryAccessServlet.getCredentialsFromHeader(
-                    request.getHeader(DavConstants.HEADER_AUTHORIZATION));
-
             // login to repository
-            Session repSession = RepositoryAccessServlet.getRepository().login(creds);
+            Session repSession = sesProvider.getSession(request, repository, null);
+            if (repSession == null) {
+                return false;
+            }
             DavSession ds = new DavSessionImpl(repSession);
             request.setDavSession(ds);
+            return true;
         } catch (LoginException e) {
 	    throw new JcrDavException(e);
         } catch (RepositoryException e) {



Mime
View raw message