RenditionUtils.java 2.35 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.granite.asset.api.AssetException
 *  com.adobe.granite.asset.api.RenditionHandler
 *  javax.jcr.RepositoryException
 *  org.apache.commons.lang.StringUtils
 *  org.apache.sling.api.resource.Resource
 *  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.AssetException;
import com.adobe.granite.asset.api.RenditionHandler;
import com.adobe.granite.asset.core.impl.RHWhiteBoard;
import java.util.Map;
import javax.jcr.RepositoryException;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public final class RenditionUtils {
    private static final Logger log = LoggerFactory.getLogger(RenditionUtils.class);

    public static String getRenditionHandlerId(Map<String, Object> map, String defaultId) {
        String handlerId = (String)map.get("rendition.handler.id");
        return StringUtils.isNotEmpty((String)handlerId) ? handlerId : defaultId;
    }

    public static String getRenditionHandlerId(Resource rendition, String defaultId) {
        Resource contentResource = rendition.getChild("jcr:content");
        String handlerId = null;
        if (contentResource != null && (handlerId = (String)((ValueMap)contentResource.adaptTo(ValueMap.class)).get("rendition.handler.id", String.class)) == null) {
            log.debug("Rendition Handler property does not exist: {}", (Object)rendition.getPath());
        }
        return StringUtils.isNotEmpty((String)handlerId) ? handlerId : defaultId;
    }

    public static RenditionHandler getRenditionHandler(String handlerId) {
        RenditionHandler rh = RHWhiteBoard.getRenditionHandler(handlerId);
        if (rh == null) {
            throw new AssetException("No Rendition Handler is registered with id [" + handlerId + "]");
        }
        return rh;
    }

    public static boolean isRendition(Resource resource) throws RepositoryException {
        Resource parent = resource.getParent();
        return parent != null && parent.getName().equals("renditions");
    }
}