org.restheart.plugins.FileConfigurablePlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of restheart-commons Show documentation
Show all versions of restheart-commons Show documentation
RESTHeart Commons - Common classes for core components and plugins.
/*-
* ========================LICENSE_START=================================
* restheart-commons
* %%
* Copyright (C) 2019 - 2024 SoftInstigate
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================LICENSE_END==================================
*/
package org.restheart.plugins;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import org.restheart.configuration.Configuration;
import org.restheart.configuration.ConfigurationException;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
/**
* An helper class that simplifies getting the Plugin args from a configuration
* file.
*
* @author Maurizio Turatti {@literal }
*/
abstract public class FileConfigurablePlugin implements ConfigurablePlugin {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(FileConfigurablePlugin.class);
public abstract Consumer super Map> consumeConfiguration() throws ConfigurationException;
/**
* get the configuration args parsing the file specified in the Plugin argument
* 'conf-file'
*
* @param arguments
* @param type
* @throws java.io.FileNotFoundException
* @throws org.restheart.configuration.ConfigurationException
*/
@SuppressWarnings("unchecked")
public void init(Map arguments, String type) throws FileNotFoundException, ConfigurationException {
InputStream is = null;
try {
final String confFilePath = extractConfigFilePath(arguments);
is = new FileInputStream(new File(java.net.URLDecoder.decode(confFilePath, "utf-8")));
final Map conf = (Map) new Yaml(new SafeConstructor(new LoaderOptions())).load(is);
List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy