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
023import org.ametys.runtime.plugin.component.Prioritizable;
024
025/**
026 * Interface representing a component which imports contents from a file.
027 */
028public interface ContentImporter extends Prioritizable
029{
030    
031    /**
032     * Tests if the {@link ContentImporter} is able to import the corresponding stream.<br>
033     * Implementing classes should first test the file extension, if possible, and if the name is provided.
034     * @param is an input stream on the file, cannot be null. The stream is closed by the caller.
035     * @param name the file name, can be null.
036     * @return true if the {@link ContentImporter} can import the corresponding stream, false otherwise.
037     * @throws IOException if an error occurs.
038     */
039    public boolean supports(InputStream is, String name) throws IOException;
040    
041    /**
042     * Import the contents from the file.
043     * @param is an input stream on the file, cannot be null. The stream is closed by the caller.
044     * @param params input or output parameters.
045     * @return a Set of the imported content IDs.
046     * @throws IOException if an error occurs importing the contents.
047     */
048    public Set<String> importContents(InputStream is, Map<String, Object> params) throws IOException;
049    
050}