001/* 002 * (C) Copyright 2010 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 * Contributors: 016 * Nuxeo - initial API and implementation 017 */ 018 019package org.nuxeo.ecm.platform.rendition.impl; 020 021import java.io.File; 022import java.util.Calendar; 023 024import org.apache.commons.logging.Log; 025import org.apache.commons.logging.LogFactory; 026import org.nuxeo.ecm.core.api.Blob; 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.ecm.core.api.PropertyException; 029import org.nuxeo.ecm.platform.rendition.Rendition; 030import org.nuxeo.ecm.platform.rendition.service.RenditionDefinition; 031 032/** 033 * Base implementation of the {@link Rendition} interface that mainly wrapps the {@link RenditionDefinition} 034 * 035 * @author <a href="mailto:tdelprat@nuxeo.com">Tiry</a> 036 */ 037public abstract class AbstractRendition implements Rendition { 038 039 protected final RenditionDefinition definition; 040 041 protected static final Log log = LogFactory.getLog(AbstractRendition.class); 042 043 public AbstractRendition(RenditionDefinition definition) { 044 this.definition = definition; 045 } 046 047 @Override 048 public String getIcon() { 049 return definition.getIcon(); 050 } 051 052 @Override 053 public String getName() { 054 return definition.getName(); 055 } 056 057 @Override 058 public String getCmisName() { 059 return definition.getCmisName(); 060 } 061 062 @Override 063 public String getLabel() { 064 return definition.getLabel(); 065 } 066 067 @Override 068 public String getKind() { 069 return definition.getKind(); 070 } 071 072 protected RenditionDefinition getDefinition() { 073 return definition; 074 } 075 076 @Override 077 public Calendar getModificationDate() { 078 if (isStored()) { 079 DocumentModel hdoc = getHostDocument(); 080 if (hdoc != null) { 081 try { 082 return (Calendar) hdoc.getPropertyValue("dc:modified"); 083 } catch (PropertyException e) { 084 log.error(e); 085 } 086 } 087 } else if (isCompleted()) { 088 Calendar cal = Calendar.getInstance(); 089 Blob blob = getBlob(); 090 if (blob != null) { 091 File file = blob.getFile(); 092 if (file != null) { 093 cal.setTimeInMillis(file.lastModified()); 094 } 095 } 096 return cal; 097 } 098 return null; 099 } 100 101 @Override 102 public String getProviderType() { 103 return definition.getProviderType(); 104 } 105}