001/*
002 *  Copyright 2014 Anyware Services
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 */
016package org.ametys.plugins.contentio.in;
017
018import java.io.IOException;
019import java.io.InputStream;
020import java.util.Map;
021import java.util.Set;
022
023/**
024 * Interface representing a component which imports contents from a file.
025 */
026public interface ContentImporter
027{
028    
029    /**
030     * Tests if the {@link ContentImporter} is able to import the corresponding stream.<br>
031     * Implementing classes should first test the file extension, if possible, and if the name is provided.
032     * @param is an input stream on the file, cannot be null. The stream is closed by the caller.
033     * @param name the file name, can be null.
034     * @return true if the {@link ContentImporter} can import the corresponding stream, false otherwise.
035     * @throws IOException if an error occurs.
036     */
037    public boolean supports(InputStream is, String name) throws IOException;
038    
039    /**
040     * Get the importer priority. A lower number means a higher priority.
041     * @return the importer priority.
042     */
043    public int getPriority();
044    
045    /**
046     * Import the contents from the file.
047     * @param is an input stream on the file, cannot be null. The stream is closed by the caller.
048     * @param params input or output parameters.
049     * @return a Set of the imported content IDs.
050     * @throws IOException if an error occurs importing the contents.
051     */
052    public Set<String> importContents(InputStream is, Map<String, Object> params) throws IOException;
053    
054}