WorkflowSummaryServlet.java
6.36 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.xss.ProtectionContext
* com.adobe.granite.xss.XSSFilter
* javax.servlet.Servlet
* javax.servlet.ServletException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.servlets.SlingSafeMethodsServlet
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
*/
package com.adobe.granite.workflow.console.servlet;
import com.adobe.granite.xss.ProtectionContext;
import com.adobe.granite.xss.XSSFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Iterator;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
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.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(name="com.adobe.granite.workflow.WorkflowSummaryServlet")
@Service(value={Servlet.class})
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"sling/servlet/default"}), @Property(name="sling.servlet.selectors", value={"wfsummary"}), @Property(name="sling.servlet.extensions", value={"json"})})
public class WorkflowSummaryServlet
extends SlingSafeMethodsServlet {
protected static final String FORM_START_RESOURCE_TYPE = "foundation/components/form/start";
protected static final String FORM_END_RESOURCE_TYPE = "foundation/components/form/end";
@Reference(policy=ReferencePolicy.STATIC)
private XSSFilter xss;
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
block6 : {
response.setContentType(request.getResponseContentType());
response.setCharacterEncoding("UTF-8");
try {
JSONWriter w = new JSONWriter((Writer)response.getWriter());
Resource resource = request.getResource();
ResourceResolver resolver = request.getResourceResolver();
ValueMap values = (ValueMap)resource.adaptTo(ValueMap.class);
ValueMap parentValues = (ValueMap)ResourceUtil.getParent((Resource)resource).adaptTo(ValueMap.class);
if (parentValues.containsKey((Object)"formPath")) {
Resource form = resolver.getResource(ResourceUtil.getParent((String)((String)parentValues.get((Object)"formPath"))));
String formStartName = ResourceUtil.getName((String)((String)parentValues.get((Object)"formPath")));
Iterator children = resolver.listChildren(form);
while (children.hasNext()) {
Resource child = (Resource)children.next();
if (!ResourceUtil.isA((Resource)child, (String)"foundation/components/form/start") || !ResourceUtil.getName((Resource)child).equals(formStartName)) continue;
String description = this.getFormDescription(values, children);
w.object();
w.key("description").value((Object)description.toString());
w.endObject();
break block6;
}
break block6;
}
if (values.containsKey((Object)"jcr:description")) {
w.object();
w.key("description").value(values.get((Object)"jcr:description"));
w.endObject();
} else {
w.object();
w.key("exception").value((Object)("no .wfsummary.json renderer provided for resource " + request.getResource().getPath()));
w.endObject();
}
}
catch (JSONException ex) {
throw new ServletException("JSONException in doGet", (Throwable)ex);
}
}
}
private String getFormDescription(ValueMap values, Iterator<Resource> children) {
StringBuffer description = new StringBuffer();
int count = 0;
while (children.hasNext()) {
Resource child = children.next();
ValueMap fieldValues = (ValueMap)child.adaptTo(ValueMap.class);
if (ResourceUtil.isA((Resource)child, (String)"foundation/components/form/end") || count >= 3) break;
if (!fieldValues.containsKey((Object)"name")) continue;
if (count > 0 && count < 3) {
description.append("<br>");
}
description.append(fieldValues.get((Object)"name"));
description.append(": ");
String value = (String)values.get(fieldValues.get((Object)"name"));
if (this.xss != null) {
value = this.xss.filter(ProtectionContext.PLAIN_HTML_CONTENT, (String)values.get(fieldValues.get((Object)"name")));
}
description.append(value);
++count;
}
return description.toString();
}
protected void bindXss(XSSFilter xSSFilter) {
this.xss = xSSFilter;
}
protected void unbindXss(XSSFilter xSSFilter) {
if (this.xss == xSSFilter) {
this.xss = null;
}
}
}