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.Calendar;
020import java.util.GregorianCalendar;
021
022import org.apache.commons.logging.Log;
023import org.apache.commons.logging.LogFactory;
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.platform.rendition.Rendition;
026import org.nuxeo.ecm.platform.rendition.service.RenditionDefinition;
027
028/**
029 * Base implementation of the {@link Rendition} interface that mainly wrapps the {@link RenditionDefinition}
030 *
031 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a>
032 */
033public abstract class AbstractRendition implements Rendition {
034
035    protected final RenditionDefinition definition;
036
037    protected static final Log log = LogFactory.getLog(AbstractRendition.class);
038
039    public AbstractRendition(RenditionDefinition definition) {
040        this.definition = definition;
041    }
042
043    @Override
044    public String getIcon() {
045        return definition.getIcon();
046    }
047
048    @Override
049    public String getName() {
050        return definition.getName();
051    }
052
053    @Override
054    public String getCmisName() {
055        return definition.getCmisName();
056    }
057
058    @Override
059    public String getLabel() {
060        return definition.getLabel();
061    }
062
063    @Override
064    public String getKind() {
065        return definition.getKind();
066    }
067
068    protected RenditionDefinition getDefinition() {
069        return definition;
070    }
071
072    @Override
073    public Calendar getModificationDate() {
074        if (!isStored()) {
075            // for on the fly rendition return the current time
076            return new GregorianCalendar();
077        } else {
078            DocumentModel hdoc = getHostDocument();
079            if (hdoc != null) {
080                try {
081                    return (Calendar) hdoc.getPropertyValue("dc:modified");
082                } catch (Exception e) {
083                    log.error(e);
084                }
085            }
086        }
087        return null;
088    }
089
090    @Override
091    public String getProviderType() {
092        return definition.getProviderType();
093    }
094}