001/* 002 * (C) Copyright 2006-2013 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 * Vladimir Pasquier <vpasquier@nuxeo.com> 018 * 019 */ 020package org.nuxeo.ecm.platform.picture.thumbnail; 021 022import java.io.File; 023import java.io.IOException; 024 025import org.nuxeo.common.utils.FileUtils; 026import org.nuxeo.ecm.core.api.Blob; 027import org.nuxeo.ecm.core.api.Blobs; 028import org.nuxeo.ecm.core.api.CoreSession; 029import org.nuxeo.ecm.core.api.DocumentModel; 030import org.nuxeo.ecm.core.api.NuxeoException; 031import org.nuxeo.ecm.core.api.thumbnail.ThumbnailFactory; 032import org.nuxeo.ecm.platform.picture.api.PictureView; 033import org.nuxeo.ecm.platform.picture.api.adapters.MultiviewPicture; 034import org.nuxeo.ecm.platform.types.adapter.TypeInfo; 035 036/** 037 * Picture thumbnail factory 038 * 039 * @since 5.7 040 */ 041public class ThumbnailPictureFactory implements ThumbnailFactory { 042 043 @Override 044 public Blob getThumbnail(DocumentModel doc, CoreSession session) { 045 if (!doc.hasFacet("Picture")) { 046 throw new NuxeoException("Document is not a picture"); 047 } 048 // Choose the nuxeo default thumbnail of the picture views if exists 049 MultiviewPicture mViewPicture = doc.getAdapter(MultiviewPicture.class); 050 PictureView thumbnailView = mViewPicture.getView("Small"); 051 if (thumbnailView == null || thumbnailView.getBlob() == null) { 052 // try thumbnail view 053 thumbnailView = mViewPicture.getView("Thumbnail"); 054 if (thumbnailView == null || thumbnailView.getBlob() == null) { 055 TypeInfo docType = doc.getAdapter(TypeInfo.class); 056 try { 057 return Blobs.createBlob(FileUtils.getResourceFileFromContext("nuxeo.war" + File.separator 058 + docType.getBigIcon())); 059 } catch (IOException e) { 060 throw new NuxeoException(e); 061 } 062 } 063 } 064 return thumbnailView.getBlob(); 065 } 066 067 @Override 068 public Blob computeThumbnail(DocumentModel doc, CoreSession session) { 069 return null; 070 } 071}