AbstractMobileAppProvider.java
3.59 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.contentsync.config.Config
* 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.cq.mobile.platform.impl;
import com.adobe.cq.mobile.platform.impl.MobileAppProvider;
import com.adobe.cq.mobile.platform.impl.MobileValueMapDecorator;
import com.adobe.cq.mobile.platform.impl.utils.MobileUtil;
import com.day.cq.contentsync.config.Config;
import java.util.HashMap;
import java.util.Map;
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;
public abstract class AbstractMobileAppProvider
implements MobileAppProvider {
private static final Logger log = LoggerFactory.getLogger(AbstractMobileAppProvider.class);
protected static final String PN_CS_CONFIG_PATH = "phonegap-contentSyncConfigPath";
protected Resource resource;
protected ResourceResolver resolver;
protected AbstractMobileAppProvider(Resource resource) {
if (resource == null) {
throw new IllegalArgumentException("The mobile resource cannot be null.");
}
this.resource = resource;
this.resolver = resource.getResourceResolver();
}
@Override
public ValueMap getProperties() {
Resource contentRes = this.getContentResource();
Resource resolvedResource = contentRes != null ? contentRes : this.resource;
return new MobileValueMapDecorator(resolvedResource);
}
@Override
public Map<String, Config> findResourceConfigs() {
HashMap<String, Config> envList = new HashMap<String, Config>();
ValueMap properties = this.getContentResource().getValueMap();
String exportTemplate = (String)properties.get("phonegap-exportTemplate", String.class);
if (exportTemplate == null) {
exportTemplate = (String)properties.get("phonegap-contentSyncConfigPath", String.class);
}
this.addConfigToEnv("STAGE", exportTemplate, envList);
String configPath = (String)properties.get("phonegap-build-exportTemplate", String.class);
this.addConfigToEnv("BUILD-STAGE", configPath, envList);
configPath = (String)properties.get("phonegap-build-exportTemplate-dev", String.class);
this.addConfigToEnv("BUILD-DEV", configPath, envList);
return envList;
}
private void addConfigToEnv(String envKey, String configPath, HashMap<String, Config> envList) {
if (configPath != null) {
Resource configResource = this.resolver.getResource(configPath = MobileUtil.normalizePath(configPath, this.getContentResource()));
if (configResource != null) {
envList.put(envKey, (Config)configResource.adaptTo(Config.class));
} else {
log.error("Non existing config {} for key {}", (Object[])new String[]{configPath, envKey});
}
}
}
protected Config getDefaultConfig() {
Map<String, Config> configMap = this.findResourceConfigs();
if (configMap != null && configMap.containsKey("STAGE")) {
configMap.get("STAGE");
}
return null;
}
public Resource getContentResource() {
if (!"jcr:content".equals(this.resource.getName()) && this.resource.getChild("jcr:content") != null) {
return this.resource.getChild("jcr:content");
}
return this.resource;
}
}