MCMPluginAdapter.java
3.93 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.mcm.api;
import com.day.cq.mcm.api.Experience;
import com.day.cq.mcm.api.MCMPlugin;
import com.day.cq.mcm.api.Touchpoint;
import com.day.cq.mcm.util.NormalizedResource;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class MCMPluginAdapter
implements MCMPlugin {
private static final Logger log = LoggerFactory.getLogger(MCMPluginAdapter.class);
private HashMap<String, Factory<Experience>> experienceFactoryMap = new HashMap();
private HashMap<String, Factory<Touchpoint>> touchpointFactoryMap = new HashMap();
@Override
public Collection<String> getTouchpointRootComponents() {
return this.touchpointFactoryMap.keySet();
}
@Override
public Collection<String> getExperienceRootComponents() {
return this.experienceFactoryMap.keySet();
}
protected void addExperienceComponent(String compType, Factory<Experience> fac) {
if (fac == null) {
throw new NullPointerException("Factory null");
}
this.experienceFactoryMap.put(compType, fac);
}
protected void addTouchpointComponent(String compType, Factory<Touchpoint> fac) {
if (fac == null) {
throw new NullPointerException("Factory null");
}
this.touchpointFactoryMap.put(compType, fac);
}
@Override
public Experience makeExperience(Resource adaptable) {
Experience retval = null;
String compTypeToSearch = this.extractCompType(adaptable);
if (compTypeToSearch == null) {
throw new RuntimeException("Given resource doesn't have a resource type: " + adaptable.getPath());
}
if (!this.experienceFactoryMap.containsKey(compTypeToSearch)) {
throw new RuntimeException("Unkown resourceType (misuse of the the class? We have: " + this.experienceFactoryMap.toString() + "): " + compTypeToSearch);
}
Factory<Experience> fac = this.experienceFactoryMap.get(compTypeToSearch);
retval = fac.create(adaptable);
return retval;
}
@Override
public Touchpoint makeTouchpoint(Resource adaptable) {
if (adaptable == null) {
throw new NullPointerException("Null passed as Resource adaptable.");
}
Touchpoint retval = null;
String compTypeToSearch = this.extractCompType(adaptable);
if (compTypeToSearch == null) {
throw new RuntimeException("Given resource doesn't have a resource type: " + adaptable.getPath());
}
if (!this.touchpointFactoryMap.containsKey(compTypeToSearch)) {
throw new RuntimeException("Unkown resourceType (misuse of the the class? We have: " + this.touchpointFactoryMap.toString() + "): " + compTypeToSearch);
}
Factory<Touchpoint> fac = this.touchpointFactoryMap.get(compTypeToSearch);
retval = fac.create(adaptable);
return retval;
}
private String extractCompType(Resource adaptable) {
NormalizedResource nr = new NormalizedResource();
nr.setResource(adaptable);
String retval = null;
if (nr.getContentVals() != null) {
retval = (String)nr.getContentVals().get("sling:resourceType", String.class);
}
if (retval == null) {
log.warn("Cannot make an object because resource {} doesn't have content node or resourceType.", (Object)adaptable);
}
return retval;
}
public String toString() {
return super.toString() + "/id:" + this.getPluginId();
}
public static interface Factory<T> {
public T create(Resource var1);
}
}