AppInstanceProviderImpl.java
11.6 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.Externalizer
* com.day.cq.contentsync.config.Config
* javax.jcr.Session
* org.apache.commons.lang3.StringUtils
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceUtil
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.phonegap.impl;
import com.adobe.cq.mobile.appcache.impl.AppCacheManager;
import com.adobe.cq.mobile.appcache.impl.AppCacheManagerAdapterFactory;
import com.adobe.cq.mobile.appcache.impl.CacheUpdate;
import com.adobe.cq.mobile.platform.impl.AbstractMobileAppProvider;
import com.adobe.cq.mobile.platform.impl.MobileAppException;
import com.adobe.cq.mobile.platform.impl.MobileAppProvider;
import com.adobe.cq.mobile.platform.impl.WidgetConfigDocument;
import com.day.cq.commons.Externalizer;
import com.day.cq.contentsync.config.Config;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.jcr.Session;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
public class AppInstanceProviderImpl
extends AbstractMobileAppProvider
implements MobileAppProvider {
private static final Logger log = LoggerFactory.getLogger(AppInstanceProviderImpl.class);
private static final String DEFAULT_ICON_PATH = "/libs/mobileapps/gui/components/dashboard/tiles/info/thumbnail/icon.png";
private static final String NN_CONFIG_XML = "config.xml";
private static final String NN_STORE = "store";
private final AppCacheManagerAdapterFactory appCacheManagerAdapterFactory;
private final Resource contentRes;
private ValueMap properties;
private final List<String> appPlatforms;
public AppInstanceProviderImpl(Resource resource, AppCacheManagerAdapterFactory appCacheManagerAdapterFactory, List<String> appPlatforms) {
super(resource);
if (appPlatforms == null) {
appPlatforms = new ArrayList<String>();
}
this.appPlatforms = appPlatforms;
this.appCacheManagerAdapterFactory = appCacheManagerAdapterFactory;
this.contentRes = this.getContentResource();
this.properties = null;
}
@Override
public ValueMap getProperties() {
Config defaultConfig;
if (this.properties != null) {
return this.properties;
}
ValueMap properties = super.getProperties();
if (!this.addWidgetConfigProperties(properties)) {
try {
properties.clear();
properties.putAll((Map)super.getProperties());
properties.put((Object)"widgetConfigPath", (Object)"");
}
catch (UnsupportedOperationException ex) {
// empty catch block
}
}
this.addResourceProperties(this.contentRes.getChild("store"), properties, "store");
String serverURL = (String)properties.get("serverURL", String.class);
if (StringUtils.isEmpty((CharSequence)serverURL)) {
Externalizer externalizer = (Externalizer)this.resolver.adaptTo(Externalizer.class);
properties.put((Object)"serverURL", (Object)externalizer.publishLink(this.resolver, "/"));
}
if ((defaultConfig = this.getDefaultConfig()) != null) {
AppCacheManager appCacheManager = this.appCacheManagerAdapterFactory.getAdapter(this.resolver.adaptTo(Session.class), AppCacheManager.class);
CacheUpdate update = appCacheManager.getLastUpdate(defaultConfig);
long updateTime = 0;
try {
if (update != null) {
updateTime = update.getCreated().getTimeInMillis();
}
}
catch (Exception e) {
log.error("Unable to determine update time for {}", (Object)defaultConfig.getPath());
}
properties.put((Object)"updateTimestamp", (Object)updateTime);
}
this.addRPSProperties(properties);
return properties;
}
private boolean addWidgetConfigProperties(ValueMap properties) {
Resource configRes = this.findWidgetConfigResource((String)properties.get("widgetConfigPath", String.class));
if (configRes == null) {
log.debug("Unable to locate widget config resource.");
return true;
}
try {
WidgetConfigDocument widgetConfig = WidgetConfigDocument.loadConfigDocument(configRes.getPath(), this.contentRes);
if (widgetConfig != null) {
Resource iconRes;
properties.put((Object)"widgetConfigPath", (Object)configRes.getPath());
properties.put((Object)"widget/id", (Object)widgetConfig.getId());
properties.put((Object)"widget/version", (Object)widgetConfig.getVersion());
properties.put((Object)"widget/name/text", (Object)widgetConfig.getName());
properties.put((Object)"widget/description/text", (Object)widgetConfig.getDescription());
Map<String, String> author = widgetConfig.getAuthor();
if (author != null) {
properties.put((Object)"widget/author/text", (Object)author.get("value"));
properties.put((Object)"widget/author/href", (Object)author.get("href"));
properties.put((Object)"widget/author/email", (Object)author.get("email"));
}
properties.put((Object)"widget/preferences/phonegap-version/value", (Object)widgetConfig.getPreferenceValue("phonegap-version"));
properties.put((Object)"widget/access/origin", (Object)widgetConfig.getAccessOrigin());
properties.put((Object)"widget/content/src", (Object)widgetConfig.getContentSource());
List<String> platforms = widgetConfig.getPlatforms();
if (platforms.isEmpty()) {
platforms = this.appPlatforms;
}
String[] p = platforms.toArray(new String[platforms.size()]);
properties.put((Object)"widget/platforms", (Object)p);
properties.put((Object)"widget/plugins", widgetConfig.getPlugins());
Element iconElement = widgetConfig.getDefaultIconElement();
if (iconElement != null) {
properties.put((Object)"widget/icon/src", (Object)iconElement.getAttribute("src"));
properties.put((Object)"widget/icon/fileReference", (Object)iconElement.getAttribute("fileReference"));
}
if ((iconRes = this.findIconResource(widgetConfig)) != null) {
properties.put((Object)"iconPath", (Object)iconRes.getPath());
}
return true;
}
}
catch (MobileAppException e) {
log.error("Unable to add widget config properties", (Throwable)e);
}
return false;
}
public Resource getWidgetResource() {
return this.contentRes.getChild("widget");
}
private Resource findContentResource(String basePath, String childPath) {
Resource baseResource = this.contentRes.getChild(basePath);
if (baseResource != null) {
Resource childContentResource = baseResource.getChild(childPath);
if ((childContentResource == null || ResourceUtil.isNonExistingResource((Resource)childContentResource)) && !"www".equals(baseResource.getName())) {
Resource r;
Iterable allChildren = baseResource.getChildren();
Iterator i$ = allChildren.iterator();
while (i$.hasNext() && ("jcr:content".equals((r = (Resource)i$.next()).getName()) || (childContentResource = this.findContentResource(r.getPath(), childPath)) == null || ResourceUtil.isNonExistingResource((Resource)childContentResource))) {
}
}
return childContentResource;
}
return null;
}
private Resource findWidgetConfigResource(String path) {
Resource configRes = null;
if (StringUtils.isNotEmpty((CharSequence)path) && (configRes = this.resolver.getResource(path)) != null) {
return configRes;
}
String appContentPath = (String)this.contentRes.getValueMap().get("appAssetPath", String.class);
if (StringUtils.isNotEmpty((CharSequence)appContentPath)) {
configRes = this.findContentResource(appContentPath, "config.xml");
}
if (configRes == null || ResourceUtil.isNonExistingResource((Resource)configRes)) {
configRes = this.findContentResource("pge-app/app-content/phonegap", "config.xml");
}
return configRes;
}
private Resource findIconResource(WidgetConfigDocument configDoc) {
try {
String iconSrc = configDoc.getDefaultIconPath();
if (StringUtils.isNotBlank((CharSequence)iconSrc)) {
Resource iconRes = this.resolver.getResource(iconSrc);
if (iconRes == null) {
String appContentPath = (String)this.contentRes.getValueMap().get("appAssetPath", String.class);
iconRes = this.findContentResource(appContentPath, iconSrc);
}
if (iconRes == null) {
iconRes = this.findContentResource("pge-app/app-content/images", iconSrc);
}
if (iconRes == null) {
iconRes = this.findContentResource("pge-app/app-content/phonegap", iconSrc);
}
if (iconRes != null) {
return iconRes;
}
}
}
catch (MobileAppException e) {
log.error("Unable to find an icon for this mobile resource.", (Throwable)e);
}
return this.resolver.getResource("/libs/mobileapps/gui/components/dashboard/tiles/info/thumbnail/icon.png");
}
private ValueMap addRPSProperties(ValueMap instanceVM) {
Resource rpsCloudService;
String notificationConfig;
if (instanceVM.containsKey((Object)"notificationConfig") && !StringUtils.isEmpty((CharSequence)(notificationConfig = (String)instanceVM.get("notificationConfig", String.class))) && !ResourceUtil.isNonExistingResource((Resource)(rpsCloudService = this.resolver.resolve(notificationConfig)))) {
this.addResourceProperties(rpsCloudService.getChild("jcr:content"), instanceVM, "rps");
Resource rpsCloudParentContent = rpsCloudService.getParent().getChild("jcr:content");
ValueMap parentContentVM = rpsCloudParentContent.getValueMap();
String pushServiceId = (String)parentContentVM.get("pushServiceId", String.class);
if (pushServiceId != null) {
instanceVM.put((Object)"rps/pushServiceId", (Object)pushServiceId);
}
}
return instanceVM;
}
private void addResourceProperties(Resource res, ValueMap props, String namespace) {
if (res != null) {
if (namespace == null) {
namespace = res.getName();
}
ValueMap resProps = res.getValueMap();
for (Map.Entry entry : resProps.entrySet()) {
if (((String)entry.getKey()).contains(":")) continue;
props.put((Object)(namespace + "/" + (String)entry.getKey()), entry.getValue());
}
}
}
}