LCFormsAdminServiceImpl.java
9.65 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
204
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.PropertyOption
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.commons.osgi.OsgiUtil
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
* scala.Option
*/
package com.adobe.forms.admin.impl;
import com.adobe.forms.admin.LCFormsAdminService;
import com.adobe.forms.cache.LCFormsCacheConfig;
import com.adobe.forms.cache.impl.CacheConfigParam;
import com.adobe.forms.service.LCFormsOsgiService;
import com.adobe.forms.service.impl.LCFormsOptionServiceImpl;
import java.util.Dictionary;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyOption;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.Option;
@Component(label="Mobile Forms Configurations", description="Mobile Forms Configurations", metatype=1, immediate=1)
@Service(value={LCFormsAdminService.class, LCFormsCacheConfig.class})
public class LCFormsAdminServiceImpl
implements LCFormsAdminService,
LCFormsCacheConfig {
private static Logger logger = LoggerFactory.getLogger(LCFormsAdminServiceImpl.class);
private static final String CACHE_STRATEGY_NONE = "none";
private static final String CACHE_STRATEGY_CONSERVATIVE = "conservative";
private static final String CACHE_STRATEGY_AGGRESIVE = "aggressive";
@Property(value={"aggressive"}, label="Caching Strategy", description="Caching Strategy", options={@PropertyOption(name="none", value="None"), @PropertyOption(name="conservative", value="Conservative"), @PropertyOption(name="aggressive", value="Aggressive")})
private static final String CACHE_STRATEGY = "lcforms.cache.strategy";
private String cacheStrategy;
private static final String CACHE_SIZE_DEFAULT = "128";
@Property(value={"128"}, label="Cache Size in terms of number of forms (128)", description="Number of forms to cache in-memory")
private static final String MAX_CACHE_SIZE = "lcforms.cache.unit";
private Long cacheSize;
private static final String MAX_OBJECT_SIZE_DEFAULT = "8M";
@Property(value={"8M"}, label="Max Object Size to be cached(8M)", description="Max Object Size limit to be cached")
private static final String MAX_CACHE_OBJECT_SIZE = "lcforms.cache.maxObjectSize";
private String maxObjectSize;
@Property(value={""}, label="Debug Options", description="Options for enabling debugging. e.g.: 1-a5-b5-c5")
private static final String DEBUG_OPTIONS = "lcforms.debug.debugOptions";
private String debugOptions = "";
@Property(boolValue={0}, label="Allow debug parameters in request", description="If enabled, HTML5 Forms would start honoring debugDir & log parameters")
private static final String ALLOW_DEBUG_PARAMETERS = "lcforms.debug.allowDebugParameters";
private boolean allowDebugParameters = false;
private static final String DefaultLevel = "2";
private static final String[] LoggerType = new String[]{"off", "console", "server", "consoleServer"};
private static final String[] Category = new String[]{"a", "b", "c"};
@Property(boolValue={1}, label="Embed Http/Https Images", description="select the option to embed Http/Https images using the data scheme instead of the http/https url in html")
private static final String EMBED_HTTP_IMAGES = "lcforms.model.embedHttpImages";
private boolean embedHttpImages = true;
private LCFormsOsgiService lcFormsOsgiService;
@Property(boolValue={0}, label="Keep Data Description", description="select the option to keep the dataDescription Tag in dataXML. This will increase the size of dataxml")
private static final String KEEP_DATA_DESCRIPTION_OPTION = "lcforms.data.keepDataDescription";
private boolean keepDataDescription = false;
@Property(boolValue={1}, label="Protected Mode", description="select the option to enable protected mode")
private static final String PROTECTED_MODE_OPTION = "lcforms.data.protectedMode";
private boolean protectedMode = true;
private static final String LOGGING_LEVEL_XFA = "xfaLevel";
private static final String LOGGING_LEVEL_VIEW = "xfaViewLevel";
private static final String LOGGING_LEVEL_PERF = "xfaPerfLevel";
private static final String LOGGING_ENABLED = "loggingEnabled";
private static final String LOGGER_TYPE = "loggerType";
private static final String CATEGORY_XFA = "a";
private static final String CATEGORY_VIEW = "b";
private static final String CATEGORY_PERF = "c";
@Override
public String getCacheStrategy() {
return this.cacheStrategy;
}
private String getOrElse(Option<String> option, String defaultVal) {
if (option.isDefined()) {
return (String)option.get();
}
return defaultVal;
}
@Deprecated
@Override
public String getOriginalVersion() {
return "";
}
protected void activate(ComponentContext context) {
Dictionary props = context.getProperties();
String newCacheStrategy = OsgiUtil.toString(props.get("lcforms.cache.strategy"), (String)"aggressive");
String oldCacheStrategy = this.getCacheStrategy();
if ("none".equalsIgnoreCase(newCacheStrategy) && !newCacheStrategy.equalsIgnoreCase(oldCacheStrategy) && this.lcFormsOsgiService != null) {
this.lcFormsOsgiService.clearCache();
}
this.cacheStrategy = newCacheStrategy;
this.cacheSize = OsgiUtil.toLong(props.get("lcforms.cache.unit"), (long)Long.parseLong("128"));
this.maxObjectSize = this.getOrElse(CacheConfigParam.getValidSize(OsgiUtil.toString(props.get("lcforms.cache.maxObjectSize"), (String)"8M")), "8M");
this.debugOptions = OsgiUtil.toString(props.get("lcforms.debug.debugOptions"), (String)"");
this.keepDataDescription = OsgiUtil.toBoolean(props.get("lcforms.data.keepDataDescription"), (boolean)false);
this.embedHttpImages = OsgiUtil.toBoolean(props.get("lcforms.model.embedHttpImages"), (boolean)true);
this.allowDebugParameters = OsgiUtil.toBoolean(props.get("lcforms.debug.allowDebugParameters"), (boolean)false);
this.protectedMode = PropertiesUtil.toBoolean(props.get("lcforms.data.protectedMode"), (boolean)true);
}
@Override
public long getCacheSize() {
return this.cacheSize;
}
@Override
public String getMaxObjectSize() {
return this.maxObjectSize;
}
private String readValue(String splitParam, String category) {
if (splitParam != null && splitParam.startsWith(category)) {
return splitParam.substring(category.length());
}
return null;
}
@Override
public void setupLogging(SlingHttpServletRequest slingRequest) {
if (slingRequest == null) {
throw new IllegalArgumentException();
}
String logParam = LCFormsOptionServiceImpl.getAttributeOrRequestParam(slingRequest, "log", this);
if (logParam == null || "".equals(logParam.trim())) {
logParam = this.debugOptions;
}
slingRequest.setAttribute("xfaLevel", (Object)"2");
slingRequest.setAttribute("xfaViewLevel", (Object)"2");
slingRequest.setAttribute("xfaPerfLevel", (Object)"2");
slingRequest.setAttribute("loggingEnabled", (Object)"false");
int level = 1;
String loggerType = LoggerType[level];
slingRequest.setAttribute("loggerType", (Object)loggerType);
if (logParam != null && !"".equals(logParam.trim())) {
slingRequest.setAttribute("loggingEnabled", (Object)"true");
String[] splitParams = logParam.split("-");
if (splitParams.length >= 1) {
try {
level = Integer.parseInt(splitParams[0]);
}
catch (Exception e) {
logger.debug("Error parsing logParam: " + logParam, (Throwable)e);
}
loggerType = LoggerType[level];
}
slingRequest.setAttribute("loggerType", (Object)loggerType);
for (int i = 1; i < splitParams.length; ++i) {
String xfaLevel = this.readValue(splitParams[i], "a");
if (xfaLevel == null) {
String xfaViewLevel = this.readValue(splitParams[i], "b");
if (xfaViewLevel == null) {
String xfaPerfLevel = this.readValue(splitParams[i], "c");
if (xfaPerfLevel == null) continue;
slingRequest.setAttribute("xfaPerfLevel", (Object)xfaPerfLevel);
continue;
}
slingRequest.setAttribute("xfaViewLevel", (Object)xfaViewLevel);
continue;
}
slingRequest.setAttribute("xfaLevel", (Object)xfaLevel);
}
}
}
@Override
public boolean isKeepDataDescription() {
return this.keepDataDescription;
}
@Override
public boolean isEmbedHttpImages() {
return this.embedHttpImages;
}
@Override
public boolean isAllowDebugParameters() {
return this.allowDebugParameters;
}
@Override
public boolean isProtectedMode() {
return this.protectedMode;
}
}