001/* 002 * (C) Copyright 2006-2013 Nuxeo SAS (http://nuxeo.com/) and contributors. 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.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 * Vladimir Pasquier <vpasquier@nuxeo.com> 016 * 017 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.thumbnail.seam; 021 022import java.io.Serializable; 023 024import org.jboss.seam.ScopeType; 025import org.jboss.seam.annotations.In; 026import org.jboss.seam.annotations.Name; 027import org.jboss.seam.annotations.Scope; 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.ecm.core.api.CoreSession; 030import org.nuxeo.ecm.core.api.DocumentLocation; 031import org.nuxeo.ecm.core.api.DocumentModel; 032import org.nuxeo.ecm.core.api.thumbnail.ThumbnailAdapter; 033import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 034import org.nuxeo.ecm.platform.ui.web.util.ComponentUtils; 035import org.nuxeo.ecm.platform.url.api.DocumentView; 036import org.nuxeo.ecm.platform.util.RepositoryLocation; 037 038/** 039 * Thumbnail Manager seam bean 040 * 041 * @since 5.7 042 */ 043@Name("thumbnailManager") 044@Scope(ScopeType.CONVERSATION) 045public class ThumbnailManagerBean implements Serializable { 046 047 private static final long serialVersionUID = 1L; 048 049 @In(create = true, required = false) 050 protected transient CoreSession documentManager; 051 052 @In(required = true, create = true) 053 protected transient NavigationContext navigationContext; 054 055 /** 056 * @since 5.7 057 */ 058 public void downloadThumbnail(DocumentView docView) { 059 if (docView != null) { 060 DocumentLocation docLoc = docView.getDocumentLocation(); 061 if (documentManager == null) { 062 RepositoryLocation loc = new RepositoryLocation(docLoc.getServerName()); 063 navigationContext.setCurrentServerLocation(loc); 064 documentManager = navigationContext.getOrCreateDocumentManager(); 065 } 066 DocumentModel doc = documentManager.getDocument(docLoc.getDocRef()); 067 if (doc != null) { 068 ThumbnailAdapter thumbnailDoc = doc.getAdapter(ThumbnailAdapter.class); 069 Blob thumbnail = thumbnailDoc.getThumbnail(documentManager); 070 if (thumbnail == null) { 071 return; 072 } 073 ComponentUtils.download(doc, null, thumbnail, thumbnail.getFilename(), "thumbnail"); 074 } 075 } 076 } 077}