Contribute to this guideReport an issue

guideLoading configuration from a custom location

CKFinder loads the configuration once, at the start of the application.

By default, the CKFinder 3 for Java connector searches the application’s resources directory for a file named ckfinder.yml. The template of this configuration file can be found here.

In some cases you may want to alter the default behavior, and load the configuration from the file system path or from the database. You can achieve this by creating a custom component that implements the ConfigLoader interface. If the connector detects this type of component at the start of the application, it will use it to load the configuration instead of searching the application resources directory for a file named ckfinder.yml

In the example presented below, the configuration is loaded from the YAML file located under a physical file system path /home/joe/ckfinder.yml.

package com.cksource.ckfinder;

import com.cksource.ckfinder.config.Config;
import com.cksource.ckfinder.config.loader.ConfigLoader;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import javax.inject.Named;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class CustomConfigLoader implements ConfigLoader {
    public Config loadConfig() throws IOException {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        Path configPath = Paths.get("/home/joe/ckfinder.yml");

        return mapper.readValue(Files.newInputStream(configPath), Config.class);