jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1686293 - in /jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit: server/io/ webdav/simple/
Date Thu, 18 Jun 2015 19:13:34 GMT
Author: tripod
Date: Thu Jun 18 19:13:34 2015
New Revision: 1686293

URL: http://svn.apache.org/r1686293
Log:
JCR-3884 Add handler to handle webdav based DELETE requests

Added:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContext.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContextImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteHandler.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManager.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManagerImpl.java
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/webdav/simple/DavResourceImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java

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?rev=1686293&r1=1686292&r2=1686293&view=diff
==============================================================================
--- 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
Thu Jun 18 19:13:34 2015
@@ -71,7 +71,7 @@ import java.util.HashMap;
  * Subclasses therefore should provide their own {@link #importData(ImportContext, boolean,
Node)
  * importData} method, that handles the data according their needs.
  */
-public class DefaultHandler implements IOHandler, PropertyHandler, CopyMoveHandler {
+public class DefaultHandler implements IOHandler, PropertyHandler, CopyMoveHandler, DeleteHandler
{
 
     private static Logger log = LoggerFactory.getLogger(DefaultHandler.class);
 
@@ -720,6 +720,35 @@ public class DefaultHandler implements I
             return true;
         } catch (RepositoryException e) {
             throw new JcrDavException(e);
+        }
+    }
+
+    //----------------------------------------------------< DeleteHandler >---
+
+    /**
+     * @see DeleteHandler#canDelete(DeleteContext, DavResource)
+     */
+    public boolean canDelete(DeleteContext deleteContext, DavResource member) {
+        return true;
+    }
+
+    /**
+     * @see DeleteHandler#delete(DeleteContext, DavResource)
+     */
+    public boolean delete(DeleteContext deleteContext, DavResource member) throws DavException
{
+        try {
+            String itemPath = member.getLocator().getRepositoryPath();
+            Item item = deleteContext.getSession().getItem(itemPath);
+            if (item instanceof Node) {
+                ((Node) item).removeShare();
+            } else {
+                item.remove();
+            }
+            deleteContext.getSession().save();
+            log.debug("default handler deleted {}", member.getResourcePath());
+            return true;
+        } catch (RepositoryException e) {
+            throw new JcrDavException(e);
         }
     }
 

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContext.java?rev=1686293&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContext.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContext.java
Thu Jun 18 19:13:34 2015
@@ -0,0 +1,32 @@
+/*
+ * 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 javax.jcr.Session;
+
+/**
+ * The context associated with a DELETE operation
+ */
+public interface DeleteContext {
+
+    /**
+     * @return the jcr session associated with this context.
+     */
+    public Session getSession();
+
+}

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContextImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContextImpl.java?rev=1686293&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContextImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteContextImpl.java
Thu Jun 18 19:13:34 2015
@@ -0,0 +1,39 @@
+/*
+ * 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 javax.jcr.Session;
+
+/**
+ * Implements a simple delete context
+ */
+public class DeleteContextImpl implements  DeleteContext {
+
+    private final Session session;
+
+    public DeleteContextImpl(Session session) {
+        this.session = session;
+    }
+
+    /**
+     * @see DeleteContext#getSession()
+     */
+    public Session getSession() {
+        return this.session;
+    }
+}

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteHandler.java?rev=1686293&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteHandler.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteHandler.java
Thu Jun 18 19:13:34 2015
@@ -0,0 +1,51 @@
+/*
+ * 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.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+
+/**
+ * The DeleteHandler is invoked when a webdav DELETE request is received. Implementers of
this interface should plugin
+ * their handling of DELETE request here
+ */
+public interface DeleteHandler {
+
+    /**
+     * Executes the delete operation with the given parameters.
+     *
+     * @param deleteContext The context of the delete.
+     * @param resource The resource to be deleted
+     * @return {@code true} if this instance successfully executed the delete operation with
the given parameters;
+     *         {@code false} otherwise.
+     * @throws DavException If an error occurs.
+     */
+    public boolean delete(DeleteContext deleteContext, DavResource resource) throws DavException;
+
+
+    /**
+     * Validates if this handler is able to execute a delete operation with the given
+     * parameters.
+     *
+     * @param deleteContext The context of the delete
+     * @param resource The resource to be deleted
+     * @return {@code true} if this instance can successfully execute the delete operation
with the given parameters;
+     *         {@code false} otherwise.
+     */
+    public boolean canDelete(DeleteContext deleteContext, DavResource resource);
+}

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManager.java?rev=1686293&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManager.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManager.java
Thu Jun 18 19:13:34 2015
@@ -0,0 +1,54 @@
+/*
+ * 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.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+
+/**
+ * The DeleteManager handles DELETE operation by delegating it to its handlers. It also provides
a way
+ * to register {@link org.apache.jackrabbit.server.io.DeleteHandler} within it. Implementers
of this interface
+ * must invoke the registered delete handlers appropriately when a DELETE operation is to
be performed
+ */
+public interface DeleteManager {
+
+    /**
+     * Delegates the delete operation to the fist handler that accepts it.
+     *
+     * @param deleteContext The context associated with the DELETE operation
+     * @param resource The resource to be deleted
+     * @return {@code true} if this instance successfully executed the delete operation with
the given parameters;
+     *         {@code false} otherwise.
+     * @throws DavException If an error occurs.
+     */
+    public boolean delete(DeleteContext deleteContext, DavResource resource) throws DavException;
+
+    /**
+     * Registers a delete handler
+     *
+     * @param deleteHandler Registers a delete handler with this delete manager
+     */
+    public void addDeleteHandler(DeleteHandler deleteHandler);
+
+    /**
+     * Returns the registered delete handlers
+     *
+     * @return An array of all the registered delete handlers.
+     */
+    public DeleteHandler[] getDeleteHandlers();
+}

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManagerImpl.java?rev=1686293&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManagerImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/io/DeleteManagerImpl.java
Thu Jun 18 19:13:34 2015
@@ -0,0 +1,77 @@
+/*
+ * 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.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DeleteManagerImpl implements DeleteManager {
+
+    private static DeleteManager DEFAULT_MANAGER;
+
+    private final List<DeleteHandler> deleteHandlers = new ArrayList<DeleteHandler>();
+
+    /**
+     * @see DeleteManager#delete(DeleteContext, DavResource)
+     */
+    public boolean delete(DeleteContext deleteContext, DavResource member) throws DavException
{
+        boolean success = false;
+        DeleteHandler[] deleteHandlers = getDeleteHandlers();
+        for (int i = 0; i < deleteHandlers.length && !success; i++) {
+            DeleteHandler dh = deleteHandlers[i];
+            if (dh.canDelete(deleteContext, member)) {
+                success = dh.delete(deleteContext, member);
+            }
+        }
+        return success;
+    }
+
+    /**
+     * @see DeleteManager#addDeleteHandler(DeleteHandler)
+     */
+    public void addDeleteHandler(DeleteHandler deleteHandler) {
+        if (deleteHandler == null) {
+            throw new IllegalArgumentException("'null' is not a valid DeleteHandler.");
+        }
+        deleteHandlers.add(deleteHandler);
+
+    }
+
+    /**
+     * @see DeleteManager#getDeleteHandlers()
+     */
+    public DeleteHandler[] getDeleteHandlers() {
+        return deleteHandlers.toArray(new DeleteHandler[deleteHandlers.size()]);
+    }
+
+    /**
+     * Returns this delete manager singleton
+     */
+    public static DeleteManager getDefaultManager() {
+        if (DEFAULT_MANAGER == null) {
+            DeleteManager manager = new DeleteManagerImpl();
+            manager.addDeleteHandler(new DefaultHandler());
+            DEFAULT_MANAGER = manager;
+        }
+        return DEFAULT_MANAGER;
+    }
+
+}

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?rev=1686293&r1=1686292&r2=1686293&view=diff
==============================================================================
--- 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
Thu Jun 18 19:13:34 2015
@@ -20,6 +20,8 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.jackrabbit.server.io.AbstractExportContext;
 import org.apache.jackrabbit.server.io.CopyMoveContextImpl;
 import org.apache.jackrabbit.server.io.DefaultIOListener;
