DPSCollectionAdapterFactory.java
4.6 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
* javax.jcr.Node
* javax.jcr.RepositoryException
* 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.AdapterFactory
* org.apache.sling.api.adapter.AdapterManager
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.resource.ResourceResolverFactory
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.mobile.dps.impl.metadata;
import com.adobe.cq.mobile.dps.DPSCollection;
import com.adobe.cq.mobile.dps.impl.metadata.DPSCollectionImpl;
import com.adobe.cq.mobile.dps.impl.utils.DPSUtil;
import com.day.cq.wcm.api.Page;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
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.AdapterFactory;
import org.apache.sling.api.adapter.AdapterManager;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0, label="%media.publishing.dpsCollection.adapterfactory.service.name", description="%media.publishing.dpsCollection.adapterfactory.service.description")
@Service
public class DPSCollectionAdapterFactory
implements AdapterFactory {
private static Logger log = LoggerFactory.getLogger(DPSCollectionAdapterFactory.class);
@Property(name="adapters", propertyPrivate=1)
private static final String[] ADAPTER_CLASSES = new String[]{DPSCollection.class.getName()};
@Property(name="adaptables", propertyPrivate=1)
private static final String[] ADAPTABLE_CLASSES = new String[]{Page.class.getName(), Node.class.getName(), Resource.class.getName()};
@Reference
private AdapterManager adapterManager;
@Reference
private ResourceResolverFactory resourceResolverFactory;
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
try {
if (adaptable instanceof Node) {
Node node = (Node)adaptable;
ResourceResolver resourceResolver = DPSUtil.getResourceResolver(this.resourceResolverFactory, node.getSession());
Resource adaptableResource = resourceResolver.getResource(node.getPath());
if (adaptableResource != null) {
return this.getAdapter((Object)adaptableResource, type);
}
} else {
if (adaptable instanceof Resource) {
Page page = (Page)((Resource)adaptable).adaptTo(Page.class);
return this.getAdapter(page, type);
}
if (adaptable instanceof Page) {
return this.getAdapter((Page)adaptable, type);
}
}
}
catch (RepositoryException e) {
log.warn("Can't adapt {} to {}", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()), type);
}
log.info("Can't adapt {} to {}", (Object)(adaptable == null ? "null" : adaptable.getClass().getName()), type);
return null;
}
private <AdapterType> AdapterType getAdapter(Page page, Class<AdapterType> type) {
if (DPSUtil.isADPSResource(page) && DPSUtil.getDPSResourceType(page).equals("dps:Collection") && DPSCollection.class == type) {
DPSCollectionImpl implCollection = new DPSCollectionImpl(page);
return (AdapterType)implCollection;
}
return 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;
}
}
}