FormsPayloadInfoBuilder.java
6.18 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.workflow.exec.InboxItem
* com.adobe.granite.workflow.exec.WorkItem
* com.adobe.granite.workflow.metadata.MetaDataMap
* com.adobe.granite.workflow.model.WorkflowNode
* com.adobe.granite.workflow.payload.PayloadInfo
* com.adobe.granite.workflow.payload.PayloadInfoBuilder
* com.adobe.granite.workflow.payload.PayloadInfoBuilderContext
* com.adobe.granite.xss.ProtectionContext
* com.adobe.granite.xss.XSSFilter
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* 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.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.wcm.foundation.forms.impl;
import com.adobe.granite.workflow.exec.InboxItem;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import com.adobe.granite.workflow.model.WorkflowNode;
import com.adobe.granite.workflow.payload.PayloadInfo;
import com.adobe.granite.workflow.payload.PayloadInfoBuilder;
import com.adobe.granite.workflow.payload.PayloadInfoBuilderContext;
import com.adobe.granite.xss.ProtectionContext;
import com.adobe.granite.xss.XSSFilter;
import java.util.Iterator;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
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.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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service(value={PayloadInfoBuilder.class})
@Property(name="service.ranking", intValue={-100}, propertyPrivate=1)
public class FormsPayloadInfoBuilder
implements PayloadInfoBuilder {
private static final Logger log = LoggerFactory.getLogger(FormsPayloadInfoBuilder.class);
private static final String FORM_PATH_PROPERTY = "formPath";
private static final String FORM_START_RESOURCE_TYPE = "foundation/components/form/start";
private static final String FORM_END_RESOURCE_TYPE = "foundation/components/form/end";
private static final String DISABLE_WCM_EDIT_MODE = "?wcmmode=disabled";
@Reference(policy=ReferencePolicy.STATIC)
private XSSFilter xss;
public PayloadInfo getPayloadInfo(PayloadInfoBuilderContext context) {
Resource res;
String payloadPath = context.getInboxItem().getContentPath();
if (StringUtils.isBlank((CharSequence)payloadPath)) {
payloadPath = context.getPayloadPath();
}
if ((res = context.getResourceResolver().getResource(payloadPath)) != null) {
WorkflowNode node;
String formPath;
Resource parent = res.getParent();
if (parent != null) {
ValueMap values = res.getValueMap();
ValueMap parentValues = parent.getValueMap();
String formPath2 = (String)parentValues.get("formPath", String.class);
if (StringUtils.isNotBlank((CharSequence)formPath2)) {
String path = res.getPath();
String browserPath = path + ".html";
String description = "";
Resource form = context.getResourceResolver().getResource(ResourceUtil.getParent((String)formPath2));
String formStartName = ResourceUtil.getName((String)((String)parentValues.get("formPath", (Object)"")));
Iterator children = form.listChildren();
while (children.hasNext()) {
Resource child = (Resource)children.next();
if (!child.isResourceType("foundation/components/form/start") || !child.getName().equals(formStartName)) continue;
description = this.getDescription(values, children);
PayloadInfo info = context.createPayloadInfo();
info.setPath(path).setBrowserPath(browserPath).setDescription(description);
return info;
}
}
}
if (context.getInboxItem() != null && context.getInboxItem() instanceof WorkItem && (node = ((WorkItem)context.getInboxItem()).getNode()) != null && (formPath = (String)node.getMetaDataMap().get("FORM_PATH", String.class)) != null && formPath.startsWith("/")) {
String path = context.getInboxItem().getContentPath();
String browserPath = path + ".form.html" + formPath + "?wcmmode=disabled";
PayloadInfo info = context.createPayloadInfo();
info.setPath(path).setBrowserPath(browserPath);
return info;
}
}
return null;
}
private String getDescription(ValueMap values, Iterator<Resource> children) {
StringBuilder builder = new StringBuilder();
int count = 0;
while (children.hasNext() && count < 3) {
Resource child = children.next();
ValueMap fieldValues = child.getValueMap();
if (child.isResourceType("foundation/components/form/end")) break;
if (!fieldValues.containsKey((Object)"name")) continue;
String name = (String)fieldValues.get("name", (Object)"");
builder.append("<br>").append(name).append(": ").append(this.xss.filter(ProtectionContext.PLAIN_HTML_CONTENT, (String)values.get(name, (Object)"")));
++count;
}
return builder.toString();
}
protected void bindXss(XSSFilter xSSFilter) {
this.xss = xSSFilter;
}
protected void unbindXss(XSSFilter xSSFilter) {
if (this.xss == xSSFilter) {
this.xss = null;
}
}
}