001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Florent Guillaume 016 */ 017package org.nuxeo.ecm.core.blob; 018 019import java.util.Collection; 020import java.util.Map; 021import java.util.Set; 022 023import org.nuxeo.ecm.core.api.Blob; 024import org.nuxeo.ecm.core.model.Document; 025 026/** 027 * Interface for a dispatcher of blobs to different blob providers according to metadata. 028 * 029 * @since 7.3 030 */ 031public interface BlobDispatcher { 032 033 static final class BlobDispatch { 034 public final String providerId; 035 036 public final boolean addPrefix; 037 038 public BlobDispatch(String providerId, boolean addPrefix) { 039 this.providerId = providerId; 040 this.addPrefix = addPrefix; 041 } 042 } 043 044 /** 045 * Initializes this blob dispatcher. 046 */ 047 void initialize(Map<String, String> properties); 048 049 /** 050 * Gets the provider ids to which this dispatcher can dispatch. 051 * <p> 052 * Blobs already having a provider id not listed here won't be touched on write. 053 * 054 * @return a collection containing the provider ids 055 */ 056 Collection<String> getBlobProviderIds(); 057 058 /** 059 * Decides which {@link BlobProvider} to use to read a blob from the given repository if no prefix is specified in 060 * the blob key. 061 * 062 * @param repositoryName the repository name 063 * @return the blob provider id 064 */ 065 String getBlobProvider(String repositoryName); 066 067 /** 068 * Decides which {@link BlobProvider} to use to write the given blob, and whether the provider id should be added as 069 * prefix to the managed blob key. 070 * 071 * @param doc the document containing the blob 072 * @param blob the blob 073 * @return the blob provider id and whether it should be added as prefix 074 */ 075 BlobDispatch getBlobProvider(Document doc, Blob blob); 076 077 /** 078 * Notifies the blob dispatcher that a set of xpaths have changed on a document. 079 * 080 * @param doc the document 081 * @param xpaths the set of changed xpaths 082 * @since 7.3 083 */ 084 void notifyChanges(Document doc, Set<String> xpaths); 085 086}