001/* 002 * Copyright (c) 2006-2011 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 Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Nuxeo 011 */ 012package org.nuxeo.ecm.platform.picture.operation; 013 014import org.nuxeo.ecm.automation.core.Constants; 015import org.nuxeo.ecm.automation.core.annotations.Operation; 016import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 017import org.nuxeo.ecm.automation.core.annotations.Param; 018import org.nuxeo.ecm.core.api.Blob; 019import org.nuxeo.ecm.core.api.DocumentModel; 020import org.nuxeo.ecm.platform.picture.api.PictureView; 021import org.nuxeo.ecm.platform.picture.api.adapters.MultiviewPicture; 022 023/** 024 * Simple Operation to extract an image view from a Picture Document. 025 * <p> 026 * This operation is needed because using the default blob operation is too complicated in the case of the Picture 027 * DocumentType. 028 * 029 * @author Tiry (tdelprat@nuxeo.com) 030 */ 031@Operation(id = GetPictureView.ID, category = Constants.CAT_CONVERSION, label = "Get image view", description = "Get an image from a Picture document.", aliases = { "Picture.getView" }) 032public class GetPictureView { 033 034 public static final String ID = "Picture.GetView"; 035 036 @Param(name = "viewName", required = false) 037 protected String viewName; 038 039 @OperationMethod 040 public Blob run(DocumentModel doc) { 041 042 MultiviewPicture mvp = doc.getAdapter(MultiviewPicture.class); 043 044 if (mvp == null) { 045 return null; 046 } 047 048 if (viewName == null) { 049 viewName = mvp.getOrigin(); 050 } 051 052 PictureView pv = mvp.getView(viewName); 053 054 if (pv == null) { 055 return null; 056 } 057 058 return pv.getBlob(); 059 } 060 061}