IntegrationConfigImpl.java
4.78 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
/*
* 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;
}
}