FolderResource.java 2.45 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.rest.utils.DeepModifiableValueMapDecorator
 *  org.apache.sling.api.resource.ModifiableValueMap
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ValueMap
 */
package com.adobe.granite.rest.assets.impl;

import com.adobe.granite.rest.assets.impl.AbstractAssetResource;
import com.adobe.granite.rest.assets.impl.RenditionResource;
import com.adobe.granite.rest.utils.DeepModifiableValueMapDecorator;
import java.io.InputStream;
import java.util.Map;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

public class FolderResource
extends AbstractAssetResource {
    public static final String RESOURCE_TYPE = "granite/rest/assets/folder";
    private ValueMap valueMap;

    public FolderResource(Resource resource, String path) {
        ValueMap base;
        super(resource, path);
        Resource content = resource;
        if (resource.getChild("jcr:content") != null) {
            content = resource.getChild("jcr:content");
        }
        if ((base = (ValueMap)content.adaptTo(ModifiableValueMap.class)) == null) {
            base = (ValueMap)content.adaptTo(ValueMap.class);
        }
        this.valueMap = new DeepModifiableValueMapDecorator(resource, (Map)base);
    }

    public String getResourceType() {
        return "granite/rest/assets/folder";
    }

    public RenditionResource getThumbnail() {
        ResourceResolver resolver = this.resource.getResourceResolver();
        Resource thumbnail = resolver.getResource(this.resource, "jcr:content/folderThumbnail");
        if (thumbnail != null) {
            RenditionResource rendition = new RenditionResource(thumbnail, this.getPath() + "/folderThumbnail");
            return rendition;
        }
        return null;
    }

    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
        RenditionResource thumbnail;
        if (type == ValueMap.class || type == ModifiableValueMap.class) {
            return (AdapterType)this.valueMap;
        }
        if (type == InputStream.class && (thumbnail = this.getThumbnail()) != null) {
            return (AdapterType)thumbnail.adaptTo(InputStream.class);
        }
        return (AdapterType)super.adaptTo(type);
    }
}