ComponentServiceImpl.java
3.4 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.api.components.Component
* com.day.cq.wcm.api.components.ComponentManager
* com.day.cq.wcm.api.components.VirtualComponent
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.apache.sling.api.resource.ValueMap
*/
package com.day.cq.analytics.impl;
import com.day.cq.analytics.impl.ComponentFilter;
import com.day.cq.analytics.impl.ComponentService;
import com.day.cq.wcm.api.components.ComponentManager;
import com.day.cq.wcm.api.components.VirtualComponent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.TreeMap;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.ValueMap;
@Component
@Service
public class ComponentServiceImpl
implements ComponentService {
@Reference
private ResourceResolverFactory rrf;
@Override
public Collection<com.day.cq.wcm.api.components.Component> getComponents(ResourceResolver resolver, ComponentFilter filter) {
ArrayList<com.day.cq.wcm.api.components.Component> components = new ArrayList<com.day.cq.wcm.api.components.Component>();
HashSet<String> resourceTypes = new HashSet<String>();
for (com.day.cq.wcm.api.components.Component c : this.getComponentTree(resolver, filter).values()) {
String key = c.getResourceType();
if (c instanceof VirtualComponent) {
String p = c.getPath();
key = p.substring(p.indexOf("/", 1) + 1);
}
if (resourceTypes.contains(key)) continue;
resourceTypes.add(key);
components.add(c);
}
return components;
}
private Map<String, com.day.cq.wcm.api.components.Component> getComponentTree(ResourceResolver resolver, ComponentFilter filter) {
TreeMap<String, com.day.cq.wcm.api.components.Component> componentTree = new TreeMap<String, com.day.cq.wcm.api.components.Component>();
ComponentManager componentMgr = (ComponentManager)resolver.adaptTo(ComponentManager.class);
for (com.day.cq.wcm.api.components.Component c : componentMgr.getComponents()) {
if (c == null || !c.isAccessible() || !filter.include(resolver, c)) continue;
boolean displayVirtualsOnly = (Boolean)c.getProperties().get("displayVirtualsOnly", (Object)Boolean.FALSE);
if (!displayVirtualsOnly) {
componentTree.put(c.getPath(), c);
}
for (VirtualComponent v : c.getVirtualComponents()) {
componentTree.put(v.getPath(), (com.day.cq.wcm.api.components.Component)v);
}
}
return componentTree;
}
protected void bindRrf(ResourceResolverFactory resourceResolverFactory) {
this.rrf = resourceResolverFactory;
}
protected void unbindRrf(ResourceResolverFactory resourceResolverFactory) {
if (this.rrf == resourceResolverFactory) {
this.rrf = null;
}
}
}