PageNameResolverImpl.java
4.27 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.webservicesupport.Configuration
* org.apache.commons.lang.StringUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferenceCardinality
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.commons.osgi.ServiceUtil
*/
package com.day.cq.analytics.sitecatalyst.impl;
import com.day.cq.analytics.sitecatalyst.AnalyticsPageNameContext;
import com.day.cq.analytics.sitecatalyst.AnalyticsPageNameProvider;
import com.day.cq.analytics.sitecatalyst.AnalyticsPageNameResolver;
import com.day.cq.analytics.sitecatalyst.Framework;
import com.day.cq.analytics.sitecatalyst.SitecatalystUtil;
import com.day.cq.wcm.webservicesupport.Configuration;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
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.commons.osgi.ServiceUtil;
@Service
@Component(metatype=0, immediate=1)
@Reference(name="pageNameProvider", referenceInterface=AnalyticsPageNameProvider.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
public class PageNameResolverImpl
implements AnalyticsPageNameResolver {
private SortedMap<Comparable<Object>, AnalyticsPageNameProvider> registeredPageNameProvider = new TreeMap(Collections.reverseOrder());
@Override
public String getPageName(AnalyticsPageNameContext context) {
AnalyticsPageNameProvider pnp;
String pageName = null;
Iterator<AnalyticsPageNameProvider> i$ = this.getPageNameProviders().iterator();
while (i$.hasNext() && (pageName = (pnp = i$.next()).getPageName(context)) == null) {
}
if (StringUtils.isEmpty((String)pageName) && !context.getFramework().mapsSCVariable("pageName")) {
Configuration config = context.getConfiguration();
Resource resource = context.getResource();
if (config != null && resource != null) {
pageName = SitecatalystUtil.getFormattedPagePath(resource, config);
}
}
return pageName;
}
@Override
public Resource getResource(AnalyticsPageNameContext context) {
AnalyticsPageNameProvider pnp;
Resource res = null;
Iterator<AnalyticsPageNameProvider> i$ = this.getPageNameProviders().iterator();
while (i$.hasNext() && (res = (pnp = i$.next()).getResource(context)) == null) {
}
if (res == null && !context.getFramework().mapsSCVariable("pageName")) {
String pageName = context.getPageName();
ResourceResolver resolver = context.getResourceResolver();
if (pageName != null && resolver != null) {
String resourcePath = "/" + pageName.replaceAll(":", "/");
if (context.getBasePath() != null && resourcePath.startsWith(context.getBasePath())) {
res = resolver.getResource("/" + pageName.replaceAll(":", "/"));
}
}
}
return res;
}
private synchronized void bindPageNameProvider(AnalyticsPageNameProvider provider, Map<String, Object> config) {
this.registeredPageNameProvider.put(ServiceUtil.getComparableForServiceRanking(config), provider);
}
private synchronized void unbindPageNameProvider(AnalyticsPageNameProvider provider, Map<String, Object> config) {
this.registeredPageNameProvider.remove(ServiceUtil.getComparableForServiceRanking(config));
}
private synchronized Collection<AnalyticsPageNameProvider> getPageNameProviders() {
return this.registeredPageNameProvider.values();
}
}