001/* 002 * (C) Copyright 2006-2011 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 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 */ 020 021package org.nuxeo.ecm.core.api.blobholder; 022 023import java.io.Serializable; 024import java.util.ArrayList; 025import java.util.Arrays; 026import java.util.Calendar; 027import java.util.List; 028import java.util.Map; 029 030import org.nuxeo.ecm.core.api.Blob; 031 032/** 033 * {@link BlobHolder} implementation that simply wraps a detached {@link Blob}. 034 * 035 * @author tiry 036 */ 037public class SimpleBlobHolder extends AbstractBlobHolder { 038 039 protected List<Blob> blobs; 040 041 protected Calendar creationDate; 042 043 public SimpleBlobHolder() { 044 // Empty constructor 045 } 046 047 public SimpleBlobHolder(List<Blob> blobs) { 048 init(blobs); 049 } 050 051 public SimpleBlobHolder(Blob blob) { 052 blobs = new ArrayList<>(); 053 blobs.add(blob); 054 init(blobs); 055 } 056 057 protected void init(List<Blob> blobs) { 058 this.blobs = blobs; 059 creationDate = Calendar.getInstance(); 060 } 061 062 @Override 063 public void setBlob(Blob blob) { 064 init(new ArrayList<>(Arrays.asList(blob))); 065 } 066 067 @Override 068 public Blob getBlob() { 069 if (blobs == null || blobs.size() == 0) { 070 return null; 071 } else { 072 return blobs.get(0); 073 } 074 } 075 076 @Override 077 public List<Blob> getBlobs() { 078 return blobs; 079 } 080 081 @Override 082 protected String getBasePath() { 083 return ""; 084 } 085 086 @Override 087 public Calendar getModificationDate() { 088 return creationDate; 089 } 090 091 @Override 092 public Serializable getProperty(String name) { 093 return null; 094 } 095 096 @Override 097 public Map<String, Serializable> getProperties() { 098 return null; 099 } 100 101}