001/* 002 * (C) Copyright 2006-2009 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 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.picture.api.adapters; 023 024import java.util.ArrayList; 025import java.util.Collection; 026import java.util.List; 027 028import org.nuxeo.ecm.core.api.Blob; 029import org.nuxeo.ecm.core.api.DocumentModel; 030import org.nuxeo.ecm.core.api.blobholder.DocumentBlobHolder; 031import org.nuxeo.ecm.core.api.model.Property; 032 033public class PictureBlobHolder extends DocumentBlobHolder { 034 035 public PictureBlobHolder(DocumentModel doc, String path) { 036 super(doc, path); 037 } 038 039 @Override 040 public List<Blob> getBlobs() { 041 List<Blob> blobList = new ArrayList<>(); 042 043 Blob mainBlob = getBlob(); 044 if (mainBlob != null) { 045 blobList.add(getBlob()); 046 } 047 048 Collection<Property> views = doc.getProperty("picture:views").getChildren(); 049 for (Property property : views) { 050 blobList.add((Blob) property.getValue("content")); 051 } 052 return blobList; 053 } 054 055 public List<Blob> getBlobs(String... viewNames) { 056 List<Blob> blobList = new ArrayList<>(); 057 for (String viewName : viewNames) { 058 blobList.add(getBlob(viewName)); 059 } 060 return blobList; 061 } 062 063 public Blob getBlob(String title) { 064 PictureResourceAdapter picture = doc.getAdapter(PictureResourceAdapter.class); 065 return picture.getPictureFromTitle(title); 066 } 067 068 @Override 069 public String getHash() { 070 071 Blob blob = getBlob(); 072 if (blob != null) { 073 String h = blob.getDigest(); 074 if (h != null) { 075 return h; 076 } 077 } 078 return doc.getId() + xPath + getModificationDate().toString(); 079 } 080 081}