ProjectThumbnailProvider.java 1.92 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.cq.projects.api.Project
 *  com.day.cq.commons.thumbnail.ThumbnailProvider
 *  com.day.cq.dam.api.Asset
 *  com.day.cq.dam.api.Rendition
 *  com.day.cq.dam.commons.util.UIHelper
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.Resource
 */
package com.adobe.cq.projects.impl.servlet.image;

import com.adobe.cq.projects.api.Project;
import com.day.cq.commons.thumbnail.ThumbnailProvider;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.Rendition;
import com.day.cq.dam.commons.util.UIHelper;
import java.util.Map;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;

@Component(metatype=0)
@Service
@Property(name="thumbnail.provider.name", value={"cq/gui/components/projects/admin/card/projectcard"})
public class ProjectThumbnailProvider
implements ThumbnailProvider {
    private static String DEFAULT_PROJECT_ICON = "/libs/cq/ui/widgets/themes/default/icons/240x180/page.png";

    public String getThumbnailPath(Resource resource, int width, int height, Map<String, Object> additionalConf) {
        Asset asset;
        Rendition rendition = null;
        Project project = (Project)resource.adaptTo(Project.class);
        Resource projectCover = project.getProjectCover();
        if (projectCover != null && (asset = (Asset)projectCover.adaptTo(Asset.class)) != null) {
            rendition = UIHelper.getBestfitRendition((Asset)asset, (int)width);
            Rendition rendition2 = rendition = rendition == null ? asset.getOriginal() : rendition;
        }
        if (rendition == null) {
            return DEFAULT_PROJECT_ICON;
        }
        return rendition.getPath();
    }
}