RenditionImpl.java 2.42 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.asset.api.AssetIOException
 *  com.adobe.granite.asset.api.Rendition
 *  javax.jcr.Binary
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ResourceUtil
 *  org.apache.sling.api.resource.ResourceWrapper
 *  org.apache.sling.api.resource.ValueMap
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.granite.asset.core.impl;

import com.adobe.granite.asset.api.AssetIOException;
import com.adobe.granite.asset.api.Rendition;
import java.io.InputStream;
import javax.jcr.Binary;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ResourceWrapper;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RenditionImpl
extends ResourceWrapper
implements Rendition {
    private static final Logger log = LoggerFactory.getLogger(Rendition.class);
    private final ValueMap contentProperties;

    public RenditionImpl(Resource resource) {
        super(resource);
        Resource contentResource = resource.getResourceResolver().getResource(resource, "jcr:content");
        this.contentProperties = ResourceUtil.getValueMap((Resource)contentResource);
    }

    public String getName() {
        return ResourceUtil.getName((String)this.getPath());
    }

    public String getMimeType() {
        return (String)this.contentProperties.get("jcr:mimeType", String.class);
    }

    public long getSize() {
        boolean size = false;
        Property p = (Property)this.contentProperties.get("jcr:data", Property.class);
        try {
            return null != p ? p.getBinary().getSize() : 0;
        }
        catch (RepositoryException e) {
            log.error("Failed to get the Rendition binary size in bytes [{}]: ", (Object)this.getPath(), (Object)e);
            return (long)size ? 1 : 0;
        }
    }

    public InputStream getStream() {
        try {
            return (InputStream)this.contentProperties.get("jcr:data", InputStream.class);
        }
        catch (Throwable t) {
            throw new AssetIOException(t);
        }
    }
}