ResourceConverterAdapterFactory.java
3.97 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.rest.converter.ResourceConverter
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.adapter.AdapterFactory
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceWrapper
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.rest.assets.impl;
import com.adobe.granite.rest.assets.impl.AssetResource;
import com.adobe.granite.rest.assets.impl.AssetResourceConverter;
import com.adobe.granite.rest.assets.impl.CommentResource;
import com.adobe.granite.rest.assets.impl.CommentResourceConverter;
import com.adobe.granite.rest.assets.impl.CommentsResource;
import com.adobe.granite.rest.assets.impl.CommentsResourceConverter;
import com.adobe.granite.rest.assets.impl.FolderResource;
import com.adobe.granite.rest.assets.impl.FolderResourceConverter;
import com.adobe.granite.rest.assets.impl.RenditionResource;
import com.adobe.granite.rest.assets.impl.RenditionResourceConverter;
import com.adobe.granite.rest.assets.impl.RenditionsResource;
import com.adobe.granite.rest.assets.impl.RenditionsResourceConverter;
import com.adobe.granite.rest.converter.ResourceConverter;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.adapter.AdapterFactory;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
public class ResourceConverterAdapterFactory
implements AdapterFactory {
private Logger log;
@Property(name="adapters")
public static final String[] ADAPTER_CLASSES = new String[]{ResourceConverter.class.getName()};
@Property(name="adaptables")
public static final String[] ADAPTABLE_CLASSES = new String[]{Resource.class.getName()};
public ResourceConverterAdapterFactory() {
this.log = LoggerFactory.getLogger(this.getClass());
}
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
if (type == ResourceConverter.class) {
return this.getResourceConverterAdapter(adaptable, type);
}
this.log.warn("Unable to handle adaptable {}", (Object)adaptable.getClass().getName());
return null;
}
private <AdapterType> AdapterType getResourceConverterAdapter(Object adaptable, Class<AdapterType> type) {
Resource resource = null;
if (adaptable instanceof Resource) {
resource = (Resource)adaptable;
resource = this.unwrap(resource);
}
if (resource != null) {
if (resource instanceof AssetResource) {
return (AdapterType)((Object)new AssetResourceConverter(resource));
}
if (resource instanceof FolderResource) {
return (AdapterType)((Object)new FolderResourceConverter(resource));
}
if (resource instanceof RenditionsResource) {
return (AdapterType)((Object)new RenditionsResourceConverter(resource));
}
if (resource instanceof RenditionResource) {
return (AdapterType)((Object)new RenditionResourceConverter(resource));
}
if (resource instanceof CommentsResource) {
return (AdapterType)((Object)new CommentsResourceConverter(resource));
}
if (resource instanceof CommentResource) {
return (AdapterType)((Object)new CommentResourceConverter(resource));
}
}
return null;
}
private Resource unwrap(Resource resource) {
Resource result = resource;
while (result instanceof ResourceWrapper) {
result = ((ResourceWrapper)result).getResource();
}
return result;
}
}