/*
* (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Contributors:
* Nuxeo - initial API and implementation
*
* $Id$
*/
package org.nuxeo.ecm.platform.picture.api.adapters;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.nuxeo.ecm.core.api.Blob;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.blobholder.DocumentBlobHolder;
import org.nuxeo.ecm.core.api.model.Property;
public class PictureBlobHolder extends DocumentBlobHolder {
public PictureBlobHolder(DocumentModel doc, String path) {
super(doc, path);
}
@Override
public List<Blob> getBlobs() {
List<Blob> blobList = new ArrayList<>();
Blob mainBlob = getBlob();
if (mainBlob != null) {
blobList.add(getBlob());
}
Collection<Property> views = doc.getProperty("picture:views").getChildren();
for (Property property : views) {
blobList.add((Blob) property.getValue("content"));
}
return blobList;
}
public List<Blob> getBlobs(String... viewNames) {
List<Blob> blobList = new ArrayList<>();
for (String viewName : viewNames) {
blobList.add(getBlob(viewName));
}
return blobList;
}
public Blob getBlob(String title) {
PictureResourceAdapter picture = doc.getAdapter(PictureResourceAdapter.class);
return picture.getPictureFromTitle(title);
}
@Override
public String getHash() {
Blob blob = getBlob();
if (blob != null) {
String h = blob.getDigest();
if (h != null) {
return h;
}
}
return doc.getId() + xPath + getModificationDate().toString();
}
}