001/*
002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     ataillefer
016 */
017
018package org.nuxeo.ecm.core.io.impl.plugins;
019
020import java.io.IOException;
021
022import org.nuxeo.ecm.core.api.CoreSession;
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.core.api.DocumentRef;
025import org.nuxeo.ecm.core.io.ExportedDocument;
026import org.nuxeo.ecm.core.io.impl.TypedExportedDocumentImpl;
027
028/**
029 * @author <a href="mailto:ataillefer@nuxeo.com">Antoine Taillefer</a>
030 * @since 5.6
031 */
032public class TypedSingleDocumentReader extends SingleDocumentReader {
033
034    public TypedSingleDocumentReader(CoreSession session, DocumentModel root) {
035        super(session, root);
036    }
037
038    public TypedSingleDocumentReader(CoreSession session, DocumentRef root) {
039        this(session, session.getDocument(root));
040    }
041
042    @Override
043    public ExportedDocument read() throws IOException {
044        if (doc != null) {
045            if (readDone && !enableRepeatedReads) {
046                return null;
047            } else {
048                readDone = true;
049                return new TypedExportedDocumentImpl(doc);
050            }
051        }
052        doc = null;
053        return null;
054    }
055
056}