001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thomas Roger 018 */ 019 020package org.nuxeo.ecm.platform.thumbnail.rendition; 021 022import java.util.Collections; 023import java.util.List; 024 025import org.nuxeo.ecm.core.api.Blob; 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.thumbnail.ThumbnailService; 028import org.nuxeo.ecm.platform.rendition.extension.RenditionProvider; 029import org.nuxeo.ecm.platform.rendition.service.RenditionDefinition; 030import org.nuxeo.runtime.api.Framework; 031 032/** 033 * @since 7.2 034 */ 035public class ThumbnailRenditionProvider implements RenditionProvider { 036 037 @Override 038 public boolean isAvailable(DocumentModel doc, RenditionDefinition definition) { 039 return true; 040 } 041 042 @Override 043 public List<Blob> render(DocumentModel doc, RenditionDefinition definition) { 044 ThumbnailService thumbnailService = Framework.getService(ThumbnailService.class); 045 Blob blob = thumbnailService.getThumbnail(doc, doc.getCoreSession()); 046 if (blob != null) { 047 return Collections.singletonList(blob); 048 } 049 050 return Collections.emptyList(); 051 } 052}