TargetVersionActionFactory.java
2.94 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.Page
* com.day.cq.wcm.api.PageManager
* com.day.cq.wcm.api.Revision
* 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.commons.BaseAction
* com.day.cq.wcm.msm.commons.BaseActionFactory
* javax.jcr.RepositoryException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.wcm.msm.impl.actions;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.api.Revision;
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.commons.BaseAction;
import com.day.cq.wcm.msm.commons.BaseActionFactory;
import javax.jcr.RepositoryException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
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;
@Component(metatype=0)
@Service
public class TargetVersionActionFactory
extends BaseActionFactory<BaseAction> {
@Property(name="liveActionName")
private static final String[] LIVE_ACTION_NAME = new String[]{TargetVersionActionFactory.class.getSimpleName(), "targetVersion"};
public String createsAction() {
return LIVE_ACTION_NAME[0];
}
protected TargetVersionAction newActionInstance(ValueMap config) {
return new TargetVersionAction(config, this);
}
private static final class TargetVersionAction
extends BaseAction {
public TargetVersionAction(ValueMap config, BaseActionFactory<BaseAction> factory) {
super(config, factory);
}
protected boolean handles(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws WCMException, RepositoryException {
return target != null && relation.getStatus().isPage() && target.getResourceResolver().adaptTo(PageManager.class) != null;
}
protected void doExecute(Resource source, Resource target, LiveRelationship relation, boolean resetRollout) throws RepositoryException, WCMException {
Page p;
assert (target != null);
PageManager pm = (PageManager)target.getResourceResolver().adaptTo(PageManager.class);
Page page = p = pm != null ? pm.getContainingPage(target.getPath()) : null;
if (p != null) {
pm.createRevision(p);
}
}
}
}