ContentUpdateActionFactory.java
9.56 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.LiveAction
* com.day.cq.wcm.msm.api.LiveRelationship
* com.day.cq.wcm.msm.api.LiveStatus
* com.day.cq.wcm.msm.api.RolloutManager
* com.day.cq.wcm.msm.commons.BaseActionFactory
* com.day.cq.wcm.msm.commons.FilteredAction
* com.day.cq.wcm.msm.commons.ItemFilterImpl
* com.day.cq.wcm.msm.commons.ItemFilterUtil
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.nodetype.NodeType
* javax.jcr.nodetype.PropertyDefinition
* 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.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.service.component.ComponentContext
*/
package com.day.cq.wcm.msm.impl.actions;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.LiveAction;
import com.day.cq.wcm.msm.api.LiveRelationship;
import com.day.cq.wcm.msm.api.LiveStatus;
import com.day.cq.wcm.msm.api.RolloutManager;
import com.day.cq.wcm.msm.commons.BaseActionFactory;
import com.day.cq.wcm.msm.commons.FilteredAction;
import com.day.cq.wcm.msm.commons.ItemFilterImpl;
import com.day.cq.wcm.msm.commons.ItemFilterUtil;
import com.day.cq.wcm.msm.impl.Utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
import javax.jcr.nodetype.PropertyDefinition;
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.felix.scr.annotations.Reference;
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.api.resource.ValueMap;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
@Component(metatype=1, label="%cq.wcm.msm.impl.actions.contentupdate.label", description="%cq.wcm.msm.impl.actions.contentupdate.description")
@Service
public class ContentUpdateActionFactory
extends BaseActionFactory<FilteredAction> {
@Deprecated
@Property(name="cq.wcm.msm.action.rank", propertyPrivate=1)
private static final int RANK = 303;
@Deprecated
@Property(name="cq.wcm.msm.action.title", propertyPrivate=1)
private static final String TITLE = "Update content";
@Deprecated
@Property(name="cq.wcm.msm.action.parameter", propertyPrivate=1)
private static final String PARAMETER = "msm:actionContentUpdate";
@Deprecated
@Property(name="actiontype", propertyPrivate=1)
private static final String ACTION_TYPE = "contentupdate";
@Property(name="cq.wcm.msm.action.excludednodetypes")
private static final String[] DEFAULT_FILTER_NODE_TYPES = ItemFilterUtil.EMPTY_PROPERTIES;
@Property(name="cq.wcm.msm.action.excludedparagraphitems")
private static final String[] DEFAULT_EXCLUDED_PARAGRAPH_ITEMS = ItemFilterUtil.EMPTY_PROPERTIES;
@Property(name="cq.wcm.msm.action.excludedprops")
private static final String[] DEFAULT_EXCLUDED_PROPERTIES = ItemFilterUtil.EMPTY_PROPERTIES;
public static final String IGNORED_MIXINS = "cq.wcm.msm.action.ignoredMixin";
@Property(name="cq.wcm.msm.action.ignoredMixin", unbounded=PropertyUnbounded.ARRAY)
public static final String[] EXCLUDED_MIXINS_DEFAULT = new String[]{".*"};
@Property(name="liveActionName", propertyPrivate=1)
private static final String[] LIVE_ACTION_NAME = new String[]{ContentUpdateAction.class.getSimpleName(), "contentUpdate"};
@Reference
private RolloutManager rolloutManager = null;
private Dictionary properties;
private ItemFilterImpl excludedMixinFilter;
public String createsAction() {
return LIVE_ACTION_NAME[0];
}
@Activate
@Modified
protected void configure(ComponentContext context) {
this.properties = context.getProperties();
this.excludedMixinFilter = ItemFilterUtil.createFilter((String[])PropertiesUtil.toStringArray(context.getProperties().get("cq.wcm.msm.action.ignoredMixin"), (String[])EXCLUDED_MIXINS_DEFAULT), (String[])null, (String[])null, (RolloutManager)this.getRolloutManager());
}
protected Dictionary getFactoryConfig() {
return this.properties;
}
protected ContentUpdateAction newActionInstance(ValueMap config) {
return new ContentUpdateAction(config, this);
}
private RolloutManager getRolloutManager() {
return this.rolloutManager;
}
private ItemFilterImpl getExcludedMixins() {
return this.excludedMixinFilter;
}
protected void bindRolloutManager(RolloutManager rolloutManager) {
this.rolloutManager = rolloutManager;
}
protected void unbindRolloutManager(RolloutManager rolloutManager) {
if (this.rolloutManager == rolloutManager) {
this.rolloutManager = null;
}
}
private static final class ContentUpdateAction
extends FilteredAction {
private final ItemFilterImpl mixinFilter;
public ContentUpdateAction(ValueMap config, ContentUpdateActionFactory factory) {
super(config, ItemFilterUtil.createPageFilter((ValueMap)config, (RolloutManager)factory.rolloutManager), ItemFilterUtil.createComponentFilter((ValueMap)config, (RolloutManager)factory.rolloutManager), (BaseActionFactory)factory);
this.mixinFilter = factory.getExcludedMixins();
}
protected boolean doHandle(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
return relation.getStatus().isSourceExisting() && source != null && target != null && Utils.getWorkingNode((Node)source.adaptTo(Node.class)) != null && Utils.getWorkingNode((Node)target.adaptTo(Node.class)) != null;
}
protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
boolean updated = false;
Node masterNode = Utils.getWorkingNode((Node)source.adaptTo(Node.class));
Node slaveNode = Utils.getWorkingNode((Node)target.adaptTo(Node.class));
NodeType[] masterMixins = masterNode.getMixinNodeTypes();
ArrayList<NodeType> slaveMixins = new ArrayList<NodeType>(Arrays.asList(slaveNode.getMixinNodeTypes()));
for (NodeType masterMixin : masterMixins) {
if (!this.mixinFilter.excludesNodeType(masterMixin.getName()) && !slaveNode.isNodeType(masterMixin.getName())) {
slaveNode.addMixin(masterMixin.getName());
updated = true;
}
slaveMixins.remove((Object)masterMixin);
}
for (NodeType slaveMixin : slaveMixins) {
String name = slaveMixin.getName();
if (this.mixinFilter.excludesNodeType(name)) continue;
slaveNode.removeMixin(name);
updated = true;
}
HashSet<String> inspectedProperties = new HashSet<String>();
Iterator mpi = this.getFilteredProperties(masterNode);
while (mpi.hasNext()) {
javax.jcr.Property property = (javax.jcr.Property)mpi.next();
inspectedProperties.add(property.getName());
if (relation.getStatus().getCanceledProperties().contains(property.getName())) continue;
if (!relation.getStatus().isPage() && property.getName().equals("jcr:lastModified")) {
JcrUtil.setProperty((Node)slaveNode, (String)"jcr:lastModified", (Object)Calendar.getInstance());
} else {
JcrUtil.copy((javax.jcr.Property)property, (Node)slaveNode, (String)null);
}
updated = true;
}
Iterator pItr = this.getFilteredProperties(slaveNode);
while (pItr.hasNext()) {
javax.jcr.Property prop = (javax.jcr.Property)pItr.next();
if (inspectedProperties.remove(prop.getName()) || prop.getDefinition().isAutoCreated() || prop.getDefinition().isProtected() || relation.getStatus().getCanceledProperties().contains(prop.getName())) continue;
prop.remove();
updated = true;
}
if (updated) {
Page page;
PageManager pm = (PageManager)source.getResourceResolver().adaptTo(PageManager.class);
Page page2 = page = pm == null ? null : pm.getContainingPage(slaveNode.getPath());
if (page != null) {
pm.touch((Node)page.adaptTo(Node.class), true, Calendar.getInstance(), false);
}
}
}
}
}