ConfMgrImpl.java 3.13 KB
/*
 * 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);
    }
}