BulkEditorServlet.java
4.73 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* 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.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.servlet;
import com.adobe.aemds.guide.service.GuideException;
import com.adobe.aemds.guide.utils.GuideUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
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.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.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(metatype=0)
@Service(value={Servlet.class})
@Properties(value={@Property(name="sling.servlet.resourceTypes", value={"fd/af/components/guideContainer"}), @Property(name="sling.servlet.methods", value={"GET"}), @Property(name="service.description", value={"Adaptive Form Bulk Editor"}), @Property(name="sling.servlet.selectors", value={"af.bulkeditor"})})
public class BulkEditorServlet
extends SlingAllMethodsServlet {
private Logger logger = LoggerFactory.getLogger(BulkEditorServlet.class);
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
Resource formResource = request.getResource();
ValueMap properties = ResourceUtil.getValueMap((Resource)formResource);
StringBuilder sb = new StringBuilder();
sb.append(request.getContextPath());
sb.append("/etc/importers/bulkeditor.html?rootPath=");
String actionPath = request.getParameter("storePath");
if (actionPath == null || actionPath.trim().length() == 0) {
response.sendError(400, "Missing 'storePath' property on node " + formResource.getPath());
}
if (actionPath.endsWith("*")) {
actionPath = actionPath.substring(0, actionPath.length() - 1);
}
if (actionPath.endsWith("/")) {
actionPath = actionPath.substring(0, actionPath.length() - 1);
}
sb.append(this.encodeValue(actionPath));
sb.append("&initialSearch=true&contentMode=false&spc=true");
ArrayList<String> fields = new ArrayList<String>();
this.getFieldsFromGuideContainer(formResource, fields);
this.logger.error("size is " + fields.size());
for (String field : fields) {
sb.append("&cs=");
sb.append(field);
sb.append("&cv=");
sb.append(field);
}
response.sendRedirect(sb.toString());
}
public String encodeValue(String value) {
try {
return URLEncoder.encode(value, "UTF-8");
}
catch (UnsupportedEncodingException e) {
this.logger.error(e.getMessage(), (Throwable)e);
throw new GuideException(e);
}
}
public void getFieldsFromGuideContainer(Resource formResource, List<String> fields) {
ValueMap vm = (ValueMap)formResource.adaptTo(ValueMap.class);
String guideNodeClass = "";
if (vm.containsKey((Object)"guideNodeClass")) {
guideNodeClass = (String)vm.get("guideNodeClass", (Object)"");
}
if (GuideUtils.isGuideFieldModel(guideNodeClass)) {
boolean isButton = GuideUtils.isGuideButtonModel(guideNodeClass);
boolean isFileUpload = GuideUtils.isGuideFileUploadModel(guideNodeClass);
if (!isButton && !isFileUpload && !vm.containsKey((Object)"bindRef") && vm.containsKey((Object)"name")) {
fields.add((String)vm.get("name", (Object)""));
}
}
for (Resource child : formResource.getChildren()) {
this.getFieldsFromGuideContainer(child, fields);
}
}
}