PGBuildManagerAdapterFactory.java
7.83 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.crypto.CryptoSupport
* com.day.cq.contentsync.ContentSyncManager
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* javax.jcr.Session
* 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.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.http.osgi.services.HttpClientBuilderFactory
* 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.osgi.PropertiesUtil
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.phonegap.impl.build.service;
import com.adobe.cq.mobile.phonegap.impl.build.PGBuildManager;
import com.adobe.cq.mobile.phonegap.impl.build.service.PGBuildManagerImpl;
import com.adobe.granite.crypto.CryptoSupport;
import com.day.cq.contentsync.ContentSyncManager;
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.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.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.http.osgi.services.HttpClientBuilderFactory;
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.osgi.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=1, immediate=1, label="%mobile.phonegap.pgBuildManager.adapterfactory.service.name", description="%mobile.phonegap.pgBuildManager.adapterfactory.service.description")
@Service(value={PGBuildManagerAdapterFactory.class})
public class PGBuildManagerAdapterFactory {
private static Logger log = LoggerFactory.getLogger(PGBuildManagerAdapterFactory.class);
@Property(name="adapters", propertyPrivate=1)
private static final String[] ADAPTER_CLASSES = new String[]{PGBuildManager.class.getName()};
@Property(name="adaptables", propertyPrivate=1)
private static final String[] ADAPTABLE_CLASSES = new String[]{Session.class.getName(), ResourceResolver.class.getName()};
@Property(label="PhoneGap Build Host", description="PhoneGap Build Host", value={"build.phonegap.com"})
private static String PHONEGAP_BUILD_HOST = "phonegap.build.host";
@Property(label="PhoneGap Build Port", description="PhoneGap Build Port", value={"443"})
private static final String PHONEGAP_BUILD_PORT = "phonegap.build.port";
@Property(label="Use SSL", description="Use SSL", value={"true"})
private static final String USE_SSL = "phonegap.build.useSsl";
private static int phonegapBuildPort = 443;
private static String phonegapBuildHost = "build.phonegap.com";
private static boolean useSsl = true;
@Reference
private AdapterManager adapterManagerService;
@Reference
private ContentSyncManager contentSyncManagerService;
@Reference
private CryptoSupport cryptoSupportService;
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Reference
private HttpClientBuilderFactory clientBuilderFactory;
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (PGBuildManager.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.info("Can't adapt {} to PGBuildManager", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()));
}
if (userSession != null) {
return (AdapterType)this.getPGBuildManager(userSession);
}
}
return null;
}
public PGBuildManager getPGBuildManager(Session userSession) {
if (log.isDebugEnabled()) {
log.debug("Creating PGBuildManager for user: " + (userSession == null ? "no user" : userSession.getUserID()));
}
HashMap<String, Session> authInfo = new HashMap<String, Session>();
authInfo.put("user.jcr.session", userSession);
ResourceResolver resolver = null;
try {
resolver = this.resourceResolverFactory.getResourceResolver(authInfo);
}
catch (LoginException e) {
log.error("Unable to obtain the resource resolver", (Object)0);
return null;
}
ConfigurationManager configurationManagerService = (ConfigurationManager)resolver.adaptTo(ConfigurationManager.class);
return new PGBuildManagerImpl(userSession, this.contentSyncManagerService, this.adapterManagerService, configurationManagerService, this.cryptoSupportService, this.clientBuilderFactory, phonegapBuildPort, phonegapBuildHost, useSsl);
}
@Activate
public void activate(Map<String, Object> properties) {
this.modified(properties);
}
@Modified
protected void modified(Map<String, Object> props) {
Object host = props.get(PHONEGAP_BUILD_HOST);
phonegapBuildHost = PropertiesUtil.toString((Object)host, (String)phonegapBuildHost);
Object port = props.get("phonegap.build.port");
phonegapBuildPort = PropertiesUtil.toInteger((Object)port, (int)phonegapBuildPort);
Object propertyUseSsl = props.get("phonegap.build.useSsl");
useSsl = PropertiesUtil.toBoolean((Object)propertyUseSsl, (boolean)useSsl);
}
protected void bindAdapterManagerService(AdapterManager adapterManager) {
this.adapterManagerService = adapterManager;
}
protected void unbindAdapterManagerService(AdapterManager adapterManager) {
if (this.adapterManagerService == adapterManager) {
this.adapterManagerService = null;
}
}
protected void bindContentSyncManagerService(ContentSyncManager contentSyncManager) {
this.contentSyncManagerService = contentSyncManager;
}
protected void unbindContentSyncManagerService(ContentSyncManager contentSyncManager) {
if (this.contentSyncManagerService == contentSyncManager) {
this.contentSyncManagerService = null;
}
}
protected void bindCryptoSupportService(CryptoSupport cryptoSupport) {
this.cryptoSupportService = cryptoSupport;
}
protected void unbindCryptoSupportService(CryptoSupport cryptoSupport) {
if (this.cryptoSupportService == cryptoSupport) {
this.cryptoSupportService = null;
}
}
protected void bindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
this.resourceResolverFactory = resourceResolverFactory;
}
protected void unbindResourceResolverFactory(ResourceResolverFactory resourceResolverFactory) {
if (this.resourceResolverFactory == resourceResolverFactory) {
this.resourceResolverFactory = null;
}
}
protected void bindClientBuilderFactory(HttpClientBuilderFactory httpClientBuilderFactory) {
this.clientBuilderFactory = httpClientBuilderFactory;
}
protected void unbindClientBuilderFactory(HttpClientBuilderFactory httpClientBuilderFactory) {
if (this.clientBuilderFactory == httpClientBuilderFactory) {
this.clientBuilderFactory = null;
}
}
}