LiveCopyServiceImpl.java
5.21 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.WCMException
* com.day.cq.wcm.msm.api.RolloutConfig
* com.day.cq.wcm.msm.api.RolloutConfigManager
* javax.jcr.RepositoryException
* javax.jcr.Session
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.commons.osgi.PropertiesUtil
* org.osgi.service.component.ComponentContext
*/
package com.day.cq.wcm.msm.impl;
import com.day.cq.wcm.api.WCMException;
import com.day.cq.wcm.msm.api.RolloutConfig;
import com.day.cq.wcm.msm.api.RolloutConfigManager;
import com.day.cq.wcm.msm.impl.LiveCopyIndexImpl;
import com.day.cq.wcm.msm.impl.LiveCopyManagerImpl;
import com.day.cq.wcm.msm.impl.RolloutConfigManagerFactory;
import java.util.Dictionary;
import java.util.Map;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;
@Component
@Service(value={LiveCopyServiceImpl.class})
public class LiveCopyServiceImpl {
static final String DEFAULT_PATH = "/content";
static final String[] DEFAULT_EXCLUDED_PATHS = new String[]{"/content/dam"};
@Property(value={"/content"}, propertyPrivate=1)
static final String PATH = "cq.wcm.msm.liveCopyIndex.path";
@Property(value={"/content/dam"}, propertyPrivate=1)
static final String EXCLUDED_PATHS = "cq.wcm.msm.liveCopyIndex.excludedPaths";
@Reference
private ResourceResolverFactory resolverFactory = null;
@Reference
private RolloutConfigManagerFactory rolloutConfigManagerFactory = null;
private ResourceResolver serviceUser;
private LiveCopyIndexImpl index;
@Activate
protected void activate(ComponentContext context) throws LoginException, RepositoryException {
String path = PropertiesUtil.toString(context.getProperties().get("cq.wcm.msm.liveCopyIndex.path"), (String)"/content");
String[] excludedPaths = PropertiesUtil.toStringArray(context.getProperties().get("cq.wcm.msm.liveCopyIndex.excludedPaths"), (String[])DEFAULT_EXCLUDED_PATHS);
this.serviceUser = this.resolverFactory.getServiceResourceResolver(null);
Session adminSession = (Session)this.serviceUser.adaptTo(Session.class);
if (adminSession == null) {
throw new IllegalArgumentException("Need a JCR ResourceResolver to run");
}
this.index = new LiveCopyIndexImpl(adminSession, path, excludedPaths);
this.index.startListening();
}
@Deactivate
protected void deactivate(ComponentContext context) throws RepositoryException {
if (this.serviceUser != null && this.serviceUser.isLive()) {
this.index.endListening();
this.serviceUser.close();
}
}
public LiveCopyManagerImpl createLiveCopyManager(ResourceResolver resolver) {
Session adminSession = (Session)resolver.adaptTo(Session.class);
if (adminSession == null) {
throw new IllegalArgumentException("Need a ResourceResolver that adapts to Session");
}
return new LiveCopyManagerImpl(adminSession, this.index, this.rolloutConfigManagerFactory.create(resolver));
}
public int getIndexSize() throws RepositoryException, WCMException {
return -1;
}
public void setIndexDirty() {
this.getLiveCopyIndex().setDirty();
}
LiveCopyIndexImpl getLiveCopyIndex() {
return this.index;
}
RolloutConfig getRolloutConfig(String path, ResourceResolver resolver) throws WCMException {
return this.rolloutConfigManagerFactory.create(resolver).getRolloutConfig(path);
}
protected void bindResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resolverFactory = resourceResolverFactory;
}
protected void unbindResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resolverFactory == resourceResolverFactory) {
this.resolverFactory = null;
}
}
protected void bindRolloutConfigManagerFactory(RolloutConfigManagerFactory rolloutConfigManagerFactory) {
this.rolloutConfigManagerFactory = rolloutConfigManagerFactory;
}
protected void unbindRolloutConfigManagerFactory(RolloutConfigManagerFactory rolloutConfigManagerFactory) {
if (this.rolloutConfigManagerFactory == rolloutConfigManagerFactory) {
this.rolloutConfigManagerFactory = null;
}
}
}