001/* 002 * (C) Copyright 2006-2016 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 * Tiago Cardoso <[email protected]> 018 */ 019package org.nuxeo.ecm.platform.threed.adapter; 020 021import org.nuxeo.common.utils.FileUtils; 022import org.nuxeo.ecm.core.api.Blob; 023import org.nuxeo.ecm.core.api.Blobs; 024import org.nuxeo.ecm.core.api.CoreSession; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.api.NuxeoException; 027import org.nuxeo.ecm.core.api.thumbnail.ThumbnailFactory; 028import org.nuxeo.ecm.platform.threed.ThreeDDocument; 029import org.nuxeo.ecm.platform.types.adapter.TypeInfo; 030 031import java.io.File; 032import java.io.IOException; 033 034import static org.nuxeo.ecm.platform.threed.ThreeDConstants.THREED_FACET; 035 036/** 037 * 3D content thumbnail factory 038 * 039 * @since 8.4 040 */ 041public class ThumbnailThreeDFactory implements ThumbnailFactory { 042 043 @Override 044 public Blob getThumbnail(DocumentModel documentModel, CoreSession coreSession) { 045 if (!documentModel.hasFacet(THREED_FACET)) { 046 throw new NuxeoException("Document is not 3D"); 047 } 048 ThreeDDocument threeDDoc = documentModel.getAdapter(ThreeDDocument.class); 049 Blob thumbnailBlob = null; 050 if (!threeDDoc.getRenderViews().isEmpty()) { 051 thumbnailBlob = threeDDoc.getRenderViews().iterator().next().getContent(); 052 } 053 if (thumbnailBlob == null) { 054 // do default 055 TypeInfo docType = documentModel.getAdapter(TypeInfo.class); 056 try { 057 return Blobs.createBlob( 058 FileUtils.getResourceFileFromContext("nuxeo.war" + File.separator + docType.getBigIcon())); 059 } catch (IOException e) { 060 throw new NuxeoException(e); 061 } 062 } 063 return thumbnailBlob; 064 } 065 066 @Override 067 public Blob computeThumbnail(DocumentModel documentModel, CoreSession coreSession) { 068 return null; 069 } 070 071}