sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1702935 - in /sling/trunk: bundles/jcr/webdav/ bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/ bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/ bundles/jcr/webdav/src/main/java/org/apache...
Date Mon, 14 Sep 2015 12:50:16 GMT
Author: bdelacretaz
Date: Mon Sep 14 12:50:16 2015
New Revision: 1702935

URL: http://svn.apache.org/r1702935
Log:
SLING-4825 - support Jackrabbit DeleteHandler - contributed by Satya Deep Maheshwari, thanks!

Added:
    sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingDeleteManager.java
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavDeleteTest.java
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java
Modified:
    sling/trunk/bundles/jcr/webdav/pom.xml
    sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DefaultHandlerService.java
    sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
    sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
    sling/trunk/launchpad/builder/src/main/provisioning/sling.txt
    sling/trunk/launchpad/test-services/pom.xml

Modified: sling/trunk/bundles/jcr/webdav/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/webdav/pom.xml?rev=1702935&r1=1702934&r2=1702935&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/webdav/pom.xml (original)
+++ sling/trunk/bundles/jcr/webdav/pom.xml Mon Sep 14 12:50:16 2015
@@ -56,7 +56,7 @@
                     <instructions>
                         <Bundle-Category>sling,jcr</Bundle-Category>
                         <Export-Package>
-                            org.apache.jackrabbit.server.io;version=2.3;provide:=true
+                            org.apache.jackrabbit.server.io;version=2.4;provide:=true
                         </Export-Package>
                         <Private-Package>
                             org.apache.jackrabbit.server,
@@ -115,7 +115,7 @@
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-jcr-server</artifactId>
-            <version>2.6.4</version>
+            <version>2.11.0</version>
             <scope>compile</scope>
         </dependency>
 

Modified: sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DefaultHandlerService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DefaultHandlerService.java?rev=1702935&r1=1702934&r2=1702935&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DefaultHandlerService.java
(original)
+++ sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/DefaultHandlerService.java
Mon Sep 14 12:50:16 2015
@@ -26,6 +26,8 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.server.io.DefaultHandler;
+import org.apache.jackrabbit.server.io.DeleteContext;
+import org.apache.jackrabbit.server.io.DeleteHandler;
 import org.apache.jackrabbit.server.io.ExportContext;
 import org.apache.jackrabbit.server.io.IOHandler;
 import org.apache.jackrabbit.server.io.IOManager;
@@ -58,7 +60,8 @@ import javax.jcr.RepositoryException;
     @Property(name = SlingWebDavServlet.TYPE_NONCOLLECTIONS, value = SlingWebDavServlet.TYPE_NONCOLLECTIONS_DEFAULT,
propertyPrivate = false),
     @Property(name = SlingWebDavServlet.TYPE_CONTENT, value = SlingWebDavServlet.TYPE_CONTENT_DEFAULT,
propertyPrivate = false) })
 @Service
