jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r559335 - in /jackrabbit/trunk: jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ jackrabbit-webapp/src/main/webapp/WEB-INF/
Date Wed, 25 Jul 2007 06:45:53 GMT
Author: angela
Date: Tue Jul 24 23:45:52 2007
New Revision: 559335

URL: http://svn.apache.org/viewvc?view=rev&rev=559335
Log:
JCR-388: add support for RFC 3253 to the simple server

Added:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHandler.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHistoryHandler.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DeltaVResourceImpl.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionControlledResourceImpl.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
    jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java?view=diff&rev=559335&r1=559334&r2=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultHandler.java Tue Jul 24 23:45:52 2007
@@ -543,8 +543,8 @@
                 Property p = it.nextProperty();
                 String name = p.getName();
                 PropertyDefinition def = p.getDefinition();
-                if (def.isMultiple()) {
-                    log.debug("Multivalued property '" + name + "' not added to webdav property set.");
+                if (def.isMultiple() || isDefinedByFilteredNodeType(def)) {
+                    log.debug("Skip property '" + name + "': not added to webdav property set.");
                     continue;
                 }
                 if (JcrConstants.JCR_DATA.equals(name)
@@ -708,5 +708,13 @@
             contentNode.getProperty(jcrName).remove();
         }
         // removal of non existing property succeeds
+    }
+
+    private static boolean isDefinedByFilteredNodeType(PropertyDefinition def) {
+        String ntName = def.getDeclaringNodeType().getName();
+        return ntName.equals(JcrConstants.NT_BASE)
+               || ntName.equals(JcrConstants.MIX_REFERENCEABLE)
+               || ntName.equals(JcrConstants.MIX_VERSIONABLE)
+               || ntName.equals(JcrConstants.MIX_LOCKABLE);
     }
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java?view=diff&rev=559335&r1=559334&r2=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DefaultIOManager.java Tue Jul 24 23:45:52 2007
@@ -51,6 +51,8 @@
     /**
      * Add the predefined <code>IOHandler</code>s to this manager. This includes
      * <ul>
+     * <li>{@link VersionHistoryHandler}</li>
+     * <li>{@link VersionHandler}</li>
      * <li>{@link ZipHandler}</li>
      * <li>{@link XmlHandler}</li>
      * <li>{@link DirListingExportHandler}</li>
@@ -58,9 +60,11 @@
      * </ul>
      */
     protected void init() {
+        addIOHandler(new VersionHistoryHandler(this));
+        addIOHandler(new VersionHandler(this));
         addIOHandler(new ZipHandler(this));
         addIOHandler(new XmlHandler(this));
         addIOHandler(new DirListingExportHandler(this));
         addIOHandler(new DefaultHandler(this));
     }