+import org.apache.jackrabbit.server.io.DeleteContextImpl;
+import org.apache.jackrabbit.server.io.DeleteManager;
 import org.apache.jackrabbit.server.io.ExportContext;
 import org.apache.jackrabbit.server.io.ExportContextImpl;
 import org.apache.jackrabbit.server.io.IOListener;
@@ -557,31 +559,20 @@ public class DavResourceImpl implements
             throw new DavException(DavServletResponse.SC_FORBIDDEN);
         }
 
+        DeleteManager dm = config.getDeleteManager();
+        dm.delete(new DeleteContextImpl(getJcrSession()), member);
 
+        // make sure, non-jcr locks are removed, once the removal is completed
         try {
-            String itemPath = member.getLocator().getRepositoryPath();
-            Item memItem = getJcrSession().getItem(itemPath);
-            if (memItem instanceof Node) {
-                ((Node)memItem).removeShare();
-            } else {
-                memItem.remove();
-            }
-            getJcrSession().save();
-
-            // make sure, non-jcr locks are removed, once the removal is completed
-            try {
-                if (!isJcrLockable()) {
-                    ActiveLock lock = getLock(Type.WRITE, Scope.EXCLUSIVE);
-                    if (lock != null) {
-                        lockManager.releaseLock(lock.getToken(), member);
-                    }
+            if (!isJcrLockable()) {
+                ActiveLock lock = getLock(Type.WRITE, Scope.EXCLUSIVE);
+                if (lock != null) {
+                    lockManager.releaseLock(lock.getToken(), member);
                 }
-            } catch (DavException e) {
-                // since check for 'locked' exception has been performed before
-                // ignore any error here
             }
-        } catch (RepositoryException e) {
-            throw new JcrDavException(e);
+        } catch (DavException e) {
+            // since check for 'locked' exception has been performed before
+            // ignore any error here
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java?rev=1686293&r1=1686292&r2=1686293&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/simple/ResourceConfig.java
Thu Jun 18 19:13:34 2015
@@ -35,6 +35,8 @@ import org.apache.jackrabbit.server.io.C
 import org.apache.jackrabbit.server.io.CopyMoveManager;
 import org.apache.jackrabbit.server.io.CopyMoveManagerImpl;
 import org.apache.jackrabbit.server.io.DefaultIOManager;
+import org.apache.jackrabbit.server.io.DeleteManager;
+import org.apache.jackrabbit.server.io.DeleteManagerImpl;
 import org.apache.jackrabbit.server.io.IOHandler;
 import org.apache.jackrabbit.server.io.IOManager;
 import org.apache.jackrabbit.server.io.PropertyHandler;
@@ -80,6 +82,7 @@ public class ResourceConfig {
     private IOManager ioManager;
     private CopyMoveManager cmManager;
     private PropertyManager propManager;
+    private DeleteManager deleteManager;
     private String[] nodetypeNames = new String[0];
     private boolean collectionNames = false;
 
@@ -473,6 +476,18 @@ public class ResourceConfig {
     }
 
     /**
+     * Returns the delete manager.
+     * @return the delete manager
+     */
+    public DeleteManager getDeleteManager() {
+        if (deleteManager == null) {
+            log.debug("Missing delete-manager > building default.");
+            deleteManager = DeleteManagerImpl.getDefaultManager();
+        }
+        return deleteManager;
+    }
+
+    /**
      * Returns true, if the given item represents a {@link Node node} that is
      * either any of the nodetypes specified to represent a collection or
      * none of the nodetypes specified to represent a non-collection, respectively.



Mime
View raw message