ServletBase.java
2.76 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.http.HttpServletResponse
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.request.RequestParameter
* org.apache.sling.api.request.RequestParameterMap
* org.apache.sling.api.servlets.HtmlResponse
* org.apache.sling.api.servlets.SlingAllMethodsServlet
*/
package com.adobe.granite.workflow.console.servlet;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.request.RequestParameterMap;
import org.apache.sling.api.servlets.HtmlResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public abstract class ServletBase
extends SlingAllMethodsServlet {
private static final long serialVersionUID = 8498347475694730617L;
protected static final String[] DEFAULT_META_DATA_EXCLUDES = new String[]{"_charset_", ":status", ":cq_csrf_token"};
protected void sendResponse(HttpServletResponse response, int status, String message) {
HtmlResponse htmlResponse = new HtmlResponse();
htmlResponse.setStatus(status, message);
htmlResponse.setTitle(message);
try {
htmlResponse.send(response, true);
}
catch (IOException e) {
this.log("Error while writing response", (Throwable)e);
}
}
protected void sendResourceCreatedResponse(HttpServletResponse response, String url) {
response.setCharacterEncoding("utf-8");
HtmlResponse htmlResponse = new HtmlResponse();
htmlResponse.setStatus(201, "Created");
htmlResponse.setTitle("Created");
htmlResponse.setLocation(url);
try {
htmlResponse.send(response, true);
}
catch (IOException e) {
this.log("Error while writing response", (Throwable)e);
}
}
protected String getUrl(SlingHttpServletRequest request, String uri) {
return request.getContextPath() + uri;
}
protected void updateMetaData(RequestParameterMap params, Map<String, Object> metaData) {
List<String> excludes = Arrays.asList(DEFAULT_META_DATA_EXCLUDES);
for (String key : params.keySet()) {
if (excludes.contains(key) || this.getMetaDataExcludes(params).contains(key)) continue;
RequestParameter para = params.getValue(key);
metaData.put(key, para.getString());
}
}
protected abstract List<String> getMetaDataExcludes(RequestParameterMap var1);
}