DeleteRequest.java
2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.request.RequestPathInfo
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.servlets.post.Modification
* org.apache.sling.servlets.post.PostResponse
*/
package com.adobe.granite.rest.impl.servlet;
import com.adobe.granite.rest.RequestException;
import com.adobe.granite.rest.impl.servlet.AbstractRequest;
import java.util.List;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestPathInfo;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.servlets.post.Modification;
import org.apache.sling.servlets.post.PostResponse;
public class DeleteRequest
extends AbstractRequest {
@Override
protected void doHandle(SlingHttpServletRequest request, PostResponse response, List<Modification> changes) throws UnsupportedOperationException, RequestException, Exception {
String notExists = null;
try {
RequestPathInfo rpi = request.getRequestPathInfo();
Resource resource = request.getResource();
if (ResourceUtil.isNonExistingResource((Resource)resource)) {
notExists = rpi.getResourcePath();
} else {
String resourcePath = resource.getPath();
resource.getResourceResolver().delete(resource);
changes.add(Modification.onDeleted((String)resourcePath));
}
}
catch (UnsupportedOperationException e) {
throw new RequestException(403, "Source does not support deletion");
}
catch (Exception e) {
throw new RequestException(500, e.getMessage());
}
if (notExists != null) {
throw new RequestException(404, "No resource found at path " + notExists);
}
}
}