001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS (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.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 *     <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
016 *
017 * $Id: IOResourceAdapter.java 25080 2007-09-18 14:52:20Z atchertchian $
018 */
019
020package org.nuxeo.ecm.platform.io.api;
021
022import java.io.InputStream;
023import java.io.OutputStream;
024import java.io.Serializable;
025import java.util.Collection;
026import java.util.Map;
027
028import org.nuxeo.ecm.core.api.DocumentRef;
029import org.nuxeo.ecm.core.io.DocumentTranslationMap;
030
031/**
032 * Resource adapter holding the import/export for document associated resources.
033 *
034 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
035 */
036public interface IOResourceAdapter extends Serializable {
037
038    /**
039     * Returns properties.
040     */
041    Map<String, Serializable> getProperties();
042
043    /**
044     * Set properties.
045     */
046    void setProperties(Map<String, Serializable> properties);
047
048    /**
049     * Extracts resources for given document locations.
050     *
051     * @param repo TODO
052     * @param sources locations of documents to consider. Has to include documents children if needed.
053     * @return a structure holding associated resources.
054     */
055    IOResources extractResources(String repo, Collection<DocumentRef> sources);
056
057    /**
058     * Returns translated resources once copy has been done, passing a correspondence map.
059     *
060     * @param repo target repository for resources.
061     * @param resources resources previously extracted thanks to
062     *            {@link IOResourceAdapter#extractResources(String, Collection)}
063     * @param map correspondence map between old locations and new ones.
064     * @return translated resources.
065     */
066    IOResources translateResources(String repo, IOResources resources, DocumentTranslationMap map);
067
068    /**
069     * Persists resources.
070     *
071     * @param newResources resources previously extracted thanks to
072     *            {@link IOResourceAdapter#extractResources(String, Collection)} or
073     *            {@link IOResourceAdapter#translateResources(String, IOResources, DocumentTranslationMap)}
074     */
075    void storeResources(IOResources newResources);
076
077    /**
078     * Export resources as XML.
079     *
080     * @param out stream where export will be written.
081     * @param newResources resources previously extracted thanks to
082     *            {@link IOResourceAdapter#extractResources(String, Collection)} or
083     *            {@link IOResourceAdapter#translateResources(String, IOResources, DocumentTranslationMap)}
084     */
085    void getResourcesAsXML(OutputStream out, IOResources newResources);
086
087    /**
088     * Returns resources built from given stream.
089     */
090    IOResources loadResourcesFromXML(InputStream stream);
091
092}