AdXmlDataProviderImpl.java
8.93 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemds.guide.utils.GuideContainerThreadLocal
* com.adobe.dct.exception.DCTException
* com.adobe.dct.service.DataDictionaryRegistryService
* com.adobe.dct.transfer.DataDictionary
* com.adobe.dct.transfer.DataDictionarySearchFilter
* com.adobe.forms.common.service.DataXMLOptions
* com.adobe.forms.common.service.DataXMLProvider
* com.adobe.forms.common.service.FormsException
* com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
* com.adobe.icc.dbforms.obj.Letter
* com.adobe.icc.services.api.LetterService
* 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.ReferenceCardinality
* 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.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.adaddon.service.impl;
import com.adobe.aemds.guide.utils.GuideContainerThreadLocal;
import com.adobe.dct.exception.DCTException;
import com.adobe.dct.service.DataDictionaryRegistryService;
import com.adobe.dct.transfer.DataDictionary;
import com.adobe.dct.transfer.DataDictionarySearchFilter;
import com.adobe.forms.common.service.DataXMLOptions;
import com.adobe.forms.common.service.DataXMLProvider;
import com.adobe.forms.common.service.FormsException;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import com.adobe.icc.dbforms.obj.Letter;
import com.adobe.icc.services.api.LetterService;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
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.ReferenceCardinality;
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.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=1, label="AdXmlDataProviderImpl", description="AdXmlDataProviderImpl")
@Service(value={DataXMLProvider.class})
public class AdXmlDataProviderImpl
implements DataXMLProvider {
private static Logger logger = LoggerFactory.getLogger(AdXmlDataProviderImpl.class);
@Property(intValue={2100})
private static final String SERVICE_RANKING = "service.ranking";
@Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
private ResourceResolverHelper resolverHelper;
@Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
private LetterService letterService;
@Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
private DataDictionaryRegistryService dataDictionaryRegistryService;
private byte[] getDataXMLForDataRef(String s) throws FormsException {
logger.trace("getDataXMLForDataRef: url= " + s);
if ("ad-testdata://AD_EMPTY_DATA".equals(s)) {
return this.strToBytes("<?xml version=\"1.0\" ?><root/>");
}
logger.trace("getDataXMLForDataRef:resolverHelper= " + (Object)this.resolverHelper);
if ("ad-testdata://USE_TEST_DATA".equals(s)) {
try {
return this.getTestData();
}
catch (Exception e) {
logger.error("Error when getting test from dd", (Throwable)e);
throw new FormsException(e);
}
}
return null;
}
private byte[] getTestData() throws Exception {
String guideContainerPath = GuideContainerThreadLocal.getGuideContainerPath();
logger.trace("getTestData:guideContainerPath :" + guideContainerPath);
ResourceResolver resourceResolver = this.resolverHelper.getResourceResolver();
Resource guideContainerResource = resourceResolver.getResource(guideContainerPath);
logger.trace("getTestData: guideContainerResource " + (Object)guideContainerResource);
if (guideContainerResource != null) {
ValueMap guideProps = guideContainerResource.getValueMap();
String ddRef = (String)guideProps.get("ddRef", (Object)"");
String letterRef = (String)guideProps.get("letterRef", (Object)"");
logger.trace("getTestData: ddRef= " + ddRef);
logger.trace("getTestData: letterRef= " + letterRef);
if (StringUtils.isNotBlank((CharSequence)letterRef)) {
if (this.letterService == null) {
logger.error("getTestData: LetterService is null, should not be null in AD with letterRef");
throw new Exception(" LetterService is null");
}
Letter letter = this.letterService.getLetter(letterRef, false);
if (letter == null) {
throw new Exception(" letter is null");
}
ddRef = letter.getDataDictionaryRef();
logger.trace("getTestData: ddRef from letter : " + ddRef);
}
if (StringUtils.isNotBlank((CharSequence)ddRef)) {
if (this.dataDictionaryRegistryService == null) {
logger.error("getTestData: dataDictionaryRegistryService is null, should not be null in AD with ddRef");
throw new Exception(" dataDictionaryRegistryService is null");
}
DataDictionary dataDictionary = null;
dataDictionary = ddRef.contains("/") ? this.dataDictionaryRegistryService.getDataDictionary(ddRef) : this.getDataDictionaryFromName(ddRef);
if (dataDictionary == null) {
throw new Exception(" DataDictionary is null");
}
byte[] testData = dataDictionary.getTestdata();
if (testData != null && testData.length > 0) {
return testData;
}
return this.strToBytes("<?xml version=\"1.0\" ?><root/>");
}
return this.strToBytes("<?xml version=\"1.0\" ?><root/>");
}
throw new Exception("guideContainerResource is null");
}
private DataDictionary getDataDictionaryFromName(String ddName) throws DCTException {
logger.trace("getDataDictionaryFromName : " + ddName);
DataDictionarySearchFilter ddsf = new DataDictionarySearchFilter();
ddsf.setName(ddName.trim());
List dataDictionaryList = this.dataDictionaryRegistryService.getDataDictionaries(ddsf);
logger.trace("getDataDictionaryFromName: DataDictionaries : {} ", (Object)dataDictionaryList);
if (dataDictionaryList != null && dataDictionaryList.size() > 0) {
return (DataDictionary)dataDictionaryList.get(0);
}
return null;
}
public InputStream getDataXMLForDataRef(DataXMLOptions dataXMLOptions) throws FormsException {
byte[] data = this.getDataXMLForDataRef(dataXMLOptions.getDataRef());
if (data != null) {
return new ByteArrayInputStream(data);
}
return null;
}
private byte[] strToBytes(String str) throws FormsException {
try {
return str.getBytes("UTF-8");
}
catch (UnsupportedEncodingException e) {
throw new FormsException((Exception)e);
}
}
public String getServiceName() {
return null;
}
public String getServiceDescription() {
return null;
}
protected void bindResolverHelper(ResourceResolverHelper resourceResolverHelper) {
this.resolverHelper = resourceResolverHelper;
}
protected void unbindResolverHelper(ResourceResolverHelper resourceResolverHelper) {
if (this.resolverHelper == resourceResolverHelper) {
this.resolverHelper = null;
}
}
protected void bindLetterService(LetterService letterService) {
this.letterService = letterService;
}
protected void unbindLetterService(LetterService letterService) {
if (this.letterService == letterService) {
this.letterService = null;
}
}
protected void bindDataDictionaryRegistryService(DataDictionaryRegistryService dataDictionaryRegistryService) {
this.dataDictionaryRegistryService = dataDictionaryRegistryService;
}
protected void unbindDataDictionaryRegistryService(DataDictionaryRegistryService dataDictionaryRegistryService) {
if (this.dataDictionaryRegistryService == dataDictionaryRegistryService) {
this.dataDictionaryRegistryService = null;
}
}
}