-}
\ No newline at end of file
+}

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHandler.java?view=auto&rev=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHandler.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHandler.java Tue Jul 24 23:45:52 2007
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.server.io;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.Version;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class VersionHandler extends DefaultHandler implements IOHandler{
+
+    private static Logger log = LoggerFactory.getLogger(VersionHandler.class);
+
+    public VersionHandler() {
+    }
+
+    public VersionHandler(IOManager ioManager) {
+        super(ioManager);
+    }
+
+    //----------------------------------------------------------< IOHandler >---
+    public boolean canImport(ImportContext context, boolean isCollection) {
+        // version node is read only.
+        return false;
+    }
+
+    public boolean canImport(ImportContext context, DavResource resource) {
+        // version node is read only.
+        return false;
+    }
+
+    public boolean importContent(ImportContext context, boolean isCollection) throws IOException {
+        // version node is read only.
+        return false;
+    }
+
+    public boolean importContent(ImportContext context, DavResource resource) throws IOException {
+        // version node is read only.
+        return false;
+    }
+
+    /**
+     * @param context
+     * @param isCollection
+     * @return true if the export root is a <code>Version</code> node. False otherwise.
+     */
+    public boolean canExport(ExportContext context, boolean isCollection) {
+        if (context == null) {
+            return false;
+        }
+        return context.getExportRoot() instanceof Version;
+    }
+
+    /**
+     * @return true if the export root is a <code>Version</code> node. False otherwise.
+     * @see IOHandler#canExport(ExportContext, DavResource)
+     */
+    public boolean canExport(ExportContext context, DavResource resource) {
+        if (context == null) {
+            return false;
+        }
+        return context.getExportRoot() instanceof Version;
+    }
+
+    //----------------------------------------------------< PropertyHandler >---
+    public boolean canImport(PropertyImportContext context, boolean isCollection) {
+        // version is read only
+        return false;
+    }
+
+    public Map importProperties(PropertyImportContext importContext, boolean isCollection) throws RepositoryException {
+        // version is read only
+        throw new RepositoryException("Properties cannot be imported");
+    }
+
+    /**
+     * @see PropertyHandler#exportProperties(PropertyExportContext, boolean)
+     */
+    public boolean exportProperties(PropertyExportContext exportContext, boolean isCollection) throws RepositoryException {
+        if (!canExport(exportContext, isCollection)) {
+            throw new RepositoryException("PropertyHandler " + getName() + " failed to export properties.");
+        }
+        Node cn = getContentNode(exportContext, isCollection);
+        try {
+            // export the properties common with normal IO handling
+            exportProperties(exportContext, isCollection, cn);
+            // BUT don't export the special properties defined by nt:version
+            return true;
+        } catch (IOException e) {
+            // should not occur (log output see 'exportProperties')
+            return false;
+        }
+    }
+
+    /**
+     * Retrieves the content node that contains the data to be exported.
+     *
+     * @param context
+     * @param isCollection
+     * @return content node used for the export
+     * @throws javax.jcr.RepositoryException
+     */
+    protected Node getContentNode(ExportContext context, boolean isCollection) throws RepositoryException {
+        Node node = (Node)context.getExportRoot();
+        Node frozenNode = node.getNode(JcrConstants.JCR_FROZENNODE);
+        if (frozenNode.hasNode(JcrConstants.JCR_CONTENT)) {
+            return frozenNode.getNode(JcrConstants.JCR_CONTENT);
+        } else {
+            return frozenNode;
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHistoryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHistoryHandler.java?view=auto&rev=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHistoryHandler.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHistoryHandler.java Tue Jul 24 23:45:52 2007
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.server.io;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.webdav.DavResource;
+
+import javax.jcr.version.VersionHistory;
+import javax.jcr.RepositoryException;
+import javax.jcr.Item;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * <code>VersionHistoryHandler</code>...
+ */
+public class VersionHistoryHandler implements IOHandler, PropertyHandler {
+
+    private static Logger log = LoggerFactory.getLogger(VersionHistoryHandler.class);
+
+    private IOManager ioManager;
+
+    public VersionHistoryHandler() {
+    }
+
+    public VersionHistoryHandler(IOManager ioManager) {
+        this.ioManager = ioManager;
+    }
+
+    //----------------------------------------------------------< IOHandler >---
+    public IOManager getIOManager() {
+        return ioManager;
+    }
+
+    public void setIOManager(IOManager ioManager) {
+        this.ioManager = ioManager;
+    }
+
+    public String getName() {
+        return getClass().getName();
+    }
+
+    public boolean canImport(ImportContext context, boolean isCollection) {
+        return false;
+    }
+
+    public boolean canImport(ImportContext context, DavResource resource) {
+        return false;
+    }
+
+    public boolean importContent(ImportContext context, boolean isCollection) throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean importContent(ImportContext context, DavResource resource) throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean canExport(ExportContext context, boolean isCollection) {
+        if (context == null) {
+            return false;
+        }
+        return context.getExportRoot() instanceof VersionHistory;
+    }
+
+    public boolean canExport(ExportContext context, DavResource resource) {
+        if (context == null) {
+            return false;
+        }
+        return context.getExportRoot() instanceof VersionHistory;
+    }
+
+    public boolean exportContent(ExportContext context, boolean isCollection) throws IOException {
+        Item exportRoot = context.getExportRoot();
+        if (exportRoot instanceof VersionHistory) {
+            return export(context);
+        } else {
+            return false;
+        }
+    }
+
+    public boolean exportContent(ExportContext context, DavResource resource) throws IOException {
+        Item exportRoot = context.getExportRoot();
+        if (exportRoot instanceof VersionHistory) {
+            return export(context);
+        } else {
+            return false;
+        }
+    }
+
+    //----------------------------------------------------< PropertyHandler >---
+    public boolean canImport(PropertyImportContext context, boolean isCollection) {
+        return false;
+    }
+
+    public Map importProperties(PropertyImportContext importContext, boolean isCollection) throws RepositoryException {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean canExport(PropertyExportContext context, boolean isCollection) {
+        return canExport((ExportContext) context, isCollection);
+    }
+
+    public boolean exportProperties(PropertyExportContext exportContext, boolean isCollection) throws RepositoryException {
+        if (!canExport(exportContext, isCollection)) {
+            throw new RepositoryException("PropertyHandler " + getName() + " failed to export properties.");
+        }
+        return export(exportContext);
+    }
+
+    //--------------------------------------------------------------------------
+    private boolean export(ExportContext exportContext) {
+        // don't export any properties of the version history node. deltaV
+        // defines a fix set of properties to be exported and the dav-resource
+        // needs to take care of those.
+        exportContext.setContentLength(0);
+        exportContext.setModificationTime(IOUtil.UNDEFINED_TIME);
+        return true;
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHistoryHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/VersionHistoryHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java?view=diff&rev=559335&r1=559334&r2=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java Tue Jul 24 23:45:52 2007
@@ -17,20 +17,19 @@
 package org.apache.jackrabbit.webdav.simple;
 
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.server.io.AbstractExportContext;
+import org.apache.jackrabbit.server.io.DefaultIOListener;
 import org.apache.jackrabbit.server.io.ExportContext;
 import org.apache.jackrabbit.server.io.ExportContextImpl;
+import org.apache.jackrabbit.server.io.IOListener;
 import org.apache.jackrabbit.server.io.IOManager;
 import org.apache.jackrabbit.server.io.IOUtil;
 import org.apache.jackrabbit.server.io.ImportContext;
 import org.apache.jackrabbit.server.io.ImportContextImpl;
-import org.apache.jackrabbit.server.io.PropertyManager;
-import org.apache.jackrabbit.server.io.PropertyImportContext;
-import org.apache.jackrabbit.server.io.IOListener;
 import org.apache.jackrabbit.server.io.PropertyExportContext;
-import org.apache.jackrabbit.server.io.AbstractExportContext;
-import org.apache.jackrabbit.server.io.DefaultIOListener;
+import org.apache.jackrabbit.server.io.PropertyImportContext;
+import org.apache.jackrabbit.server.io.PropertyManager;
 import org.apache.jackrabbit.util.Text;
-import org.apache.jackrabbit.webdav.DavConstants;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavResource;
 import org.apache.jackrabbit.webdav.DavResourceFactory;
@@ -52,15 +51,14 @@
 import org.apache.jackrabbit.webdav.lock.Scope;
 import org.apache.jackrabbit.webdav.lock.SupportedLock;
 import org.apache.jackrabbit.webdav.lock.Type;
-import org.apache.jackrabbit.webdav.observation.ObservationConstants;
 import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertyIterator;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameIterator;
 import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
 import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
 import org.apache.jackrabbit.webdav.property.ResourceType;
-import org.apache.jackrabbit.webdav.property.DavPropertyNameIterator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -71,15 +69,15 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.lock.Lock;
+
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Collections;
 
 /**
  * DavResourceImpl implements a DavResource.
@@ -91,21 +89,14 @@
      */
     private static final Logger log = LoggerFactory.getLogger(DavResourceImpl.class);
 
-    private static final HashMap reservedNamespaces = new HashMap();
-
-    static {
-        reservedNamespaces.put(DavConstants.NAMESPACE.getPrefix(), DavConstants.NAMESPACE.getURI());
-        reservedNamespaces.put(ObservationConstants.NAMESPACE.getPrefix(), ObservationConstants.NAMESPACE.getURI());
-    }
-
     private DavResourceFactory factory;
     private LockManager lockManager;
     private JcrDavSession session;
     private Node node;
     private DavResourceLocator locator;
 
-    private DavPropertySet properties = new DavPropertySet();
-    private boolean inited = false;
+    protected DavPropertySet properties = new DavPropertySet();
+    protected boolean propsInitialized = false;
     private boolean isCollection = true;
 
     private ItemFilter filter;
@@ -120,6 +111,7 @@
      * @param locator
      * @param factory
      * @param session
+     * @deprecated
      */
     public DavResourceImpl(DavResourceLocator locator, DavResourceFactory factory,
                            DavSession session, ResourceConfig config) throws DavException {
@@ -151,6 +143,57 @@
     }
 
     /**
+     * Create a new {@link DavResource}.
+     *
+     * @param locator
+     * @param factory
+     * @param session
+     * @param config
+     * @param isCollection
+     * @throws DavException
+     */
+    public DavResourceImpl(DavResourceLocator locator, DavResourceFactory factory,
+                           DavSession session, ResourceConfig config,
+                           boolean isCollection) throws DavException {
+        this(locator, factory, session, config, null);
+        this.isCollection = isCollection;
+    }
+    
+    /**
+     * Create a new {@link DavResource}.
+     *
+     * @param locator
+     * @param factory
+     * @param session
+     * @param config
+     * @param node
+     * @throws DavException
+     */
+    public DavResourceImpl(DavResourceLocator locator, DavResourceFactory factory,
+                           DavSession session, ResourceConfig config, Node node) throws DavException {
+        if (locator == null || session == null || config == null) {
+            throw new IllegalArgumentException();
+        }
+        JcrDavSession.checkImplementation(session);
+        this.session = (JcrDavSession)session;
+        this.factory = factory;
+        this.locator = locator;
+        this.filter = config.getItemFilter();
+        this.ioManager = config.getIOManager();
+        this.propManager = config.getPropertyManager();
+
+        if (locator.getResourcePath() != null) {
+            if (node != null) {
+                this.node = node;
+                // define what is a collection in webdav
+                isCollection = config.isCollectionResource(node);
+            }
+        } else {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+    }
+
+    /**
      * @return DavResource#COMPLIANCE_CLASS
      * @see org.apache.jackrabbit.webdav.DavResource#getComplianceClass()
      */
@@ -185,6 +228,7 @@
      * represents a collection or not.
      *
      * @param isCollection
+     * @deprecated Use the constructor taking a boolean flag instead.
      */
     void setIsCollection(boolean isCollection) {
         this.isCollection = isCollection;
@@ -283,7 +327,7 @@
      * Fill the set of properties
      */
     protected void initProperties() {
-        if (!exists() || inited) {
+        if (!exists() || propsInitialized) {
             return;
         }
 
@@ -316,7 +360,7 @@
         supportedLock.addEntry(Type.WRITE, Scope.EXCLUSIVE);
         properties.add(supportedLock);
 
-        inited = true;
+        propsInitialized = true;
     }
 
     /**
@@ -501,12 +545,14 @@
         if (isLocked(this) || isLocked(member)) {
             throw new DavException(DavServletResponse.SC_LOCKED);
         }
-        // don't allow creation of nodes, that would be filtered out
-        if (isFilteredResource(member)) {
-            log.debug("Avoid creation of filtered resource: " + member.getDisplayName());
-            throw new DavException(DavServletResponse.SC_FORBIDDEN);
-        }
         try {
+            // don't allow creation of nodes if this resource represents a protected
+            // item or if the new resource would be filtered out
+            if (isFilteredResource(member) || node.getDefinition().isProtected()) {
+                log.debug("Forbidden to add member: " + member.getDisplayName());
+                throw new DavException(DavServletResponse.SC_FORBIDDEN);
+            }
+
             String memberName = Text.getName(member.getLocator().getRepositoryPath());
             ImportContext ctx = getImportContext(inputContext, memberName);
             if (!ioManager.importContent(ctx, member)) {

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DeltaVResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DeltaVResourceImpl.java?view=auto&rev=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DeltaVResourceImpl.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DeltaVResourceImpl.java Tue Jul 24 23:45:52 2007
@@ -0,0 +1,255 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav.simple;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.DavCompliance;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.HrefProperty;
+import org.apache.jackrabbit.webdav.version.DeltaVConstants;
+import org.apache.jackrabbit.webdav.version.DeltaVResource;
+import org.apache.jackrabbit.webdav.version.OptionsInfo;
+import org.apache.jackrabbit.webdav.version.OptionsResponse;
+import org.apache.jackrabbit.webdav.version.report.Report;
+import org.apache.jackrabbit.webdav.version.report.ReportInfo;
+import org.apache.jackrabbit.webdav.version.report.ReportType;
+import org.apache.jackrabbit.webdav.version.report.SupportedReportSetProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The <code>DeltaVResourceImpl</code> encapsultes the functionality common to all
+ * DeltaV compliant resources.
+ */
+public class DeltaVResourceImpl extends DavResourceImpl implements DeltaVResource {
+
+    protected SupportedReportSetProperty supportedReports = new SupportedReportSetProperty();
+    private static final Logger log = LoggerFactory.getLogger(DeltaVResourceImpl.class);
+
+
+    public DeltaVResourceImpl(DavResourceLocator locator, DavResourceFactory factory, DavSession session, ResourceConfig config, Item item) throws DavException {
+        super(locator, factory, session, config, (Node)item);
+        initSupportedReports();
+    }
+
+    public DeltaVResourceImpl(DavResourceLocator locator, DavResourceFactory factory, DavSession session, ResourceConfig config, boolean isCollection) throws DavException {
+        super(locator, factory, session, config, isCollection);
+        initSupportedReports();
+    }
+
+    //---------------------------------------------------------< DavResource>---
+    /**
+     * @return DavResource#COMPLIANCE_CLASS
+     * @see org.apache.jackrabbit.webdav.DavResource#getComplianceClass()
+     */
+    public String getComplianceClass() {
+        return DavCompliance.concatComplianceClasses(new String[] {
+                DavCompliance._1_,
+                DavCompliance._2_,
+                DavCompliance.VERSION_CONTROL,
+                DavCompliance.VERSION_HISTORY,
+                DavCompliance.LABEL
+        });
+    }
+
+    //------------------------------------------------------< DeltaVResource>---
+    /**
+     * @param optionsInfo
+     * @return object to be used in the OPTIONS response body or <code>null</code>
+     * @see DeltaVResource#getOptionResponse(org.apache.jackrabbit.webdav.version.OptionsInfo)
+     */
+    public OptionsResponse getOptionResponse(OptionsInfo optionsInfo) {
+        OptionsResponse oR = null;
+        if (optionsInfo != null) {
+            oR = new OptionsResponse();
+            // currently only DAV:version-history-collection-set is supported
+            if (optionsInfo.containsElement(DeltaVConstants.XML_VH_COLLECTION_SET, DeltaVConstants.NAMESPACE)) {
+                String[] hrefs = new String[] {
+                    getLocatorFromNodePath("/"+JcrConstants.JCR_SYSTEM+"/"+JcrConstants.JCR_VERSIONSTORAGE).getHref(true)
+                };
+                oR.addEntry(DeltaVConstants.XML_VH_COLLECTION_SET, DeltaVConstants.NAMESPACE, hrefs);
+            }
+        }
+        return oR;
+    }
+
+    /**
+     * @param reportInfo
+     * @return the requested report
+     * @throws DavException
+     * @see DeltaVResource#getReport(org.apache.jackrabbit.webdav.version.report.ReportInfo)
+     */
+    public Report getReport(ReportInfo reportInfo) throws DavException {
+        if (reportInfo == null) {
+            throw new DavException(DavServletResponse.SC_BAD_REQUEST, "A REPORT request must provide a valid XML request body.");
+        }
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+
+        if (supportedReports.isSupportedReport(reportInfo)) {
+            Report report = ReportType.getType(reportInfo).createReport(this, reportInfo);
+            return report;
+        } else {
+            throw new DavException(DavServletResponse.SC_UNPROCESSABLE_ENTITY, "Unkown report "+ reportInfo.getReportName() +"requested.");
+        }
+    }
+
+    /**
+     * The JCR api does not provide methods to create new workspaces. Calling
+     * <code>addWorkspace</code> on this resource will always fail.
+     *
+     * @param workspace
+     * @throws DavException Always throws.
+     * @see DeltaVResource#addWorkspace(org.apache.jackrabbit.webdav.DavResource)
+     */
+    public void addWorkspace(DavResource workspace) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Return an array of <code>DavResource</code> objects that are referenced
+     * by the property with the specified name.
+     *
+     * @param hrefPropertyName
+     * @return array of <code>DavResource</code>s
+     * @throws DavException
+     * @see DeltaVResource#getReferenceResources(org.apache.jackrabbit.webdav.property.DavPropertyName)
+     */
+    public DavResource[] getReferenceResources(DavPropertyName hrefPropertyName) throws DavException {
+        DavProperty prop = getProperty(hrefPropertyName);
+        List resources = new ArrayList();
+        if (prop != null && prop instanceof HrefProperty) {
+            HrefProperty hp = (HrefProperty)prop;
+            // process list of hrefs 
+            List hrefs = hp.getHrefs();
+            for (Iterator iter = hrefs.iterator(); iter.hasNext();) {
+                String href = (String)iter.next();
+                DavResourceLocator locator = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), href);
+                resources.add(createResourceFromLocator(locator));
+            }
+        } else {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+        }
+        return (DavResource[])resources.toArray(new DavResource[0]);
+    }
+
+    /**
+     * Build a <code>DavResourceLocator</code> from the given nodePath path.
+     *
+     * @param nodePath
+     * @return a new <code>DavResourceLocator</code>
+     * @see DavLocatorFactory#createResourceLocator(String, String, String)
+     */
+    protected DavResourceLocator getLocatorFromNodePath(String nodePath) {
+        DavResourceLocator loc = getLocator().getFactory().createResourceLocator(getLocator().getPrefix(), getLocator().getWorkspacePath(), nodePath, false);
+        return loc;
+    }
+
+
+    /**
+     * Build a new {@link DavResourceLocator} from the given repository node.
+     *
+     * @param repositoryNode
+     * @return a new locator for the specified node.
+     * @see #getLocatorFromNodePath(String)
+     */
+    protected DavResourceLocator getLocatorFromNode(Node repositoryNode) {
+        String nodePath = null;
+        try {
+            if (repositoryNode != null) {
+                nodePath = repositoryNode.getPath();
+            }
+        } catch (RepositoryException e) {
+            // ignore: should not occur
+            log.warn(e.getMessage());
+        }
+        return getLocatorFromNodePath(nodePath);
+    }
+
+    /**
+     * Create a new <code>DavResource</code> from the given locator.
+     * @param loc
+     * @return new <code>DavResource</code>
+     */
+    protected DavResource createResourceFromLocator(DavResourceLocator loc)
+            throws DavException {
+        DavResource res = getFactory().createResource(loc, getSession());
+        return res;
+    }
+
+    /**
+     * Returns a {@link org.apache.jackrabbit.webdav.property.HrefProperty} with the
+     * specified property name and values. Each node present in the specified
+     * array is referenced in the resulting property.
+     *
+     * @param name
+     * @param values
+     * @param isProtected
+     * @return HrefProperty
+     */
+    protected HrefProperty getHrefProperty(DavPropertyName name, Node[] values,
+                                           boolean isProtected, boolean isCollection) {
+        if (values == null) {
+            return null;
+        }
+        String[] pHref = new String[values.length];
+        for (int i = 0; i < values.length; i++) {
+            pHref[i] = getLocatorFromNode(values[i]).getHref(isCollection);
+        }
+        return new HrefProperty(name, pHref, isProtected);
+    }
+
+    /**
+     * Initialize the supported reports field
+     */
+    protected void initSupportedReports() {
+        if (exists()) {
+            supportedReports.addReportType(ReportType.EXPAND_PROPERTY);
+            if (isCollection()) {
+                supportedReports.addReportType(ReportType.LOCATE_BY_HISTORY);
+            }
+        }
+    }
+
+    /**
+     * Fill the property set for this resource.
+     */
+    protected void initProperties() {
+        if (!propsInitialized) {
+            super.initProperties();
+            if (exists()) {
+                properties.add(supportedReports);
+            }
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DeltaVResourceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/DeltaVResourceImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java?view=diff&rev=559335&r1=559334&r2=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java Tue Jul 24 23:45:52 2007
@@ -24,13 +24,27 @@
 import org.apache.jackrabbit.webdav.DavServletRequest;
 import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.jcr.JcrDavSession;
 import org.apache.jackrabbit.webdav.lock.LockManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
 
 /**
  * ResourceFactoryImpl implements a simple DavResourceFactory
  */
 public class ResourceFactoryImpl implements DavResourceFactory {
 
+    private static Logger log =LoggerFactory.getLogger(ResourceFactoryImpl.class);
+
     private final LockManager lockMgr;
     private final ResourceConfig resourceConfig;
 
@@ -64,18 +78,28 @@
      * @param locator
      * @param request
      * @param response
-     * @return
+     * @return DavResource
      * @throws DavException
      * @see DavResourceFactory#createResource(DavResourceLocator,
      *      DavServletRequest, DavServletResponse)
      */
     public DavResource createResource(DavResourceLocator locator, DavServletRequest request,
                                       DavServletResponse response) throws DavException {
-        DavResourceImpl resource = (DavResourceImpl)createResource(locator, request.getDavSession());
-        if (DavMethods.isCreateRequest(request) && ! resource.exists()) {
-            resource.setIsCollection(DavMethods.isCreateCollectionRequest(request));
+        try {
+            Node node = getNode(request.getDavSession(), locator);
+            DavResource resource;
+            if (node == null) {
+                log.debug("Creating resource for non-existing repository node.");
+                boolean isCollection = DavMethods.isCreateCollectionRequest(request);
+                resource = createNullResource(locator, request.getDavSession(), isCollection);
+            } else {
+                resource = createResource(node, locator, request.getDavSession());
+            }
+            resource.addLockManager(lockMgr);
+            return resource;
+        } catch (RepositoryException e) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
         }
-        return resource;
     }
 
     /**
@@ -89,8 +113,103 @@
      * @see DavResourceFactory#createResource(DavResourceLocator, DavSession)
      */
     public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
-        DavResourceImpl res = new DavResourceImpl(locator, this, session, resourceConfig);
-        res.addLockManager(lockMgr);
-        return res;
+        try {
+            Node node = getNode(session, locator);
+            DavResource resource = createResource(node, locator, session);
+            resource.addLockManager(lockMgr);
+            return resource;
+        } catch (RepositoryException e) {
+            throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
+        }
+    }
+
+    /**
+     * Returns the <code>Node</code> corresponding to the given locator or
+     * <code>null</code> if it does not exist or if the existing item represents
+     * a <code>Property</code>.
+     *
+     * @param sessionImpl
+     * @param locator
+     * @return
+     * @throws RepositoryException
+     */
+    private Node getNode(DavSession sessionImpl, DavResourceLocator locator)
+            throws RepositoryException {
+        Node node = null;
+        try {
+            Item item = ((JcrDavSession)sessionImpl).getRepositorySession().getItem(locator.getRepositoryPath());
+            if (item instanceof Node) {
+                node = (Node)item;
+            } // else: item is a property -> return null
+        } catch (PathNotFoundException e) {
+            // item does not exist (yet) -> create null-resource
+            node = null;
+        }
+        return node;
+    }
+
+    /**
+     * Create a 'null resource'
+     *
+     * @param locator
+     * @param session
+     * @param request
+     * @return
+     * @throws DavException
+     */
+    private DavResource createNullResource(DavResourceLocator locator,
+                                           DavSession session,
+                                           boolean isCollection) throws DavException {
+        JcrDavSession.checkImplementation(session);
+        JcrDavSession sessionImpl = (JcrDavSession)session;
+
+        DavResource resource;
+        if (versioningSupported(sessionImpl.getRepositorySession())) {
+            resource = new VersionControlledResourceImpl(locator, this, sessionImpl, resourceConfig, isCollection);
+        } else {
+            resource = new DavResourceImpl(locator, this, sessionImpl, resourceConfig, isCollection);
+        }
+        return resource;
+    }
+
+    /**
+     * Tries to retrieve the repository item defined by the locator's resource
+     * path and build the corresponding WebDAV resource. If the repository
+     * supports the versioning option different resources are created for
+     * version, versionhistory and common nodes.
+     *
+     * @param locator
+     * @param sessionImpl
+     * @return DavResource representing a repository item.
+     * @throws RepositoryException if {@link javax.jcr.Session#getItem(String)} fails.
+     */
+    private DavResource createResource(Node node, DavResourceLocator locator,
+                                       DavSession session) throws DavException {
+        JcrDavSession.checkImplementation(session);
+        JcrDavSession sessionImpl = (JcrDavSession)session;
+
+        DavResource resource;
+        if (versioningSupported(sessionImpl.getRepositorySession())) {
+            // create special resources for Version and VersionHistory
+            if (node instanceof Version) {
+                resource = new VersionResourceImpl(locator, this, sessionImpl, resourceConfig, node);
+            }  else if (node instanceof VersionHistory) {
+                resource = new VersionHistoryResourceImpl(locator, this, sessionImpl, resourceConfig, node);
+            } else {
+                resource = new VersionControlledResourceImpl(locator, this, sessionImpl, resourceConfig, node);
+            }
+        } else {
+            resource = new DavResourceImpl(locator, this, session, resourceConfig, node);
+        }
+        return resource;
+    }
+
+    /**
+     * @param repoSession
+     * @return true if the JCR repository supports versioning.
+     */
+    private static boolean versioningSupported(Session repoSession) {
+        String desc = repoSession.getRepository().getDescriptor(Repository.OPTION_VERSIONING_SUPPORTED);
+        return Boolean.valueOf(desc).booleanValue();
     }
 }

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionControlledResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionControlledResourceImpl.java?view=auto&rev=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionControlledResourceImpl.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionControlledResourceImpl.java Tue Jul 24 23:45:52 2007
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav.simple;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.MultiStatus;
+import org.apache.jackrabbit.webdav.DavMethods;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
+import org.apache.jackrabbit.webdav.property.HrefProperty;
+import org.apache.jackrabbit.webdav.version.LabelInfo;
+import org.apache.jackrabbit.webdav.version.MergeInfo;
+import org.apache.jackrabbit.webdav.version.UpdateInfo;
+import org.apache.jackrabbit.webdav.version.VersionControlledResource;
+import org.apache.jackrabbit.webdav.version.VersionHistoryResource;
+import org.apache.jackrabbit.webdav.version.VersionResource;
+import org.apache.jackrabbit.webdav.version.VersionableResource;
+import org.apache.jackrabbit.webdav.version.report.ReportType;
+import org.apache.jackrabbit.webdav.version.report.SupportedReportSetProperty;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+
+/**
+ * <code>VersionControlledResourceImpl</code> represents a JCR node item and
+ * covers all functionality related to versioning of {@link Node}s.
+ *
+ * @see Node
+ */
+public class VersionControlledResourceImpl extends DeltaVResourceImpl
+        implements VersionControlledResource {
+
+    private static final Logger log = LoggerFactory.getLogger(VersionControlledResourceImpl.class);
+
+    /**
+     * Create a new {@link org.apache.jackrabbit.webdav.DavResource}.
+     *
+     * @param locator
+     * @param factory
+     * @param session
+     * @param config 
+     * @param item 
+     * @throws DavException
+     */
+    public VersionControlledResourceImpl(DavResourceLocator locator, DavResourceFactory factory, DavSession session, ResourceConfig config, Item item) throws DavException {
+        super(locator, factory, session, config, item);
+        initSupportedReports();
+    }
+
+    /**
+     * Create a new {@link org.apache.jackrabbit.webdav.DavResource}.
+     *
+     * @param locator
+     * @param factory
+     * @param session
+     * @param config 
+     * @param isCollection 
+     * @throws DavException 
+     */
+    public VersionControlledResourceImpl(DavResourceLocator locator, DavResourceFactory factory, DavSession session, ResourceConfig config, boolean isCollection) throws DavException {
+        super(locator, factory, session, config, isCollection);
+        initSupportedReports();
+    }
+
+    //--------------------------------------------------------< DavResource >---
+    /**
+     * Return a comma separated string listing the supported method names.
+     *
+     * @return the supported method names.
+     * @see org.apache.jackrabbit.webdav.DavResource#getSupportedMethods()
+     */
+    public String getSupportedMethods() {
+        StringBuffer sb = new StringBuffer(super.getSupportedMethods());
+        // Versioning support
+        sb.append(", ").append(VersionableResource.METHODS);
+        if (isVersionControlled()) {
+            try {
+                if (getNode().isCheckedOut()) {
+                    sb.append(", ").append(DavMethods.METHOD_CHECKIN);
+                } else {
+                    sb.append(", ").append(DavMethods.METHOD_CHECKOUT);
+                    sb.append(", ").append(DavMethods.METHOD_LABEL);
+                }
+            } catch (RepositoryException e) {
+                // should not occur.
+                log.error(e.getMessage());
+            }
+        }
+        return sb.toString();
+    }
+
+    //------------------------------------------< VersionControlledResource >---
+    /**
+     * Adds version control to this resource. If the resource is already under
+     * version control, this method has no effect. If this resource is a Collection
+     * resource this method fails with {@link DavServletResponse#SC_METHOD_NOT_ALLOWED}.
+     *
+     * @throws org.apache.jackrabbit.webdav.DavException if this resource does not
+     * exist yet, is a collection or if an error occurs while making the
+     * underlying node versionable.
+     * @see org.apache.jackrabbit.webdav.version.VersionableResource#addVersionControl()
+     */
+    public void addVersionControl() throws DavException {
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+        if (isCollection()) {
+            // since the version-controlled-collection feature is not supported
+            // collections may not be put under dav version control even if
+            // the underlaying node was / could be made jcr versionable.
+            throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
+        }
+        if (!isVersionControlled()) {
+            Node item = getNode();
+            try {
+                item.addMixin(JcrConstants.MIX_VERSIONABLE);
+                item.save();
+            } catch (RepositoryException e) {
+                throw new JcrDavException(e);
+            }
+        } // else: is already version controlled -> ignore
+    }
+
+    /**
+     * Calls {@link javax.jcr.Node#checkin()} on the underlying repository node.
+     *
+     * @throws org.apache.jackrabbit.webdav.DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#checkin()
+     */
+    public String checkin() throws DavException {
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+        if (!isVersionControlled()) {
+            throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
+        }
+        try {
+            Version v = getNode().checkin();
+            String versionHref = getLocatorFromNode(v).getHref(false);
+            return versionHref;
+        } catch (RepositoryException e) {
+            // UnsupportedRepositoryException should not occur
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Calls {@link javax.jcr.Node#checkout()} on the underlying repository node.
+     *
+     * @throws org.apache.jackrabbit.webdav.DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#checkout()
+     */
+    public void checkout() throws DavException {
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+        if (!isVersionControlled()) {
+            throw new DavException(DavServletResponse.SC_METHOD_NOT_ALLOWED);
+        }
+        try {
+            getNode().checkout();
+        } catch (RepositoryException e) {
+            // UnsupportedRepositoryException should not occur
+            throw new JcrDavException(e);
+        }
+    }
+
+
+    /**
+     * UNCHECKOUT cannot be implemented on top of JSR 170 repository.
+     * Therefore this methods always throws a <code>DavException</code> with error code
+     * {@link org.apache.jackrabbit.webdav.DavServletResponse#SC_NOT_IMPLEMENTED}.
+     *
+     * @throws org.apache.jackrabbit.webdav.DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#uncheckout()
+     */
+    public void uncheckout() throws DavException {
+        throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
+    }
+
+    /**
+     * UPDATE feature is not (yet) supported. This method allows fails with
+     * {@link DavServletResponse#SC_NOT_IMPLEMENTED}.
+     *
+     * @param updateInfo
+     * @return
+     * @throws DavException
+     * @see VersionControlledResource#update(UpdateInfo)
+     */
+    public MultiStatus update(UpdateInfo updateInfo) throws DavException {
+        throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
+    }
+
+    /**
+     * MERGE feature is not (yet) supported. This method allows fails with
+     * {@link DavServletResponse#SC_NOT_IMPLEMENTED}.
+     *
+     * @param mergeInfo
+     * @return
+     * @throws DavException
+     * @see VersionControlledResource#merge(MergeInfo)
+     */
+    public MultiStatus merge(MergeInfo mergeInfo) throws DavException {
+        throw new DavException(DavServletResponse.SC_NOT_IMPLEMENTED);
+    }
+
+    /**
+     * Modify the labels present with the versions of this resource.
+     *
+     * @param labelInfo
+     * @throws DavException
+     * @see VersionControlledResource#label(LabelInfo)
+     * @see javax.jcr.version.VersionHistory#addVersionLabel(String, String, boolean)
+     * @see javax.jcr.version.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 {
+            if (!isVersionControlled() || getNode().isCheckedOut()) {
+                throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "A LABEL request may only be applied to a version-controlled, checked-in resource.");
+            }
+            DavResource[] resArr = this.getReferenceResources(CHECKED_IN);
+            if (resArr.length == 1 && resArr[0] instanceof VersionResource) {
+                ((VersionResource)resArr[0]).label(labelInfo);
+            } else {
+                throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, "DAV:checked-in property on '" + getHref() + "' did not point to a single VersionResource.");
+            }
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Returns the {@link javax.jcr.version.VersionHistory} associated with the repository node.
+     * If the node is not versionable an exception is thrown.
+     *
+     * @return the {@link VersionHistoryResource} associated with this resource.
+     * @throws org.apache.jackrabbit.webdav.DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionControlledResource#getVersionHistory()
+     * @see javax.jcr.Node#getVersionHistory()
+     */
+    public VersionHistoryResource getVersionHistory() throws DavException {
+        if (!exists()) {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+        if (!isVersionControlled()) {
+            throw new DavException(DavServletResponse.SC_FORBIDDEN);
+        }
+        try {
+            VersionHistory vh = getNode().getVersionHistory();
+            DavResourceLocator loc = getLocatorFromNode(vh);
+            DavResource vhr =  createResourceFromLocator(loc);
+            if (vhr instanceof VersionHistoryResource) {
+                return (VersionHistoryResource)vhr;
+            } else {
+                // severe error since resource factory doesn't behave correctly.
+                throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+            }
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     * Define the set of reports supported by this resource.
+     *
+     * @see SupportedReportSetProperty
+     * @see DeltaVResourceImpl#initSupportedReports()
+     */
+    protected void initSupportedReports() {
+        super.initSupportedReports();
+        if (exists()) {
+            supportedReports.addReportType(ReportType.LOCATE_BY_HISTORY);
+            if (isVersionControlled()) {
+                supportedReports.addReportType(ReportType.VERSION_TREE);
+            }
+        }
+    }
+
+    /**
+     * Fill the property set for this resource.
+     * @see DavResourceImpl#initProperties()
+     */
+    protected void initProperties() {
+        if (!propsInitialized) {
+            super.initProperties();
+            if (isVersionControlled()) {
+                Node n = getNode();
+                // properties defined by RFC 3253 for version-controlled resources
+                try {
+                    // DAV:version-history (computed)
+                    String vhHref = getLocatorFromNode(n.getVersionHistory()).getHref(true);
+                    properties.add(new HrefProperty(VERSION_HISTORY, vhHref, true));
+
+                    // DAV:auto-version property: there is no auto version, explicit CHECKOUT is required.
+                    properties.add(new DefaultDavProperty(AUTO_VERSION, null, false));
+
+                    // baseVersion -> used for DAV:checked-out or DAV:checked-in
+                    String baseVHref = getLocatorFromNode(n.getBaseVersion()).getHref(false);
+                    if (n.isCheckedOut()) {
+                        // DAV:predecessors property
+                        if (n.hasProperty(JcrConstants.JCR_PREDECESSORS)) {
+                            Value[] pv = n.getProperty(JcrConstants.JCR_PREDECESSORS).getValues();
+                            Node[] predecessors = new Node[pv.length];
+                            for (int i = 0; i < pv.length; i++) {
+                                predecessors[i] = n.getSession().getNodeByUUID(pv[i].getString());
+                            }
+                            properties.add(getHrefProperty(VersionResource.PREDECESSOR_SET, predecessors, false, false));
+                        }
+                        // DAV:checked-out property (protected)
+                        properties.add(new HrefProperty(CHECKED_OUT, baseVHref, true));
+                    } else {
+                        // DAV:checked-in property (protected)
+                        properties.add(new HrefProperty(CHECKED_IN, baseVHref, true));
+                    }
+                } catch (RepositoryException e) {
+                    log.error(e.getMessage());
+                }
+            }
+        }
+    }
+
+    /**
+     * @return true, if this resource is a non-collection resource and represents
+     * an existing repository node that has the mixin nodetype 'mix:versionable' set.
+     */
+    private boolean isVersionControlled() {
+        boolean vc = false;
+        // since the version-controlled-collection feature is not supported
+        // all collection are excluded from version-controll even if the
+        // underlying node was JCR versionable.
+        if (exists() && !isCollection()) {
+            Node item = getNode();
+            try {
+                vc = item.isNodeType(JcrConstants.MIX_VERSIONABLE);
+            } catch (RepositoryException e) {
+                log.warn(e.getMessage());
+            }
+        }
+        return vc;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionControlledResourceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionControlledResourceImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java?view=auto&rev=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java Tue Jul 24 23:45:52 2007
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav.simple;
+
+import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.DavResourceIterator;
+import org.apache.jackrabbit.webdav.DavResourceIteratorImpl;
+import org.apache.jackrabbit.webdav.MultiStatusResponse;
+import org.apache.jackrabbit.webdav.io.InputContext;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.property.HrefProperty;
+import org.apache.jackrabbit.webdav.property.ResourceType;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.version.VersionHistoryResource;
+import org.apache.jackrabbit.webdav.version.VersionResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.Item;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
+import javax.jcr.version.Version;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <code>VersionHistoryResourceImpl</code> represents a JCR version history.
+ *
+ * @see VersionHistory
+ */
+public class VersionHistoryResourceImpl extends DeltaVResourceImpl implements VersionHistoryResource {
+
+    private static final Logger log = LoggerFactory.getLogger(VersionHistoryResourceImpl.class);
+
+    public VersionHistoryResourceImpl(DavResourceLocator locator, DavResourceFactory factory, DavSession session, ResourceConfig config, Item item) throws DavException {
+        super(locator, factory, session, config, item);
+            if (getNode() == null || !(getNode() instanceof VersionHistory)) {
+                throw new IllegalArgumentException("VersionHistory item expected.");
+        }
+    }
+
+    //--------------------------------------------------------< DavResource >---
+    /**
+     * Show all versions of this history as members.
+     *
+     * @return
+     * @see DavResource#getMembers()
+     */
+    public DavResourceIterator getMembers() {
+        ArrayList list = new ArrayList();
+        if (exists() && isCollection()) {
+            try {
+                // only display versions as members of the vh. the jcr:versionLabels
+                // node is an internal structure.
+                VersionIterator it = ((VersionHistory) getNode()).getAllVersions();
+                while (it.hasNext()) {
+                    // omit item filter here. if the version history is visible
+                    // its versions should be visible as well.
+                    Version v = it.nextVersion();
+                    DavResourceLocator vhLocator = getLocator();
+                    DavResourceLocator resourceLocator = vhLocator.getFactory().createResourceLocator(vhLocator.getPrefix(), vhLocator.getWorkspacePath(), v.getPath(), false);
+                    DavResource childRes = getFactory().createResource(resourceLocator, getSession());
+                    list.add(childRes);
+                }
+            } catch (RepositoryException e) {
+                // should not occure
+            } catch (DavException e) {
+                // should not occure
+            }
+        }
+        return new DavResourceIteratorImpl(list);
+    }
+
+    /**
+     * The version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#addMember(DavResource, InputContext)
+     */
+    public void addMember(DavResource member, InputContext inputContext) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * 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) getNode();
+            try {
+                String itemPath = member.getLocator().getRepositoryPath();
+                // Retrieve the last segment of the given path and removes the index if present.
+                if (itemPath == null) {
+                    throw new IllegalArgumentException("Cannot retrieve name from a 'null' item path.");
+                }
+                String name = Text.getName(itemPath);
+                // remove index
+                if (name.endsWith("]")) {
+                    name = name.substring(0, name.lastIndexOf('['));
+                }
+                versionHistory.removeVersion(name);
+            } catch (RepositoryException e) {
+                throw new JcrDavException(e);
+            }
+        } else {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
+        }
+    }
+
+    /**
+     * Version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#setProperty(DavProperty)
+     */
+    public void setProperty(DavProperty property) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#removeProperty(DavPropertyName)
+     */
+    public void removeProperty(DavPropertyName propertyName) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#alterProperties(DavPropertySet, DavPropertyNameSet)
+     */
+    public MultiStatusResponse alterProperties(DavPropertySet setProperties, DavPropertyNameSet removePropertyNames) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#alterProperties(List)
+     */
+    public MultiStatusResponse alterProperties(List changeList) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    //---------------------------------------------< VersionHistoryResource >---
+    /**
+     * Return an array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
+     * present in the underlying JCR version history.
+     *
+     * @return array of {@link org.apache.jackrabbit.webdav.version.VersionResource}s representing all versions
+     * present in the underlying JCR version history.
+     * @throws org.apache.jackrabbit.webdav.DavException
+     * @see org.apache.jackrabbit.webdav.version.VersionHistoryResource#getVersions()
+     */
+    public VersionResource[] getVersions() throws DavException {
+        try {
+            VersionIterator vIter = ((VersionHistory)getNode()).getAllVersions();
+            ArrayList l = new ArrayList();
+            while (vIter.hasNext()) {
+                    DavResourceLocator versionLoc = getLocatorFromNode(vIter.nextVersion());
+                    DavResource vr = createResourceFromLocator(versionLoc);
+                    if (vr instanceof VersionResource) {
+                        l.add(vr);
+                    } else {
+                        // severe error since resource factory doesn't behave correctly.
+                        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+                    }
+            }
+            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() {
+        if (!propsInitialized) {
+            super.initProperties();
+
+            // change resourcetype defined by default item collection
+            properties.add(new ResourceType(new int[] {ResourceType.COLLECTION, ResourceType.VERSION_HISTORY}));
+
+            // required root-version property for version-history resource
+            try {
+                String rootVersionHref = getLocatorFromNode(((VersionHistory)getNode()).getRootVersion()).getHref(false);
+                properties.add(new HrefProperty(VersionHistoryResource.ROOT_VERSION, rootVersionHref, false));
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+
+            // required, protected version-set property for version-history resource
+            try {
+                VersionIterator vIter = ((VersionHistory)getNode()).getAllVersions();
+                ArrayList l = new ArrayList();
+                while (vIter.hasNext()) {
+                    l.add(vIter.nextVersion());
+                }
+                properties.add(getHrefProperty(VersionHistoryResource.VERSION_SET, (Version[]) l.toArray(new Version[l.size()]), true, false));
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionHistoryResourceImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java?view=auto&rev=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java Tue Jul 24 23:45:52 2007
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav.simple;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavSession;
+import org.apache.jackrabbit.webdav.DavResourceIterator;
+import org.apache.jackrabbit.webdav.DavResourceIteratorImpl;
+import org.apache.jackrabbit.webdav.MultiStatusResponse;
+import org.apache.jackrabbit.webdav.io.InputContext;
+import org.apache.jackrabbit.webdav.jcr.JcrDavException;
+import org.apache.jackrabbit.webdav.property.DavPropertyName;
+import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
+import org.apache.jackrabbit.webdav.property.HrefProperty;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
+import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
+import org.apache.jackrabbit.webdav.version.LabelInfo;
+import org.apache.jackrabbit.webdav.version.LabelSetProperty;
+import org.apache.jackrabbit.webdav.version.VersionHistoryResource;
+import org.apache.jackrabbit.webdav.version.VersionResource;
+import org.apache.jackrabbit.webdav.version.report.ReportType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
+
+/**
+ * <code>VersionResourceImpl</code> represents a JCR version.
+ *
+ * @see Version
+ */
+public class VersionResourceImpl extends DeltaVResourceImpl implements VersionResource {
+
+    private static final Logger log = LoggerFactory.getLogger(VersionResourceImpl.class);
+
+    /**
+     * Create a new {@link org.apache.jackrabbit.webdav.DavResource}.
+     * @param locator
+     * @param factory 
+     * @param session 
+     * @param config 
+     * @param item 
+     * @throws DavException 
+     *
+     */
+    public VersionResourceImpl(DavResourceLocator locator, DavResourceFactory factory, DavSession session, ResourceConfig config, Item item) throws DavException {
+        super(locator, factory, session, config, item);
+        if (getNode() == null || !(getNode() instanceof Version)) {
+            throw new IllegalArgumentException("Version item expected.");
+        }
+    }
+
+    //--------------------------------------------------------< DavResource >---
+    /**
+     * Since this implementation of <code>VersionResource</code> never is a
+     * version belonging to a version controlled collection, this method always
+     * returns <code>false</code> not respecting the configuration.
+     *
+     * @return always false
+     */
+    public boolean isCollection() {
+        return false;
+    }
+
+    /**
+     * @return An empty <code>DavResourceIterator</code>
+     */
+    public DavResourceIterator getMembers() {
+        return new DavResourceIteratorImpl(Collections.EMPTY_LIST);
+    }
+
+    /**
+     * The version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#addMember(DavResource, InputContext)
+     */
+    public void addMember(DavResource member, InputContext inputContext) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * The version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#removeMember(DavResource)
+     */
+    public void removeMember(DavResource member) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#setProperty(DavProperty)
+     */
+    public void setProperty(DavProperty property) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#removeProperty(DavPropertyName)
+     */
+    public void removeProperty(DavPropertyName propertyName) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#alterProperties(DavPropertySet, DavPropertyNameSet)
+     */
+    public MultiStatusResponse alterProperties(DavPropertySet setProperties, DavPropertyNameSet removePropertyNames) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    /**
+     * Version storage is read-only -> fails with 403.
+     *
+     * @see DavResource#alterProperties(List)
+     */
+    public MultiStatusResponse alterProperties(List changeList) throws DavException {
+        throw new DavException(DavServletResponse.SC_FORBIDDEN);
+    }
+
+    //----------------------------------------------------< VersionResource >---
+    /**
+     * Modify the labels defined for the underlying repository version.
+     *
+     * @param labelInfo
+     * @throws org.apache.jackrabbit.webdav.DavException
+     * @see VersionResource#label(org.apache.jackrabbit.webdav.version.LabelInfo)
+     * @see javax.jcr.version.VersionHistory#addVersionLabel(String, String, boolean)
+     * @see javax.jcr.version.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(getNode().getName(), labelInfo.getLabelName(), false);
+            } else {
+                // SET: move label if already existing
+                vh.addVersionLabel(getNode().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 org.apache.jackrabbit.webdav.version.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 = getLocatorFromNode(vh);
+            DavResource vhr = createResourceFromLocator(loc);
+            if (vhr instanceof VersionHistoryResource) {
+                return (VersionHistoryResource)vhr;
+            } else {
+                // severe error since resource factory doesn't behave correctly.
+                throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR);
+            }
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
+        }
+    }
+
+    /**
+     * Return versionhistory that contains this version item
+     *
+     * @return versionhistory that contains this version item
+     * @throws RepositoryException
+     * @see javax.jcr.version.Version#getContainingHistory()
+     */
+    private VersionHistory getVersionHistoryItem() throws RepositoryException {
+        return ((Version)getNode()).getContainingHistory();
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     * 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() {
+        if (!propsInitialized) {
+            super.initProperties();
+            Version v = (Version) getNode();
+            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);
+                properties.add(new LabelSetProperty(labels));
+
+                // required DAV:predecessor-set (protected) and DAV:successor-set (computed) properties
+                properties.add(getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true, false));
+                properties.add(getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true, false));
+
+                // required DAV:version-history (computed) property
+                String vhHref = getLocatorFromNode(getVersionHistoryItem()).getHref(true);
+                properties.add(new HrefProperty(VersionResource.VERSION_HISTORY, vhHref, 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);
+                        }
+                    }
+                }
+                properties.add(getHrefProperty(CHECKOUT_SET, (Node[]) nodeList.toArray(new Node[nodeList.size()]), true, false));
+
+            } catch (RepositoryException e) {
+                log.error(e.getMessage());
+            }
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/VersionResourceImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml?view=diff&rev=559335&r1=559334&r2=559335
==============================================================================
--- jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml (original)
+++ jackrabbit/trunk/jackrabbit-webapp/src/main/webapp/WEB-INF/config.xml Tue Jul 24 23:45:52 2007
@@ -56,6 +56,12 @@
         -->
         <class name="org.apache.jackrabbit.server.io.IOManagerImpl" />
         <iohandler>
+            <class name="org.apache.jackrabbit.server.io.VersionHandler" />
+        </iohandler>
+        <iohandler>
+            <class name="org.apache.jackrabbit.server.io.VersionHistoryHandler" />
+        </iohandler>
+        <iohandler>
             <class name="org.apache.jackrabbit.server.io.ZipHandler" />
         </iohandler>
         <iohandler>
@@ -88,6 +94,12 @@
              they appear in the configuration.
         -->
         <class name="org.apache.jackrabbit.server.io.PropertyManagerImpl" />
+        <propertyhandler>
+            <class name="org.apache.jackrabbit.server.io.VersionHandler" />
+        </propertyhandler>
+        <propertyhandler>
+            <class name="org.apache.jackrabbit.server.io.VersionHistoryHandler" />
+        </propertyhandler>
         <propertyhandler>
             <class name="org.apache.jackrabbit.server.io.ZipHandler" />
         </propertyhandler>



Mime
View raw message