LCFormsServiceImpl.java
7.4 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.ui.clientlibs.HtmlLibraryManager
* com.adobe.granite.ui.clientlibs.LibraryType
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
*/
package com.adobe.forms.service.impl;
import com.adobe.forms.external.service.FormsContext;
import com.adobe.forms.option.LCFormsOptions;
import com.adobe.forms.service.LCFormsOptionService;
import com.adobe.forms.service.LCFormsOsgiService;
import com.adobe.forms.service.LCFormsService;
import com.adobe.granite.ui.clientlibs.HtmlLibraryManager;
import com.adobe.granite.ui.clientlibs.LibraryType;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
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.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
@Component(label="LC Forms Service", description="LC Forms Service")
@Service(value={LCFormsService.class})
@Properties(value={@Property(name="service.description", value={"LC Forms Service"})})
public class LCFormsServiceImpl
implements LCFormsService {
@Reference
private LCFormsOsgiService lcFormsOsgiService;
@Reference
private FormsContext formsContext;
@Reference
private HtmlLibraryManager htmlLibraryManager;
@Reference
LCFormsOptionService lcFormsOptionService;
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public Map<String, Object> render(SlingHttpServletRequest slingRequest) {
try {
this.formsContext.begin();
LCFormsOptions options = this.lcFormsOptionService.createFromRequest(slingRequest);
Map<String, Object> contentMap = this.lcFormsOsgiService.render(options);
for (Map.Entry<String, Object> entry : contentMap.entrySet()) {
slingRequest.setAttribute(entry.getKey(), entry.getValue());
}
Map<String, Object> i$ = contentMap;
return i$;
}
finally {
this.formsContext.end();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public Map<String, Object> render(LCFormsOptions options) {
try {
Map<String, Object> contentMap;
this.formsContext.begin();
Map<String, Object> map = contentMap = this.lcFormsOsgiService.render(options);
return map;
}
finally {
this.formsContext.end();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public Map<String, Object> exportXFA(SlingHttpServletRequest slingRequest) {
try {
this.formsContext.begin();
LCFormsOptions options = this.lcFormsOptionService.createFromRequest(slingRequest);
Map<String, Object> contentMap = this.lcFormsOsgiService.exportXFA(options);
for (Map.Entry<String, Object> entry : contentMap.entrySet()) {
slingRequest.setAttribute(entry.getKey(), entry.getValue());
}
Map<String, Object> i$ = contentMap;
return i$;
}
finally {
this.formsContext.end();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public Map<String, Object> exportXFA(LCFormsOptions options) {
try {
Map<String, Object> contentMap;
this.formsContext.begin();
Map<String, Object> map = contentMap = this.lcFormsOsgiService.exportXFA(options);
return map;
}
finally {
this.formsContext.end();
}
}
@Override
public void clearCache() {
this.lcFormsOsgiService.clearCache();
}
@Override
public String getClientLibNameForCurrentLocale(SlingHttpServletRequest slingRequest) {
String clientLibPrefix = "xfaforms.I18N";
String defaultLocale = "en";
String acceptLang = slingRequest.getHeader("accept-language");
String localeCode = null;
if (acceptLang == null || "".equals(acceptLang.trim())) {
return clientLibPrefix + "." + defaultLocale;
}
String[] locales = StringUtils.split((String)acceptLang, (String)",");
for (int i = 0; i < locales.length; ++i) {
boolean clientLibForLocaleExists;
Collection libraries;
String[] categories;
localeCode = StringUtils.substringBefore((String)locales[i], (String)";");
String[] splitLocale = StringUtils.split((String)localeCode, (String)"-");
localeCode = splitLocale[0].toLowerCase();
if (splitLocale.length > 1) {
localeCode = localeCode + splitLocale[1].toUpperCase();
}
boolean bl = clientLibForLocaleExists = (libraries = this.htmlLibraryManager.getLibraries(categories = new String[]{clientLibPrefix + "." + localeCode}, null, true, false)).toArray().length > 0;
if (clientLibForLocaleExists) {
return clientLibPrefix + "." + localeCode;
}
if (splitLocale.length <= 1) continue;
categories = new String[]{clientLibPrefix + "." + splitLocale[0].toLowerCase()};
libraries = this.htmlLibraryManager.getLibraries(categories, null, true, false);
boolean bl2 = clientLibForLocaleExists = libraries.toArray().length > 0;
if (!clientLibForLocaleExists) continue;
return clientLibPrefix + "." + splitLocale[0].toLowerCase();
}
return clientLibPrefix + "." + defaultLocale;
}
protected void bindLcFormsOsgiService(LCFormsOsgiService lCFormsOsgiService) {
this.lcFormsOsgiService = lCFormsOsgiService;
}
protected void unbindLcFormsOsgiService(LCFormsOsgiService lCFormsOsgiService) {
if (this.lcFormsOsgiService == lCFormsOsgiService) {
this.lcFormsOsgiService = null;
}
}
protected void bindFormsContext(FormsContext formsContext) {
this.formsContext = formsContext;
}
protected void unbindFormsContext(FormsContext formsContext) {
if (this.formsContext == formsContext) {
this.formsContext = null;
}
}
protected void bindHtmlLibraryManager(HtmlLibraryManager htmlLibraryManager) {
this.htmlLibraryManager = htmlLibraryManager;
}
protected void unbindHtmlLibraryManager(HtmlLibraryManager htmlLibraryManager) {
if (this.htmlLibraryManager == htmlLibraryManager) {
this.htmlLibraryManager = null;
}
}
protected void bindLcFormsOptionService(LCFormsOptionService lCFormsOptionService) {
this.lcFormsOptionService = lCFormsOptionService;
}
protected void unbindLcFormsOptionService(LCFormsOptionService lCFormsOptionService) {
if (this.lcFormsOptionService == lCFormsOptionService) {
this.lcFormsOptionService = null;
}
}
}