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 *     Anahide Tchertchian
018 */
019package org.nuxeo.ecm.core.api.externalblob;
020
021import java.io.IOException;
022import java.io.Serializable;
023import java.util.Map;
024
025import org.nuxeo.ecm.core.api.Blob;
026import org.nuxeo.ecm.core.api.PropertyException;
027
028/**
029 * Interface to implement when defining a way to get a {@link Blob} that is not stored at the usual place handled by the
030 * repository.
031 * <p>
032 * This is done storing a string instead of a blob, using a prefix that makes it possible to find the adapter in charge
033 * of retrieving the file. It makes it also possible to use the same adapter implementation for different
034 * configurations, in conjunction with properties.
035 * <p>
036 * The string will look something like "fs:file/foo.odt", "fs" being the prefix, and "file/foo.odt" being the local
037 * name, with all the needed information to retrieve the actual file for this adapter.
038 *
039 * @author Anahide Tchertchian
040 */
041public interface ExternalBlobAdapter extends Serializable {
042
043    String PREFIX_SEPARATOR = ":";
044
045    /**
046     * Returns the prefix to use as marker for this adapter
047     */
048    String getPrefix();
049
050    /**
051     * Sets the prefix to use as marker for this adapter
052     */
053    void setPrefix(String prefix);
054
055    /**
056     * Return specific properties for this adapter. Can be used for whatever useful property.
057     */
058    Map<String, String> getProperties();
059
060    /**
061     * Return property with gievn name.
062     * <p>
063     * Returns null if no property value is found.
064     */
065    String getProperty(String name);
066
067    /**
068     * Set specific properties for this adapter. Can be used for whatever useful property.
069     */
070    void setProperties(Map<String, String> properties);
071
072    /**
073     * Retrieves the blob for given uri.
074     *
075     * @param uri the uri describing what adapter handles the file and the needed info to retrieve it.
076     * @return the resolved blob.
077     * @throws PropertyException if the blob cannot be retrieved (if adapter cannot retrieve it or if file is not found
078     *             for instance)
079     */
080    Blob getBlob(String uri) throws PropertyException, IOException;
081
082}