AdaptiveFormsDataServiceImpl.java
5.66 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:
* com.adobe.forms.common.service.FileAttachmentWrapper
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.service.impl;
import com.adobe.aemds.guide.service.AdaptiveFormsDataService;
import com.adobe.aemds.guide.service.GuideModelTransformer;
import com.adobe.aemds.guide.utils.AdaptiveFormData;
import com.adobe.aemds.guide.utils.AdaptiveFormInfo;
import com.adobe.aemds.guide.utils.GuideUtils;
import com.adobe.aemds.guide.utils.XMLUtils;
import com.adobe.aemds.guide.utils.guideJson.EmbeddedFormsData;
import com.adobe.aemds.guide.utils.guideJson.EmbeddedFormsDataCollector;
import com.adobe.aemds.guide.utils.guideJson.GuideJsonItemsTraverser;
import com.adobe.aemds.guide.utils.guideJson.GuideJsonVisitor;
import com.adobe.forms.common.service.FileAttachmentWrapper;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
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.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(metatype=0, immediate=1, label="Adaptive Forms Data Service", description="Service to gather User Data from Adaptive Forms")
@Service(value={AdaptiveFormsDataService.class})
public class AdaptiveFormsDataServiceImpl
implements AdaptiveFormsDataService {
private Logger logger = LoggerFactory.getLogger(AdaptiveFormsDataServiceImpl.class);
@Reference
private GuideModelTransformer guideModelTransformer;
@Override
public List<AdaptiveFormData> getEmbeddedAdaptiveFormsData(AdaptiveFormInfo adaptiveFormInfo) {
String xmlStr = adaptiveFormInfo.getXmlStr();
Resource formSetResource = adaptiveFormInfo.getFormResource();
List<FileAttachmentWrapper> attachmentWrappers = adaptiveFormInfo.getAttachments();
Document formSetDoc = XMLUtils.strToDoc(xmlStr);
ResourceResolver resolver = formSetResource.getResourceResolver();
Element fsBoundRoot = XMLUtils.getBoundDataXmlElement(formSetDoc);
Element fsUnBoundRoot = XMLUtils.getUnboundDataXmlElement(formSetDoc);
JSONObject formSetJson = GuideUtils.getFormJson(formSetResource, this.guideModelTransformer);
String formSetRoot = XMLUtils.extractXsdRootElement(formSetJson);
ArrayList<AdaptiveFormData> formSetXmlData = new ArrayList<AdaptiveFormData>();
List<EmbeddedFormsData> embeddedForms = this.getEmbeddedForms(formSetJson);
for (EmbeddedFormsData form : embeddedForms) {
Resource formResource = GuideUtils.getFormResource(formSetResource, form.getFragRef());
JSONObject formJson = GuideUtils.getFormJson(formResource, this.guideModelTransformer);
String bindRefPrefix = form.getBindRef();
String formRoot = XMLUtils.extractXsdRootElement(formJson);
String childBoundRootXpath = XMLUtils.getChildBoundRootXpath(formSetRoot, bindRefPrefix, formRoot);
boolean keepBoundPart = StringUtils.isNotBlank((CharSequence)(formSetRoot + formRoot));
Document formXml = XMLUtils.getChildXmlDoc(fsUnBoundRoot, fsBoundRoot, childBoundRootXpath, keepBoundPart);
List<String> attachmentNames = XMLUtils.extractAttachmentNames(formXml);
formSetXmlData.add(new AdaptiveFormData(XMLUtils.docToStr(formXml), bindRefPrefix, form.getFragRef(), this.getFormAttachmentsWrappers(attachmentNames, attachmentWrappers)));
}
return formSetXmlData;
}
private List<FileAttachmentWrapper> getFormAttachmentsWrappers(List<String> attachmentNames, List<FileAttachmentWrapper> attachmentWrappers) {
ArrayList<FileAttachmentWrapper> formAttachments = new ArrayList<FileAttachmentWrapper>();
if (attachmentNames != null) {
for (String attachmentName : attachmentNames) {
FileAttachmentWrapper attachmentWrapper = GuideUtils.findFileAttachment(attachmentWrappers, attachmentName);
if (attachmentWrapper == null) continue;
formAttachments.add(attachmentWrapper);
}
}
return formAttachments;
}
private List<EmbeddedFormsData> getEmbeddedForms(JSONObject guideJson) {
ArrayList<GuideJsonVisitor> visitors = new ArrayList<GuideJsonVisitor>();
EmbeddedFormsDataCollector embeddedFormsDataCollector = new EmbeddedFormsDataCollector();
visitors.add(embeddedFormsDataCollector);
GuideJsonItemsTraverser guideJsonTraverser = new GuideJsonItemsTraverser(guideJson, visitors);
guideJsonTraverser.traverse();
return embeddedFormsDataCollector.getEmbeddedForms();
}
protected void bindGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
this.guideModelTransformer = guideModelTransformer;
}
protected void unbindGuideModelTransformer(GuideModelTransformer guideModelTransformer) {
if (this.guideModelTransformer == guideModelTransformer) {
this.guideModelTransformer = null;
}
}
}