IntegrationConfigImpl.java 4.78 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Modified
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.commons.osgi.OsgiUtil
 *  org.osgi.service.component.ComponentContext
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.day.cq.mcm.campaign.impl;

import com.day.cq.mcm.campaign.impl.IntegrationConfig;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Modified;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.OsgiUtil;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=1, immediate=1, label="AEM Campaign Integration - Configuration", description="Configures the AEM integration for Adobe Campaign.")
@Service
public class IntegrationConfigImpl
implements IntegrationConfig {
    @Property(value={"string:foundation/components/form/constraints/email", "string:foundation/components/form/constraints/name", "numeric:foundation/components/form/constraints/numeric", "date:foundation/components/form/constraints/date"}, cardinality=4096)
    protected static final String FORM_CONSTRAINTS = "aem.mcm.campaign.formConstraints";
    @Property(value={""})
    protected static final String PUBLIC_URL = "aem.mcm.campaign.publicUrl";
    @Property(boolValue={0})
    protected static final String USE_RELAXED_SSL = "aem.mcm.campaign.relaxedSSL";
    private String[] supportedTypes;
    private Map<String, List<String>> constraintsPerType;
    private String publicUrl;
    private boolean useRelaxedSSL;
    private final Logger log;

    public IntegrationConfigImpl() {
        this.log = LoggerFactory.getLogger(this.getClass());
    }

    private void configure(ComponentContext context) {
        String[] formConstraints;
        Dictionary dict = context.getProperties();
        this.supportedTypes = new String[]{"string", "numeric", "byte", "date"};
        this.constraintsPerType = new HashMap<String, List<String>>();
        for (String formConstraint : formConstraints = OsgiUtil.toStringArray(dict.get("aem.mcm.campaign.formConstraints"))) {
            int sepPos = formConstraint.indexOf(":");
            if (sepPos <= 0) continue;
            String type = formConstraint.substring(0, sepPos);
            String constraint = formConstraint.substring(sepPos + 1);
            List<String> typeConstraints = this.constraintsPerType.get(type);
            if (typeConstraints == null) {
                typeConstraints = new ArrayList<String>();
                this.constraintsPerType.put(type, typeConstraints);
            }
            typeConstraints.add(constraint);
            this.log.debug("Constraint for type {}: {}", new Object[]{type, constraint});
        }
        this.publicUrl = OsgiUtil.toString(dict.get("aem.mcm.campaign.publicUrl"), (String)"");
        String string = this.publicUrl = this.publicUrl.length() > 0 ? this.publicUrl : null;
        if (this.publicUrl != null && this.publicUrl.endsWith("/")) {
            this.publicUrl = this.publicUrl.substring(0, this.publicUrl.length() - 1);
        }
        this.log.debug("Public URL: {}", (Object)(this.publicUrl != null ? this.publicUrl : "<use replication agent setting>"));
        this.useRelaxedSSL = OsgiUtil.toBoolean(dict.get("aem.mcm.campaign.relaxedSSL"), (boolean)false);
        this.log.debug("Use relaxed SSL: {}", (Object)this.useRelaxedSSL);
    }

    @Activate
    protected void activate(ComponentContext context) {
        this.configure(context);
    }

    @Modified
    protected void modified(ComponentContext context) {
        this.configure(context);
    }

    @Override
    public String[] getSupportedTypes() {
        return this.supportedTypes;
    }

    @Override
    public boolean isSupportedType(String type) {
        for (String toCheck : this.supportedTypes) {
            if (!toCheck.equals(type)) continue;
            return true;
        }
        return false;
    }

    @Override
    public List<String> getFormConstraints(String type) {
        if (!this.constraintsPerType.containsKey(type)) {
            throw new IllegalArgumentException("Unsupported type: " + type);
        }
        return this.constraintsPerType.get(type);
    }

    @Override
    public String getPublicUrl() {
        return this.publicUrl;
    }

    @Override
    public boolean useRelaxedSSL() {
        return this.useRelaxedSSL;
    }
}