001/*
002 * (C) Copyright 2006-2007 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 *     <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
018 *
019 * $Id: IOManager.java 30145 2008-02-13 16:56:56Z dmihalache $
020 */
021
022package org.nuxeo.ecm.platform.io.api;
023
024import java.io.IOException;
025import java.io.InputStream;
026import java.io.OutputStream;
027import java.io.Serializable;
028import java.util.Collection;
029import java.util.Map;
030
031import org.nuxeo.ecm.core.api.DocumentLocation;
032import org.nuxeo.ecm.core.api.DocumentRef;
033
034/**
035 * Service handling complex import/export of documents and associated resources.
036 *
037 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a>
038 */
039public interface IOManager extends Serializable {
040
041    String DOCUMENTS_ADAPTER_NAME = "documents";
042
043    /**
044     * Returns the adapter with given name.
045     */
046    IOResourceAdapter getAdapter(String name);
047
048    /**
049     * Adds an adapter with given name and definition.
050     */
051    void addAdapter(String name, IOResourceAdapter adapter);
052
053    /**
054     * Removes adapter with given name.
055     */
056    void removeAdapter(String name);
057
058    /**
059     * Import document and resources described by given input stream at given document location.
060     *
061     * @param in stream representing the documents and resources to import. Can be a zip file of a group of export
062     *            files. The service is responsible for unzipping and redirecting import to specific import services.
063     * @param repo the repository name.
064     * @param root Optional location of document that must be taken as root of the import (can be null).
065     */
066    void importDocumentsAndResources(InputStream in, String repo, DocumentRef root) throws IOException;
067
068    /**
069     * Export documents and resources.
070     *
071     * @param out stream that can be turned into a zip holding a group of file for each additional resources types.
072     * @param repo TODO
073     * @param sources locations of documents to export.
074     * @param recurse recurse into sources children
075     * @param format export format. XXX see what format is actually accepted.
076     * @param ioAdapters list of adapters to use for additional resources.
077     */
078    void exportDocumentsAndResources(OutputStream out, String repo, Collection<DocumentRef> sources, boolean recurse,
079            String format, Collection<String> ioAdapters) throws IOException;
080
081    /**
082     * Copy documents and resources to another location (on a same machine).
083     *
084     * @param repo the initial repository name.
085     * @param sources locations of documents to export.
086     * @param targetLocation location of the document where copies must be placed.
087     * @param ioAdapters list of adapters to use for additional resources.
088     * @return the list of copied documents references.
089     */
090    Collection<DocumentRef> copyDocumentsAndResources(String repo, Collection<DocumentRef> sources,
091            DocumentLocation targetLocation, Collection<String> ioAdapters);
092
093    void importFromStream(InputStream in, DocumentLocation targetLocation, String docReaderFactoryClassName,
094            Map<String, Object> rFactoryParams, String docWriterFactoryClassName, Map<String, Object> wFactoryParams);
095
096}