AssetResourceFactory.java
2.69 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.api.resource.Resource
* 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.CommentResource;
import com.adobe.granite.rest.assets.impl.CommentsResource;
import com.adobe.granite.rest.assets.impl.FolderResource;
import com.adobe.granite.rest.assets.impl.RenditionResource;
import com.adobe.granite.rest.assets.impl.RenditionsResource;
import org.apache.sling.api.resource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AssetResourceFactory {
private static final Logger log = LoggerFactory.getLogger(AssetResourceFactory.class);
private static final String RT_DAM_ASSET = "dam:Asset";
private static final String RT_DAM_COMMENTCOLLECTION = "granite/comments/components/collection";
private static final String RT_DAM_COMMENT = "granite/comments/components/comment";
private static final String RT_NT_FOLDER = "nt:folder";
private static final String RT_NT_FILE = "nt:file";
private static final String RT_SLING_FOLDER = "sling:Folder";
private static final String RT_SLING_ORDERED_FOLDER = "sling:OrderedFolder";
private static final String NN_RENDITIONS = "renditions";
public Resource createResource(Resource resource, String apiPath) {
if ("dam:Asset".equals(resource.getResourceType())) {
return new AssetResource(resource, apiPath);
}
if (this.isRenditionCollection(resource)) {
return new RenditionsResource(resource, apiPath);
}
if ("nt:file".equals(resource.getResourceType())) {
return new RenditionResource(resource, apiPath);
}
if ("granite/comments/components/collection".equals(resource.getResourceType())) {
return new CommentsResource(resource, apiPath);
}
if ("granite/comments/components/comment".equals(resource.getResourceType())) {
return new CommentResource(resource, apiPath);
}
if (this.isFolder(resource)) {
return new FolderResource(resource, apiPath);
}
log.debug("Unknown resource type: " + resource.getResourceType());
return null;
}
private boolean isRenditionCollection(Resource resource) {
return "renditions".equals(resource.getName()) && this.isFolder(resource);
}
private boolean isFolder(Resource resource) {
return "nt:folder".equals(resource.getResourceType()) || "sling:Folder".equals(resource.getResourceType()) || "sling:OrderedFolder".equals(resource.getResourceType());
}
}