LaunchLiveActionFactoryBase.java
6.6 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
124
125
126
127
128
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.LiveAction
* com.day.cq.wcm.msm.api.LiveActionFactory
* 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.PropertyUnbounded
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.wrappers.ValueMapDecorator
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.service.component.ComponentContext
*/
package com.adobe.cq.wcm.launches.impl.msm.utils;
import com.adobe.cq.wcm.launches.impl.msm.utils.LaunchExclusionConfig;
import com.adobe.cq.wcm.launches.impl.msm.utils.LaunchLiveActionBase;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveActionFactory;
import java.util.Arrays;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
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.PropertyUnbounded;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
@Component(metatype=0, componentAbstract=1)
public abstract class LaunchLiveActionFactoryBase<Type extends LaunchLiveActionBase>
implements LiveActionFactory<Type> {
private static final String[] EMPTY_CONFIG = new String[0];
public static final String PARAMETER_EXCLUDED_PROPERTIES = "cq.wcm.msm.action.excludedprops";
@Property(name="cq.wcm.msm.action.excludedprops", unbounded=PropertyUnbounded.ARRAY)
public static String[] EXCLUDED_PROPERTIES_DEFAULT = new String[]{"jcr:.*", "sling:.*", "cq:.*"};
public static final String PARAMETER_EXCLUDED_PARAGRAPH_ITEMS = "cq.wcm.msm.action.excludedparagraphitems";
@Property(name="cq.wcm.msm.action.excludedparagraphitems", unbounded=PropertyUnbounded.ARRAY)
public static final String[] EXCLUDED_PARAGRAPH_ITEMS_DEFAULT = new String[]{"cq:propertyInheritanceCancelled"};
public static final String PARAMETER_EXCLUDED_NODE_TYPES = "cq.wcm.msm.action.excludednodetypes";
@Property(name="cq.wcm.msm.action.excludednodetypes", unbounded=PropertyUnbounded.ARRAY)
public static final String[] EXCLUDED_NODE_TYPES_DEFAULT = new String[]{"cq:LiveSyncAction", "cq:LiveSyncConfig", "cq:BlueprintSyncConfig"};
public static final String PARAMETER_RESERVED_PROPERTIES = "cq.wcm.msm.action.reservedproperties";
@Property(name="cq.wcm.msm.action.reservedproperties", unbounded=PropertyUnbounded.ARRAY)
public static final String[] RESERVED_PROPERTIES_DEFAULT = new String[]{"cq:isCancelledForChildren", "cq:lastRolledout", "cq:lastRolledoutBy"};
private LaunchExclusionConfig exclusionConfig;
private Dictionary props;
@Activate
@Modified
protected void activate(ComponentContext context) {
this.props = context.getProperties();
String[] pageProperties = PropertiesUtil.toStringArray(context.getProperties().get("cq.wcm.msm.action.excludedprops"), (String[])EMPTY_CONFIG);
String[] paragraphItems = PropertiesUtil.toStringArray(context.getProperties().get("cq.wcm.msm.action.excludedparagraphitems"), (String[])EMPTY_CONFIG);
String[] nodeTypes = PropertiesUtil.toStringArray(context.getProperties().get("cq.wcm.msm.action.excludednodetypes"), (String[])EMPTY_CONFIG);
List<String> reservedProperties = Arrays.asList(PropertiesUtil.toStringArray(context.getProperties().get("cq.wcm.msm.action.reservedproperties"), (String[])EMPTY_CONFIG));
HashSet<String> excludedPageProperties = new HashSet<String>(Arrays.asList(pageProperties));
excludedPageProperties.addAll(reservedProperties);
HashSet<String> excludedParagraphItems = new HashSet<String>(Arrays.asList(paragraphItems));
excludedParagraphItems.addAll(reservedProperties);
HashSet<String> excludedNodeTypes = new HashSet<String>(Arrays.asList(nodeTypes));
this.exclusionConfig = new LaunchExclusionConfig(excludedPageProperties, excludedParagraphItems, excludedNodeTypes);
}
public Type createAction(Resource resource) throws WCMException {
final ValueMap resourceMap = resource != null ? (ValueMap)resource.adaptTo(ValueMap.class) : null;
ValueMapDecorator map = new ValueMapDecorator(this.getLegacyProperties()){
public <T> T get(String name, Class<T> type) {
if (resourceMap != null && resourceMap.containsKey((Object)name)) {
return (T)resourceMap.get(name, type);
}
return (T)super.get(name, type);
}
public <T> T get(String name, T defaultValue) {
if (resourceMap != null && resourceMap.containsKey((Object)name)) {
return (T)resourceMap.get(name, defaultValue);
}
return (T)super.get(name, defaultValue);
}
public Object get(Object key) {
if (resourceMap != null && resourceMap.containsKey(key)) {
return resourceMap.get(key);
}
return super.get(key);
}
public boolean containsKey(Object key) {
if (resourceMap != null && resourceMap.containsKey(key)) {
return true;
}
return super.containsKey(key);
}
};
return this.createAction((ValueMap)map, this.exclusionConfig);
}
protected abstract Type createAction(ValueMap var1, LaunchExclusionConfig var2);
private Map<String, Object> getLegacyProperties() {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("cq.wcm.msm.action.rank", this.props.get("cq.wcm.msm.action.rank"));
map.put("cq.wcm.msm.action.properties", PropertiesUtil.toStringArray(this.props.get("cq.wcm.msm.action.properties")));
map.put("cq.wcm.msm.action.parameter", this.props.get("cq.wcm.msm.action.parameter"));
map.put("cq.wcm.msm.action.title", this.props.get("cq.wcm.msm.action.title"));
map.put("actiontype", this.props.get("actiontype"));
return map;
}
}