AbstractCopyMoveRequest.java
2.03 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.resource.NonExistingResource
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
*/
package com.adobe.granite.rest.impl.servlet;
import com.adobe.granite.rest.RequestException;
import com.adobe.granite.rest.impl.servlet.AbstractRequest;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.NonExistingResource;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
public abstract class AbstractCopyMoveRequest
extends AbstractRequest {
protected static final String REQUEST_HEADER_DESTINATION = "X-Destination";
protected static final String REQUEST_HEADER_DEPTH = "X-Depth";
protected static final String REQUEST_HEADER_OVERWRITE = "X-Overwrite";
protected Resource getDestinationResource(SlingHttpServletRequest request, String destinationPath) {
String destPath = ResourceUtil.normalize((String)destinationPath);
Resource destination = request.getResourceResolver().getResource(destPath);
if (destination != null && !(destination instanceof NonExistingResource)) {
return destination;
}
return null;
}
protected String getDestination(SlingHttpServletRequest request) throws RequestException {
URI uri = null;
String destination = request.getHeader("X-Destination");
if (destination == null) {
throw new RequestException(412, "Request header 'X-Destination' required");
}
try {
uri = new URI(destination);
}
catch (URISyntaxException e) {
throw new RequestException(412, "Request header 'X-Destination' is no valid URI");
}
return uri.getPath();
}
}