PhoneGapThumbnailProvider.java 2.56 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  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.commons.lang.StringUtils
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ValueMap
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.adobe.cq.mobile.phonegap.impl;

import com.adobe.cq.mobile.platform.MobileResource;
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.commons.lang.StringUtils;
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;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(metatype=0)
@Service
@Property(name="thumbnail.provider.name", value={"mobileapps/phonegap/components/instance"})
public class PhoneGapThumbnailProvider
implements ThumbnailProvider {
    private static final Logger LOGGER = LoggerFactory.getLogger(PhoneGapThumbnailProvider.class);

    public String getThumbnailPath(Resource resource, int width, int height, Map<String, Object> additionalConf) {
        String appIcon;
        String thumbnailPath = null;
        MobileResource app = (MobileResource)resource.adaptTo(MobileResource.class);
        if (app != null && resource.getChild("jcr:content/image") == null && StringUtils.isNotBlank((String)(appIcon = (String)app.getProperties().get("iconPath", String.class)))) {
            Rendition thumbnailRendition;
            Asset thumbnailAsset;
            thumbnailPath = appIcon;
            Resource thumbnailResource = resource.getResourceResolver().getResource(appIcon);
            if (thumbnailResource != null && (thumbnailAsset = (Asset)thumbnailResource.adaptTo(Asset.class)) != null && (thumbnailRendition = UIHelper.getBestfitRendition((Asset)thumbnailAsset, (int)width)) != null && thumbnailRendition.getPath() != null) {
                thumbnailPath = thumbnailRendition.getPath();
            }
        }
        return thumbnailPath;
    }
}