001/* 002 * (C) Copyright 2017 Nuxeo (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 * Guillaume Renard <[email protected]> 018 */ 019package org.nuxeo.ecm.platform.rendition.adapter; 020 021import java.io.Serializable; 022import java.util.Calendar; 023import java.util.Map; 024 025import org.nuxeo.ecm.core.api.Blob; 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.blobholder.AbstractBlobHolder; 028import org.nuxeo.ecm.platform.rendition.Rendition; 029import org.nuxeo.ecm.platform.rendition.service.RenditionService; 030import org.nuxeo.runtime.api.Framework; 031 032/** 033 * Blob holder able to return the blob of a document default rendition. See 034 * {RenditionService#getDefaultRendition(DocumentModel, String, Map<String, Serializable>)} 035 * 036 * @since 9.3 037 */ 038public class DownloadBlobHolder extends AbstractBlobHolder { 039 040 protected final DocumentModel doc; 041 042 public DownloadBlobHolder(DocumentModel doc) { 043 this.doc = doc; 044 } 045 046 @Override 047 public Serializable getProperty(String name) { 048 return null; 049 } 050 051 @Override 052 public Map<String, Serializable> getProperties() { 053 return null; 054 } 055 056 @Override 057 public Blob getBlob() { 058 Rendition rendition = Framework.getService(RenditionService.class).getDefaultRendition(doc, "download", 059 null); 060 return rendition != null ? rendition.getBlob() : null; 061 } 062 063 @Override 064 protected String getBasePath() { 065 return doc.getPathAsString(); 066 } 067 068 @Override 069 public Calendar getModificationDate() { 070 return (Calendar) doc.getPropertyValue("dc:modified"); 071 } 072 073}