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 - initial API and implementation 011 * 012 * $Id: DocumentsListReader.java 29029 2008-01-14 18:38:14Z ldoguin $ 013 */ 014 015package org.nuxeo.ecm.core.io.impl.plugins; 016 017import java.io.IOException; 018import java.util.ArrayList; 019import java.util.Collection; 020import java.util.Iterator; 021import java.util.List; 022 023import org.nuxeo.ecm.core.api.CoreSession; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.DocumentRef; 026import org.nuxeo.ecm.core.io.ExportedDocument; 027import org.nuxeo.ecm.core.io.impl.ExportedDocumentImpl; 028 029/** 030 * Reader for a simple list of DocumentModel objects. 031 * 032 * @author <a href="mailto:dm@nuxeo.com">DM</a> 033 */ 034public class DocumentsListReader extends DocumentModelReader { 035 036 private Iterator<DocumentModel> iterator; 037 038 public DocumentsListReader(CoreSession session, List<DocumentModel> docsList) { 039 super(session); 040 041 iterator = docsList.iterator(); 042 } 043 044 public static DocumentsListReader createDocumentsListReader(CoreSession session, Collection<DocumentRef> docRefsList) { 045 046 List<DocumentModel> list = new ArrayList<DocumentModel>(); 047 048 for (DocumentRef docRef : docRefsList) { 049 DocumentModel doc = session.getDocument(docRef); 050 list.add(doc); 051 } 052 053 return new DocumentsListReader(session, list); 054 } 055 056 @Override 057 public void close() { 058 super.close(); 059 iterator = null; 060 } 061 062 @Override 063 public ExportedDocument read() throws IOException { 064 if (iterator.hasNext()) { 065 DocumentModel docModel = iterator.next(); 066 return new ExportedDocumentImpl(docModel, inlineBlobs); 067 } 068 return null; 069 } 070 071}