-public class DefaultHandlerService implements IOHandler, PropertyHandler, CopyMoveHandler
{
+public class DefaultHandlerService implements IOHandler, PropertyHandler, CopyMoveHandler,
+        DeleteHandler {
 
     private DefaultHandler delegatee;
 
@@ -168,4 +171,14 @@ public class DefaultHandlerService imple
     public boolean move(CopyMoveContext context, DavResource source, DavResource destination)
throws DavException {
       return delegatee.move(context, source, destination);
     }
+
+    public boolean delete(DeleteContext deleteContext, DavResource davResource)
+            throws DavException {
+        return delegatee.delete(deleteContext, davResource);
+    }
+
+    public boolean canDelete(DeleteContext deleteContext,
+            DavResource davResource) {
+        return delegatee.canDelete(deleteContext, davResource);
+    }
 }

Added: sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingDeleteManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingDeleteManager.java?rev=1702935&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingDeleteManager.java
(added)
+++ sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingDeleteManager.java
Mon Sep 14 12:50:16 2015
@@ -0,0 +1,63 @@
+/*
+ * 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.sling.jcr.webdav.impl.handler;
+
+import org.apache.jackrabbit.server.io.DeleteHandler;
+import org.apache.jackrabbit.server.io.DeleteManagerImpl;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * DeleteManager service that uses a ServiceTracker to find available
+ * DeleteHandler.
+ */
+public class SlingDeleteManager extends DeleteManagerImpl {
+
+    private static final DeleteHandler[] DELETEHANDLERS_PROTOTYPE = new DeleteHandler[0];
+    private final SlingHandlerManager<DeleteHandler> handlerManager;
+
+    public SlingDeleteManager(final String referenceName) {
+        handlerManager = new SlingHandlerManager<DeleteHandler>(referenceName);
+    }
+
+    @Override
+    public void addDeleteHandler(DeleteHandler propertyHandler) {
+        throw new UnsupportedOperationException(
+                "This DeleteManager only supports registered DeleteHandler services");
+    }
+
+    @Override
+    public DeleteHandler[] getDeleteHandlers() {
+        return this.handlerManager.getHandlers(DELETEHANDLERS_PROTOTYPE);
+    }
+
+    public void setComponentContext(ComponentContext componentContext) {
+        this.handlerManager.setComponentContext(componentContext);
+    }
+
+    public void bindDeleteHandler(final ServiceReference deleteHandlerReference) {
+        this.handlerManager.bindHandler(deleteHandlerReference);
+    }
+
+    public void unbindDeleteHandler(final ServiceReference deleteHandlerReference) {
+        this.handlerManager.unbindHandler(deleteHandlerReference);
+    }
+
+}

Modified: sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java?rev=1702935&r1=1702934&r2=1702935&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
(original)
+++ sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
Mon Sep 14 12:50:16 2015
@@ -19,6 +19,7 @@
 package org.apache.sling.jcr.webdav.impl.helper;
 
 import org.apache.jackrabbit.server.io.CopyMoveManager;
+import org.apache.jackrabbit.server.io.DeleteManager;
 import org.apache.jackrabbit.server.io.IOManager;
 import org.apache.jackrabbit.server.io.PropertyManager;
 import org.apache.jackrabbit.webdav.simple.DefaultItemFilter;
@@ -48,6 +49,8 @@ public class SlingResourceConfig extends
 
     private final CopyMoveManager copyMoveManager;
 
+    private final DeleteManager deleteManager;
+
     private final String servletContextPath;
 
     private final Dictionary<String, String> servletInitParams;
@@ -56,11 +59,13 @@ public class SlingResourceConfig extends
             Dictionary<?, ?> config,
             IOManager ioManager,
             PropertyManager propertyManager,
-            CopyMoveManager copyMoveManager) {
+            CopyMoveManager copyMoveManager,
+            DeleteManager deleteManager) {
         super(new SlingTikaDetector(mimeTypeService));
         this.ioManager = ioManager;
         this.propertyManager = propertyManager;
         this.copyMoveManager = copyMoveManager;
+        this.deleteManager = deleteManager;
         collectionTypes = OsgiUtil.toStringArray(
             config.get(SlingWebDavServlet.COLLECTION_TYPES),
             SlingWebDavServlet.COLLECTION_TYPES_DEFAULT);
@@ -126,6 +131,11 @@ public class SlingResourceConfig extends
     }
 
     @Override
