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: AbstractDocumentReader.java 30477 2008-02-22 10:02:15Z dmihalache $ 013 */ 014 015package org.nuxeo.ecm.core.io.impl; 016 017import java.io.IOException; 018import java.util.ArrayList; 019import java.util.List; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.ecm.core.io.DocumentReader; 024import org.nuxeo.ecm.core.io.ExportedDocument; 025 026/** 027 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 028 */ 029public abstract class AbstractDocumentReader implements DocumentReader { 030 031 private static final Log log = LogFactory.getLog(AbstractDocumentReader.class); 032 033 // this abstract method is needed 034 @Override 035 public abstract ExportedDocument read() throws IOException; 036 037 @Override 038 public ExportedDocument[] read(int count) throws IOException { 039 List<ExportedDocument> docs = new ArrayList<ExportedDocument>(count); 040 for (int i = 0; i < count; i++) { 041 ExportedDocument doc = read(); 042 if (doc == null) { 043 break; 044 } 045 046 /* NXP-1688 Rux: no ID, it should be a OS folder and not an exported one */ 047 if (doc.getId() != null) { 048 if (log.isDebugEnabled()) { 049 log.debug("Adding document to be transformed (path): " + doc.getPath()); 050 } 051 docs.add(doc); 052 } else { 053 log.warn("no ID for document, won't add " + doc); 054 } 055 } 056 if (docs.isEmpty()) { 057 return null; 058 } 059 return docs.toArray(new ExportedDocument[docs.size()]); 060 } 061 062}