001/* 002 * Copyright (c) 2006-2012 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 * <a href=mailto:vpasquier@nuxeo.com>Vladimir Pasquier</a> 011 */ 012package org.nuxeo.ecm.automation.core.operations.blob; 013 014import java.util.List; 015 016import org.nuxeo.ecm.automation.core.Constants; 017import org.nuxeo.ecm.automation.core.annotations.Operation; 018import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 019import org.nuxeo.ecm.automation.core.collectors.BlobListCollector; 020import org.nuxeo.ecm.automation.core.util.BlobList; 021import org.nuxeo.ecm.core.api.Blob; 022import org.nuxeo.ecm.core.api.DocumentModel; 023import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 024 025/** 026 * Get all document blobs 027 */ 028@Operation(id = GetAllDocumentBlobs.ID, category = Constants.CAT_BLOB, label = "Get All Document Files", description = "Gets a list of all blobs that are attached on the input document. Returns a list of files.", aliases = { "Blob.GetAll" }) 029public class GetAllDocumentBlobs { 030 031 public static final String ID = "Document.GetBlobs"; 032 033 @OperationMethod(collector = BlobListCollector.class) 034 public BlobList run(DocumentModel doc) { 035 BlobList blobs = new BlobList(); 036 BlobHolder bh = doc.getAdapter(BlobHolder.class); 037 if (bh != null) { 038 List<Blob> docBlobs = bh.getBlobs(); 039 if (docBlobs != null && !docBlobs.isEmpty()) { 040 for (Blob blob : docBlobs) { 041 blobs.add(blob); 042 } 043 return blobs; 044 } else { 045 return null; 046 } 047 } else { 048 return null; 049 } 050 } 051}