+    public DeleteManager getDeleteManager() {
+        return deleteManager;
+    }
+
+    @Override
     public boolean isCollectionResource(Item item) {
         if (item.isNode()) {
             Node node = (Node) item;

Modified: sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java?rev=1702935&r1=1702934&r2=1702935&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
(original)
+++ sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
Mon Sep 14 12:50:16 2015
@@ -37,6 +37,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.server.SessionProvider;
 import org.apache.jackrabbit.server.io.CopyMoveHandler;
+import org.apache.jackrabbit.server.io.DeleteHandler;
 import org.apache.jackrabbit.server.io.IOHandler;
 import org.apache.jackrabbit.server.io.PropertyHandler;
 import org.apache.jackrabbit.webdav.DavException;
@@ -47,6 +48,7 @@ import org.apache.jackrabbit.webdav.simp
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.webdav.impl.handler.SlingCopyMoveManager;
+import org.apache.sling.jcr.webdav.impl.handler.SlingDeleteManager;
 import org.apache.sling.jcr.webdav.impl.handler.SlingIOManager;
 import org.apache.sling.jcr.webdav.impl.handler.SlingPropertyManager;
 import org.apache.sling.jcr.webdav.impl.helper.SlingLocatorFactory;
@@ -76,7 +78,8 @@ import org.osgi.service.http.NamespaceEx
     @References({
         @Reference(name = SlingWebDavServlet.IOHANDLER_REF_NAME, referenceInterface = IOHandler.class,
cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
         @Reference(name = SlingWebDavServlet.PROPERTYHANDLER_REF_NAME, referenceInterface
= PropertyHandler.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
-        @Reference(name = SlingWebDavServlet.COPYMOVEHANDLER_REF_NAME, referenceInterface
= CopyMoveHandler.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
+        @Reference(name = SlingWebDavServlet.COPYMOVEHANDLER_REF_NAME, referenceInterface
= CopyMoveHandler.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
+        @Reference(name = SlingWebDavServlet.DELETEHANDLER_REF_NAME, referenceInterface =
DeleteHandler.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC)
 })
 public class SlingWebDavServlet extends SimpleWebdavServlet {
 
@@ -136,6 +139,8 @@ public class SlingWebDavServlet extends
 
     static final String COPYMOVEHANDLER_REF_NAME = "CopyMoveHandler";
 
+    static final String DELETEHANDLER_REF_NAME = "DeleteHandler";
+
     @Reference
     private SlingRepository repository;
 
@@ -154,6 +159,9 @@ public class SlingWebDavServlet extends
     private final SlingCopyMoveManager copyMoveManager = new SlingCopyMoveManager(
         COPYMOVEHANDLER_REF_NAME);
 
+    private final SlingDeleteManager deleteManager = new SlingDeleteManager(
+            DELETEHANDLER_REF_NAME);
+
     private SlingResourceConfig resourceConfig;
 
     private DavLocatorFactory locatorFactory;
@@ -221,12 +229,14 @@ public class SlingWebDavServlet extends
         this.ioManager.setComponentContext(context);
         this.propertyManager.setComponentContext(context);
         this.copyMoveManager.setComponentContext(context);
+        this.deleteManager.setComponentContext(context);
 
         resourceConfig = new SlingResourceConfig(mimeTypeService,
             context.getProperties(),
             ioManager,
             propertyManager,
-            copyMoveManager);
+            copyMoveManager,
+            deleteManager);
 
         // Register servlet, and set the contextPath field to signal successful
         // registration
@@ -267,6 +277,7 @@ public class SlingWebDavServlet extends
     }
 
     public void bindCopyMoveHandler(final ServiceReference copyMoveHandlerReference) {
+
         this.copyMoveManager.bindCopyMoveHandler(copyMoveHandlerReference);
     }
 
@@ -274,6 +285,14 @@ public class SlingWebDavServlet extends
         this.copyMoveManager.unbindCopyMoveHandler(copyMoveHandlerReference);
     }
 
+    public void bindDeleteHandler(final ServiceReference deleteHandlerReference) {
+        this.deleteManager.bindDeleteHandler(deleteHandlerReference);
+    }
+
+    public void unbindDeleteHandler(final ServiceReference deleteHandlerReference) {
+        this.deleteManager.unbindDeleteHandler(deleteHandlerReference);
+    }
+
     /** Overridden as the base class uses sendError that we don't want (SLING-2443) */
     @Override
     protected void sendUnauthorized(WebdavRequest request, WebdavResponse response, DavException
error) throws IOException {

Modified: sling/trunk/launchpad/builder/src/main/provisioning/sling.txt
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/provisioning/sling.txt?rev=1702935&r1=1702934&r2=1702935&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/provisioning/sling.txt (original)
+++ sling/trunk/launchpad/builder/src/main/provisioning/sling.txt Mon Sep 14 12:50:16 2015
@@ -112,9 +112,9 @@
     org.apache.jackrabbit/jackrabbit-jcr-commons/2.10.1
     org.apache.jackrabbit/jackrabbit-spi/2.10.1
     org.apache.jackrabbit/jackrabbit-spi-commons/2.10.1
-    org.apache.jackrabbit/jackrabbit-webdav/2.10.1
+    org.apache.jackrabbit/jackrabbit-webdav/2.11.0
     org.apache.jackrabbit/jackrabbit-jcr-rmi/2.10.1
-    org.apache.sling/org.apache.sling.jcr.webdav/2.3.0
+    org.apache.sling/org.apache.sling.jcr.webdav/2.3.1-SNAPSHOT
     org.apache.sling/org.apache.sling.jcr.davex/1.2.2
     org.apache.sling/org.apache.sling.jcr.jackrabbit.usermanager/2.2.3-SNAPSHOT
     org.apache.sling/org.apache.sling.jcr.jackrabbit.accessmanager/2.1.2

Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavDeleteTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavDeleteTest.java?rev=1702935&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavDeleteTest.java
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/WebdavDeleteTest.java
Mon Sep 14 12:50:16 2015
@@ -0,0 +1,78 @@
+/*
+ * 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.sling.launchpad.webapp.integrationtest;
+
+import junitx.framework.Assert;
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.junit.Test;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+public class WebdavDeleteTest extends HttpTestBase{
+    private final String testDir = "/sling-test/" + getClass().getSimpleName() + System.currentTimeMillis();
+    private final String testDirUrl = HTTP_BASE_URL + testDir;
+
+    private final String DEFAULT_HANDLER   = "default-delete-handler";
+    private final String HANDLER_1   = "test-delete-handler-1";
+    private final String HANDLER_2   = "test-delete-handler-2";
+
+    private final String HANDLER_1_BKP = "backed-up-by-" + HANDLER_1;
+    private final String HANDLER_2_BKP = "backed-up-by-" + HANDLER_2;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        testClient.mkdirs(HTTP_BASE_URL, testDir);
+
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("jcr:primaryType", "nt:unstructured");
+        testClient.createNode(HTTP_BASE_URL + testDir + "/" + HANDLER_1, map);
+        testClient.createNode(HTTP_BASE_URL + testDir + "/" + HANDLER_2, map);
+        testClient.createNode(HTTP_BASE_URL + testDir + "/" + DEFAULT_HANDLER, map);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        testClient.delete(testDirUrl);
+    }
+
+    @Test
+    public void testDelete() {
+        try {
+            testClient.delete(HTTP_BASE_URL + testDir + "/" + HANDLER_1);
+            testClient.delete(HTTP_BASE_URL + testDir + "/" + HANDLER_2);
+            testClient.delete(HTTP_BASE_URL + testDir + "/" + DEFAULT_HANDLER);
+
+            Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, testClient.get(HTTP_BASE_URL
+ testDir + "/" + HANDLER_1));
+            Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, testClient.get(HTTP_BASE_URL
+ testDir + "/" + HANDLER_2));
+            Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, testClient.get(HTTP_BASE_URL
+ testDir + "/" + DEFAULT_HANDLER));
+
+            Assert.assertEquals(HttpServletResponse.SC_OK, testClient.get(HTTP_BASE_URL +
testDir + "/" + HANDLER_1 + HANDLER_1_BKP + ".json"));
+            Assert.assertEquals(HttpServletResponse.SC_OK, testClient.get(HTTP_BASE_URL +
testDir + "/" + HANDLER_2 + HANDLER_2_BKP + ".json"));
+
+        } catch (IOException e) {
+            Assert.fail(e);
+        }
+    }
+
+}

Modified: sling/trunk/launchpad/test-services/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/pom.xml?rev=1702935&r1=1702934&r2=1702935&view=diff
==============================================================================
--- sling/trunk/launchpad/test-services/pom.xml (original)
+++ sling/trunk/launchpad/test-services/pom.xml Mon Sep 14 12:50:16 2015
@@ -113,7 +113,7 @@
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-jcr-server</artifactId>
-            <version>2.2.8</version>
+            <version>2.11.0</version>
             <scope>compile</scope>
         </dependency>
         <dependency>

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java?rev=1702935&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java
Mon Sep 14 12:50:16 2015
@@ -0,0 +1,57 @@
+/*
+ * 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.sling.launchpad.testservices.handlers;
+
+import org.apache.jackrabbit.server.io.DeleteContext;
+import org.apache.jackrabbit.server.io.DeleteHandler;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+public abstract class AbstractDeleteHandler implements DeleteHandler {
+
+    protected String HANDLER_NAME = "";
+    protected String HANDLER_BKP;
+
+    @Override
+    public boolean delete(DeleteContext deleteContext,
+            DavResource resource) throws DavException {
+        try {
+            deleteContext.getSession().getWorkspace().move(resource.getResourcePath(), resource.getResourcePath()
+ HANDLER_BKP);
+            return true;
+        } catch (RepositoryException e) {
+            return false;
+        }
+    }
+
+    @Override
+    public boolean canDelete(DeleteContext deleteContext,
+            DavResource resource) {
+        try {
+            Node nodeToDelete = deleteContext.getSession().getNode(resource.getResourcePath());
+            return HANDLER_NAME.equals(nodeToDelete.getName());
+        } catch (RepositoryException e) {
+            return false;
+        }
+    }
+
+}

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java?rev=1702935&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java
Mon Sep 14 12:50:16 2015
@@ -0,0 +1,43 @@
+/*
+ * 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.sling.launchpad.testservices.handlers;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.jackrabbit.server.io.DeleteContext;
+import org.apache.jackrabbit.server.io.DeleteHandler;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.osgi.framework.Constants;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+@Component(metatype = true)
+@Property(name = Constants.SERVICE_RANKING, intValue = 2, propertyPrivate = false)
+@Service(value = { DeleteHandler.class })
+public class TestDeleteHandler1 extends AbstractDeleteHandler{
+
+    public TestDeleteHandler1() {
+        this.HANDLER_NAME = "test-delete-handler-1";
+        this.HANDLER_BKP = "backed-up-by-" + HANDLER_NAME;
+    }
+
+}

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java?rev=1702935&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java
Mon Sep 14 12:50:16 2015
@@ -0,0 +1,43 @@
+/*
+ * 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.sling.launchpad.testservices.handlers;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.jackrabbit.server.io.DeleteContext;
+import org.apache.jackrabbit.server.io.DeleteHandler;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.osgi.framework.Constants;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+@Component(metatype = true)
+@Property(name = Constants.SERVICE_RANKING, intValue = 2, propertyPrivate = false)
+@Service(value = { DeleteHandler.class })
+public class TestDeleteHandler2 extends AbstractDeleteHandler {
+
+    public TestDeleteHandler2() {
+        this.HANDLER_NAME = "test-delete-handler-2";
+        this.HANDLER_BKP = "backed-up-by-" + HANDLER_NAME;
+    }
+
+}



Mime
View raw message