All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.cq.dam.processor.nui.util.DirectBinaryUtil Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2018 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/
package com.adobe.cq.dam.processor.nui.util;

import java.net.URI;

import javax.jcr.Binary;
import javax.jcr.RepositoryException;

import org.apache.jackrabbit.api.binary.BinaryDownload;
import org.apache.jackrabbit.api.binary.BinaryDownloadOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.dam.api.Rendition;

/**
 * Utils shared between UI and bundles
 */
public class DirectBinaryUtil {
    private static final Logger LOG = LoggerFactory.getLogger(DirectBinaryUtil.class);

    /**
     * Get the cloud image URI for rendition, return null if failed to get it
     *
     * @param rendition The rendition
     *
     * @return get the cloud image URI for rendition, return null if failed to get it
     */
    public static URI getRenditionCloudURI(Rendition rendition) {
        try {
            if (rendition != null) {
                Binary binary = rendition.getBinary();

                if (binary instanceof BinaryDownload) {
                    BinaryDownload binaryDownload = (BinaryDownload) binary;

                    String mimeType = rendition.getMimeType();
                    String fileName = rendition.getAsset().getName();
                    BinaryDownloadOptions downloadOptions = BinaryDownloadOptions.builder()
                            .withMediaType(mimeType)
                            .withFileName(fileName)
                            .withDispositionTypeInline().build();

                    URI uri = binaryDownload.getURI(downloadOptions);
                    if (uri != null) {
                        LOG.debug("Get cloud uri: {} for {}: ", uri, rendition.getPath());
                        return uri;
                    } else {
                        LOG.debug("Failed to get cloud uri for {} due to failed to get URI from Binary", rendition.getPath());
                    }
                } else {
                    LOG.debug("Failed to get cloud uri for {} due to binary isnot BinaryDownload", rendition.getPath());
                }
            } else {
                LOG.debug("Failed to get cloud uri for null rendition");
            }
        } catch (RepositoryException e) {
            LOG.debug("Failed to get cloud uri due to RepositoryException", e);
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy