ConfMgrImpl.java
3.13 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.commons.lang.ArrayUtils
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.service.component.ComponentContext
*/
package com.adobe.granite.confmgr.impl;
import com.adobe.granite.confmgr.Conf;
import com.adobe.granite.confmgr.ConfMgr;
import com.adobe.granite.confmgr.impl.ConfImpl;
import java.util.Dictionary;
import org.apache.commons.lang.ArrayUtils;
import org.apache.felix.scr.annotations.Activate;
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.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
@Component(metatype=1, label="Adobe Granite ConfMgr", description="Standardized access to configurations in the repository")
@Service
@Properties(value={@Property(name="service.description", value={"Adobe Granite ConfMgr"})})
public class ConfMgrImpl
implements ConfMgr {
@Property(value={"/conf/*", "/apps", "/libs"}, label="Allowed paths", description="Whitelist of path globs where configurations can reside in.")
private static final String PROPERTY_ALLOWED_PATHS = "confmgr.allowed.paths";
@Property(value={"/libs", "/apps", "/conf/global"}, label="Fallback paths", description="Global fallback configurations, ordered from least specific (checked last) to most specific.")
private static final String PROPERTY_FALLBACK_PATHS = "confmgr.fallback.paths";
private String[] allowedPaths = new String[0];
private String[] fallbackPaths = new String[0];
public Conf getConf(Resource resource) {
return new ConfImpl(resource, null, this.allowedPaths, this.fallbackPaths);
}
public Conf getConf(Resource resource, ResourceResolver configResolver) {
return new ConfImpl(resource, configResolver, this.allowedPaths, this.fallbackPaths);
}
public ConfMgrImpl() {
}
public ConfMgrImpl(String[] allowedPaths, String[] fallbackPaths) {
this.allowedPaths = allowedPaths;
this.fallbackPaths = fallbackPaths;
ArrayUtils.reverse((Object[])fallbackPaths);
}
public String[] getAllowedPaths() {
return this.allowedPaths;
}
public String[] getFallbackPaths() {
return this.fallbackPaths;
}
@Activate
private void activate(ComponentContext ctx) {
this.allowedPaths = PropertiesUtil.toStringArray(ctx.getProperties().get("confmgr.allowed.paths"));
this.fallbackPaths = PropertiesUtil.toStringArray(ctx.getProperties().get("confmgr.fallback.paths"));
ArrayUtils.reverse((Object[])this.fallbackPaths);
}
}