001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id: AbstractDocumentReader.java 30477 2008-02-22 10:02:15Z dmihalache $ 020 */ 021 022package org.nuxeo.ecm.core.io.impl; 023 024import java.io.IOException; 025import java.util.ArrayList; 026import java.util.List; 027 028import org.apache.commons.logging.Log; 029import org.apache.commons.logging.LogFactory; 030import org.nuxeo.ecm.core.io.DocumentReader; 031import org.nuxeo.ecm.core.io.ExportedDocument; 032 033/** 034 * @author <a href="mailto:[email protected]">Bogdan Stefanescu</a> 035 */ 036public abstract class AbstractDocumentReader implements DocumentReader { 037 038 private static final Log log = LogFactory.getLog(AbstractDocumentReader.class); 039 040 // this abstract method is needed 041 @Override 042 public abstract ExportedDocument read() throws IOException; 043 044 @Override 045 public ExportedDocument[] read(int count) throws IOException { 046 List<ExportedDocument> docs = new ArrayList<ExportedDocument>(count); 047 for (int i = 0; i < count; i++) { 048 ExportedDocument doc = read(); 049 if (doc == null) { 050 break; 051 } 052 053 /* NXP-1688 Rux: no ID, it should be a OS folder and not an exported one */ 054 if (doc.getId() != null) { 055 if (log.isDebugEnabled()) { 056 log.debug("Adding document to be transformed (path): " + doc.getPath()); 057 } 058 docs.add(doc); 059 } else { 060 log.warn("no ID for document, won't add " + doc); 061 } 062 } 063 if (docs.isEmpty()) { 064 return null; 065 } 066 return docs.toArray(new ExportedDocument[docs.size()]); 067 } 068 069}