001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Thomas Roger
016 */
017
018package org.nuxeo.ecm.platform.thumbnail.rendition;
019
020import java.util.Collections;
021import java.util.List;
022
023import org.nuxeo.ecm.core.api.Blob;
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.core.api.thumbnail.ThumbnailService;
026import org.nuxeo.ecm.platform.rendition.extension.RenditionProvider;
027import org.nuxeo.ecm.platform.rendition.service.RenditionDefinition;
028import org.nuxeo.runtime.api.Framework;
029
030/**
031 * @since 7.2
032 */
033public class ThumbnailRenditionProvider implements RenditionProvider {
034
035    @Override
036    public boolean isAvailable(DocumentModel doc, RenditionDefinition definition) {
037        return true;
038    }
039
040    @Override
041    public List<Blob> render(DocumentModel doc, RenditionDefinition definition) {
042        ThumbnailService thumbnailService = Framework.getService(ThumbnailService.class);
043        Blob blob = thumbnailService.getThumbnail(doc, doc.getCoreSession());
044        if (blob != null) {
045            return Collections.singletonList(blob);
046        }
047
048        return Collections.emptyList();
049    }
050}