All Downloads are FREE. Search and download functionalities are using the official Maven repository.

htmlcompiler.pojos.compile.CompilerConfig Maven / Gradle / Ivy

The newest version!
package htmlcompiler.pojos.compile;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Type;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static htmlcompiler.utils.Json.GSON;
import static htmlcompiler.utils.Strings.isNullOrBlank;
import static java.nio.file.Files.isRegularFile;
import static java.nio.file.Files.newBufferedReader;

public final class CompilerConfig {

    public final Set ignoreTags;
    public final Set ignoreAttributes;
    public final Set ignoreInputTypes;
    public final Map checks;
    public final boolean ignoreMajorVersions;
    public final ValidatorConfig validator;

    public CompilerConfig() {
        this(new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashMap<>(), false, new ValidatorConfig());
    }

    public CompilerConfig(final Set ignoreTags, final Set ignoreAttributes,
                          final Set ignoreInputTypes, final Map checks,
                          final boolean ignoreMajorVersions, final ValidatorConfig validator) {
        this.ignoreTags = ignoreTags;
        this.ignoreAttributes = ignoreAttributes;
        this.ignoreInputTypes = ignoreInputTypes;
        this.checks = checks;
        this.ignoreMajorVersions = ignoreMajorVersions;
        this.validator = validator;
    }

    private static final Type CONFIG_MAP_TYPE = new TypeToken>() {}.getType();
    public static Map readChecksConfiguration(final String confLocation) throws IOException {
        if (isNullOrBlank(confLocation)) return Map.of("", new CompilerConfig());
        final Path confFile = Paths.get(confLocation);
        if (!isRegularFile(confFile)) return Map.of("", new CompilerConfig());

        try (final Reader in = newBufferedReader(confFile)) {
            return GSON.fromJson(in, CONFIG_MAP_TYPE);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy