SLING-4825 - support Jackrabbit DeleteHandler - contributed by Satya Deep Maheshwari, thanks!

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1702935 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 1d94e08..e7c9635 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git a/src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java b/src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java
new file mode 100644
index 0000000..09d44d3
--- /dev/null
+++ b/src/main/java/org/apache/sling/launchpad/testservices/handlers/AbstractDeleteHandler.java
@@ -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;
+        }
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java b/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java
new file mode 100644
index 0000000..4943b13
--- /dev/null
+++ b/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler1.java
@@ -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;
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java b/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java
new file mode 100644
index 0000000..defb3cf
--- /dev/null
+++ b/src/main/java/org/apache/sling/launchpad/testservices/handlers/TestDeleteHandler2.java
@@ -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;
+    }
+
+}