001/*
002 * (C) Copyright 2010 Nuxeo SAS (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 * Contributors:
014 * Nuxeo - initial API and implementation
015 */
016
017package org.nuxeo.ecm.platform.rendition.impl;
018
019import java.util.List;
020
021import org.nuxeo.ecm.core.api.Blob;
022import org.nuxeo.ecm.core.api.DocumentModel;
023import org.nuxeo.ecm.core.api.NuxeoException;
024import org.nuxeo.ecm.platform.rendition.Rendition;
025import org.nuxeo.ecm.platform.rendition.extension.RenditionProvider;
026import org.nuxeo.ecm.platform.rendition.service.RenditionDefinition;
027
028/**
029 * Implementation of the {@link Rendition} interface that is applicable for rendition created on the fly
030 *
031 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
032 */
033public class LiveRendition extends LazyRendition implements Rendition {
034
035    protected final DocumentModel doc;
036
037    public LiveRendition(DocumentModel doc, RenditionDefinition definition) {
038        super(definition);
039        this.doc = doc;
040    }
041
042    @Override
043    public boolean isStored() {
044        return false;
045    }
046
047    @Override
048    public DocumentModel getHostDocument() {
049        return doc;
050    }
051
052    @Override
053    protected List<Blob> computeRenditionBlobs() {
054
055        RenditionProvider provider = getDefinition().getProvider();
056        if (provider == null) {
057            throw new NuxeoException("No Rendition provider defined");
058        }
059
060        return provider.render(getHostDocument(), getDefinition());
061    }
062
063}