AbstractOptionsServlet.java
4.5 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
/*
* 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.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Value
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.servlets.SlingAllMethodsServlet
*/
package com.day.cq.analytics.sitecatalyst.impl.servlets;
import com.day.cq.analytics.sitecatalyst.SitecatalystWebservice;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManager;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
@Component
public class AbstractOptionsServlet
extends SlingAllMethodsServlet {
protected static final String PARAM_CONFIG_PATH = "configPath";
@Reference
protected ConfigurationManagerFactory configManagerFactory;
@Reference
protected SitecatalystWebservice catalystService;
protected Configuration getConfiguration(SlingHttpServletRequest request, String servicename) throws RepositoryException {
String configPath = request.getParameter("configPath");
ConfigurationManager configManager = this.configManagerFactory.getConfigurationManager(request.getResourceResolver());
if (configPath != null) {
return configManager.getConfiguration(configPath);
}
Resource resource = request.getResource();
ResourceResolver resolver = resource.getResourceResolver();
PageManager pageManager = (PageManager)resolver.adaptTo(PageManager.class);
Page currentPage = pageManager.getContainingPage(resource);
Configuration configuration = (Configuration)currentPage.adaptTo(Configuration.class);
if (configuration != null) {
return configuration;
}
Resource configRes = configManager.getConfigurationResource(currentPage.getContentResource());
if (configRes != null) {
return configManager.getConfiguration(this.getConfigurationPath(configRes, servicename));
}
return null;
}
protected String getConfigurationPath(Resource resource, String servicename) throws RepositoryException {
Resource cloudconfigsContent = resource.getChild("jcr:content");
Node cloudconfigsNode = (Node)cloudconfigsContent.adaptTo(Node.class);
Property prop = cloudconfigsNode.getProperty("cq:cloudserviceconfigs");
String configPath = null;
if (prop.isMultiple()) {
for (Value val : prop.getValues()) {
String path = val.getString();
if (path == null || path.indexOf(servicename) <= -1) continue;
configPath = path;
}
} else {
String path = prop.getValue().getString();
if (path != null && path.indexOf(servicename) > -1) {
configPath = path;
}
}
return configPath;
}
protected void bindConfigManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.configManagerFactory = configurationManagerFactory;
}
protected void unbindConfigManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.configManagerFactory == configurationManagerFactory) {
this.configManagerFactory = null;
}
}
protected void bindCatalystService(SitecatalystWebservice sitecatalystWebservice) {
this.catalystService = sitecatalystWebservice;
}
protected void unbindCatalystService(SitecatalystWebservice sitecatalystWebservice) {
if (this.catalystService == sitecatalystWebservice) {
this.catalystService = null;
}
}
}