AssetResourceFactory.java 2.69 KB
/*
 * 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());
    }
}