001/*
002 *  Copyright 2022 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.odf.init;
017
018import java.nio.file.FileSystems;
019import java.util.ArrayList;
020import java.util.List;
021
022import org.apache.avalon.framework.configuration.Configuration;
023import org.apache.avalon.framework.configuration.ConfigurationException;
024
025/**
026 * ODF reference table data description to import on initialization.
027 * Files to import are listed in the plugin description.
028 */
029public class OdfRefTableDataAsFilesList extends OdfRefTableDataAsFolder
030{
031    /** List of data filenames to import */
032    protected List<String> _dataFilenames;
033    
034    @Override
035    public void configure(Configuration configuration) throws ConfigurationException
036    {
037        super.configure(configuration);
038        _dataFilenames = new ArrayList<>();
039        for (Configuration fileConfiguration : configuration.getChild("files").getChildren("file"))
040        {
041            _dataFilenames.add(fileConfiguration.getValue());
042        }
043    }
044    
045    @Override
046    protected List<String> getDataFiles()
047    {
048        return _dataFilenames.stream()
049            .map(filename -> _dataFolder + FileSystems.getDefault().getSeparator() + filename)
050            .toList();
051    }
052}