DPSClientAdapterFactory.java
7.58 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.contentsync.handler.util.RequestResponseFactory
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* javax.jcr.Session
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.adapter.AdapterManager
* org.apache.sling.api.resource.LoginException
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.commons.threads.ThreadPool
* org.apache.sling.engine.SlingRequestProcessor
* org.osgi.service.event.EventAdmin
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.dps.impl.service;
import com.adobe.cq.mobile.dps.impl.DPSClient;
import com.adobe.cq.mobile.dps.impl.DPSPageExporter;
import com.adobe.cq.mobile.dps.impl.service.AdobeDPSClient;
import com.adobe.cq.mobile.dps.impl.service.DPSClientImpl;
import com.adobe.cq.mobile.dps.impl.service.DPSConnectionAdapterFactory;
import com.day.cq.contentsync.handler.util.RequestResponseFactory;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import java.util.HashMap;
import java.util.Map;
import javax.jcr.Session;
import org.apache.felix.scr.annotations.Component;
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.adapter.AdapterManager;
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.threads.ThreadPool;
import org.apache.sling.engine.SlingRequestProcessor;
import org.osgi.service.event.EventAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service(value={DPSClientAdapterFactory.class})
public class DPSClientAdapterFactory {
private static Logger log = LoggerFactory.getLogger(DPSClientAdapterFactory.class);
@Property(name="adapters", propertyPrivate=1)
private static final String[] ADAPTER_CLASSES = new String[]{DPSClient.class.getName()};
@Property(name="adaptables", propertyPrivate=1)
private static final String[] ADAPTABLE_CLASSES = new String[]{Session.class.getName(), ResourceResolver.class.getName()};
@Reference
private DPSPageExporter dpsPageExporterService;
@Reference
private EventAdmin eventAdminService;
@Reference
AdapterManager adapterManager;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference
private DPSConnectionAdapterFactory dpsConnectionAdapterFactory;
@Reference
private AdobeDPSClient adobeDPSClient;
@Reference
private SlingRequestProcessor slingRequestProcessor;
@Reference
private RequestResponseFactory requestResponseFactory;
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (DPSClient.class == type) {
Session userSession = null;
if (adaptable instanceof Session) {
userSession = (Session)adaptable;
} else if (adaptable instanceof ResourceResolver) {
userSession = (Session)((ResourceResolver)adaptable).adaptTo(Session.class);
} else {
log.error("Can't adapt {} to DPSClient", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()));
}
if (userSession != null) {
try {
return (AdapterType)this.getDPSClient(userSession);
}
catch (LoginException e) {
log.error("Unable to obtain the DPSClient", (Throwable)e);
}
}
}
return null;
}
private DPSClient getDPSClient(Session userSession) throws LoginException {
if (log.isDebugEnabled()) {
log.debug("Creating DPSClient for user: " + (userSession == null ? "no user" : userSession.getUserID()));
}
HashMap<String, Session> authInfo = new HashMap<String, Session>();
authInfo.put("user.jcr.session", userSession);
ResourceResolver resolver = this.resourceResolverFactory.getResourceResolver(authInfo);
ConfigurationManager configurationManagerService = (ConfigurationManager)resolver.adaptTo(ConfigurationManager.class);
return new DPSClientImpl(resolver, userSession, this.dpsPageExporterService, this.dpsConnectionAdapterFactory, configurationManagerService, this.eventAdminService, this.adapterManager, this.slingRequestProcessor, this.requestResponseFactory, this.adobeDPSClient.getThreadPool());
}
protected void bindDpsPageExporterService(DPSPageExporter dPSPageExporter) {
this.dpsPageExporterService = dPSPageExporter;
}
protected void unbindDpsPageExporterService(DPSPageExporter dPSPageExporter) {
if (this.dpsPageExporterService == dPSPageExporter) {
this.dpsPageExporterService = null;
}
}
protected void bindEventAdminService(EventAdmin eventAdmin) {
this.eventAdminService = eventAdmin;
}
protected void unbindEventAdminService(EventAdmin eventAdmin) {
if (this.eventAdminService == eventAdmin) {
this.eventAdminService = null;
}
}
protected void bindAdapterManager(AdapterManager adapterManager) {
this.adapterManager = adapterManager;
}
protected void unbindAdapterManager(AdapterManager adapterManager) {
if (this.adapterManager == adapterManager) {
this.adapterManager = null;
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
protected void bindDpsConnectionAdapterFactory(DPSConnectionAdapterFactory dPSConnectionAdapterFactory) {
this.dpsConnectionAdapterFactory = dPSConnectionAdapterFactory;
}
protected void unbindDpsConnectionAdapterFactory(DPSConnectionAdapterFactory dPSConnectionAdapterFactory) {
if (this.dpsConnectionAdapterFactory == dPSConnectionAdapterFactory) {
this.dpsConnectionAdapterFactory = null;
}
}
protected void bindAdobeDPSClient(AdobeDPSClient adobeDPSClient) {
this.adobeDPSClient = adobeDPSClient;
}
protected void unbindAdobeDPSClient(AdobeDPSClient adobeDPSClient) {
if (this.adobeDPSClient == adobeDPSClient) {
this.adobeDPSClient = null;
}
}
protected void bindSlingRequestProcessor(SlingRequestProcessor slingRequestProcessor) {
this.slingRequestProcessor = slingRequestProcessor;
}
protected void unbindSlingRequestProcessor(SlingRequestProcessor slingRequestProcessor) {
if (this.slingRequestProcessor == slingRequestProcessor) {
this.slingRequestProcessor = null;
}
}
protected void bindRequestResponseFactory(RequestResponseFactory requestResponseFactory) {
this.requestResponseFactory = requestResponseFactory;
}
protected void unbindRequestResponseFactory(RequestResponseFactory requestResponseFactory) {
if (this.requestResponseFactory == requestResponseFactory) {
this.requestResponseFactory = null;
}
}
}