CMDataMergeServiceImpl.java
7.67 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.guide.service.GuideModuleImporter
* com.adobe.aemds.guide.service.external.GuideDataMergerSPI
* com.adobe.aemds.guide.utils.DocumentDataMerger
* com.adobe.aemds.guide.utils.KeyValueDataMerger
* com.adobe.aemds.guide.utils.XMLUtils
* com.adobe.dct.exception.DCTException
* com.adobe.dct.service.DataDictionaryUtilService
* com.adobe.dct.transfer.DataDictionaryInstance
* com.adobe.icc.ddg.api.HTML5ModuleResolverService
* com.adobe.icc.render.obj.ContextData
* com.adobe.icc.services.api.LetterService
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.adaddon.service.impl;
import com.adobe.aemds.guide.service.GuideModuleImporter;
import com.adobe.aemds.guide.service.external.GuideDataMergerSPI;
import com.adobe.aemds.guide.utils.DocumentDataMerger;
import com.adobe.aemds.guide.utils.KeyValueDataMerger;
import com.adobe.aemds.guide.utils.XMLUtils;
import com.adobe.dct.exception.DCTException;
import com.adobe.dct.service.DataDictionaryUtilService;
import com.adobe.dct.transfer.DataDictionaryInstance;
import com.adobe.fd.adaddon.internal.utils.ADUtils;
import com.adobe.fd.adaddon.internal.utils.CMDocumentDataMerger;
import com.adobe.fd.adaddon.internal.utils.LetterDataMerger;
import com.adobe.fd.adaddon.service.impl.ADHelperServiceImpl;
import com.adobe.icc.ddg.api.HTML5ModuleResolverService;
import com.adobe.icc.render.obj.ContextData;
import com.adobe.icc.services.api.LetterService;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import javax.xml.xpath.XPathExpressionException;
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.commons.json.JSONException;
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;
@Component(immediate=1, label="CM Data Merger Service", description="CM Data Merger Service")
@Service(value={GuideDataMergerSPI.class})
public class CMDataMergeServiceImpl
implements GuideDataMergerSPI {
private static final String CM_APP_CONTEXT_PATH = "/content/apps/cm";
private static final String DD_PATH_SEPARATOR = "/";
private static Logger logger = LoggerFactory.getLogger(CMDataMergeServiceImpl.class);
@Reference
ADHelperServiceImpl adHelperService;
@Reference
DataDictionaryUtilService dataDictionaryUtilService;
@Reference
LetterService letterService;
@Reference
HTML5ModuleResolverService html5ModuleResolverService;
@Reference
GuideModuleImporter guideModuleImporter;
public DocumentDataMerger createDataMerger(JSONObject jsonObject, Document data, Map<String, Object> params) throws Exception {
DocumentDataMerger ddm = null;
ddm = jsonObject.has("letterRef") ? (ADUtils.isLetterInstanceData(data) ? this.createMergerInstanceFromLetterInstance(jsonObject, data, params) : this.createMergerInstanceFromLetter(jsonObject, data, params)) : this.createMergerInstanceFromDD(jsonObject, data, params);
return ddm;
}
private DocumentDataMerger createMergerInstanceFromLetter(JSONObject guideJson, Document data, Map<String, Object> params) throws JSONException, XPathExpressionException, DCTException {
String letterRef = guideJson.getString("letterRef");
ContextData contextData = new ContextData();
Map<String, Object> fieldValueMap = this.adHelperService.updateContextDataForLetter(letterRef, data, contextData);
this.updateParams(params, letterRef, null, contextData, fieldValueMap);
return new LetterDataMerger(guideJson, data, params, this.html5ModuleResolverService);
}
private DocumentDataMerger createMergerInstanceFromDD(JSONObject guideJson, Document data, Map<String, Object> params) throws JSONException, XPathExpressionException {
String ddRef = guideJson.getString("ddRef");
ContextData contextData = new ContextData();
DataDictionaryInstance ddi = this.adHelperService.updateContextDataForDD(ddRef, data, contextData);
this.updateParams(params, null, ddi, contextData, null);
return new CMDocumentDataMerger(guideJson, data, params);
}
private DocumentDataMerger createMergerInstanceFromLetterInstance(JSONObject jsonObject, Document data, Map<String, Object> params) throws XPathExpressionException, DCTException, UnsupportedEncodingException {
ContextData contextData = new ContextData();
Map<String, Object> fieldValueMap = this.adHelperService.updateContextDataForLetterInstance(data, contextData, params);
this.updateParams(params, "", null, contextData, fieldValueMap);
return new LetterDataMerger(jsonObject, data, params, this.html5ModuleResolverService);
}
private DataDictionaryInstance createDataDictionary(String dataDictionaryRef, Document data) {
return ADUtils.createDataDictionary(this.dataDictionaryUtilService, dataDictionaryRef, XMLUtils.getXMLfromXsdDom((Element)data.getDocumentElement()));
}
private void updateParams(Map<String, Object> params, String letterRef, DataDictionaryInstance ddi, ContextData contextData, Map<String, Object> fieldsValueMap) {
logger.debug("updateParams: params={} , letterRef={}, ddi={}, contextData={},fieldsValueMap={}", new Object[]{params, letterRef, ddi, contextData, fieldsValueMap});
params.put("letterRef", letterRef);
params.put("moduleDDI", (Object)ddi);
params.put("FIELD_VALUE_MAP", fieldsValueMap);
params.put("CONTEXT_DATA", (Object)contextData);
}
protected void bindAdHelperService(ADHelperServiceImpl aDHelperServiceImpl) {
this.adHelperService = aDHelperServiceImpl;
}
protected void unbindAdHelperService(ADHelperServiceImpl aDHelperServiceImpl) {
if (this.adHelperService == aDHelperServiceImpl) {
this.adHelperService = null;
}
}
protected void bindDataDictionaryUtilService(DataDictionaryUtilService dataDictionaryUtilService) {
this.dataDictionaryUtilService = dataDictionaryUtilService;
}
protected void unbindDataDictionaryUtilService(DataDictionaryUtilService dataDictionaryUtilService) {
if (this.dataDictionaryUtilService == dataDictionaryUtilService) {
this.dataDictionaryUtilService = null;
}
}
protected void bindLetterService(LetterService letterService) {
this.letterService = letterService;
}
protected void unbindLetterService(LetterService letterService) {
if (this.letterService == letterService) {
this.letterService = null;
}
}
protected void bindHtml5ModuleResolverService(HTML5ModuleResolverService hTML5ModuleResolverService) {
this.html5ModuleResolverService = hTML5ModuleResolverService;
}
protected void unbindHtml5ModuleResolverService(HTML5ModuleResolverService hTML5ModuleResolverService) {
if (this.html5ModuleResolverService == hTML5ModuleResolverService) {
this.html5ModuleResolverService = null;
}
}
protected void bindGuideModuleImporter(GuideModuleImporter guideModuleImporter) {
this.guideModuleImporter = guideModuleImporter;
}
protected void unbindGuideModuleImporter(GuideModuleImporter guideModuleImporter) {
if (this.guideModuleImporter == guideModuleImporter) {
this.guideModuleImporter = null;
}
}
}