mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
14.04.2019 d8523faa15d17a70009f0391ef535c04c1c9f6bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package de.micromata.borgbutler.server;
 
import com.fasterxml.jackson.annotation.JsonProperty;
import de.micromata.borgbutler.cache.ButlerCache;
import de.micromata.borgbutler.config.Configuration;
import de.micromata.borgbutler.config.ConfigurationHandler;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class ServerConfiguration extends Configuration {
    private static Logger log = LoggerFactory.getLogger(ServerConfiguration.class);
    private final static String[] SUPPORTED_LANGUAGES = {"en", "de"};
    public static final int WEBSERVER_PORT_DEFAULT = 9042;
    private static final boolean WEB_DEVELOPMENT_MODE_PREF_DEFAULT = false;
 
    private static String applicationHome;
 
    private int port = WEBSERVER_PORT_DEFAULT;
    private boolean webDevelopmentMode = WEB_DEVELOPMENT_MODE_PREF_DEFAULT;
    @JsonProperty
    public String getCacheDir() {
        return ButlerCache.getInstance().getCacheDir().getAbsolutePath();
    }
 
    public static ServerConfiguration get() {
        return (ServerConfiguration)ConfigurationHandler.getConfiguration();
    }
 
    public static String[] getSupportedLanguages() {
        return SUPPORTED_LANGUAGES;
    }
 
    public static String getApplicationHome() {
        if (applicationHome == null) {
            applicationHome = System.getProperty("applicationHome");
            if (StringUtils.isBlank(applicationHome)) {
                applicationHome = System.getProperty("user.dir");
                log.info("applicationHome is not given as JVM   parameter. Using current working dir (OK for start in IDE): " + applicationHome);
            }
        }
        return applicationHome;
    }
 
    public int getPort() {
        return port;
    }
 
    public void setPort(int port) {
        this.port = port;
    }
 
    /**
     * If true, CrossOriginFilter will be set.
     */
    public boolean isWebDevelopmentMode() {
        return webDevelopmentMode;
    }
 
    public void setWebDevelopmentMode(boolean webDevelopmentMode) {
        this.webDevelopmentMode = webDevelopmentMode;
    }
 
    public void copyFrom(ServerConfiguration other) {
        super.copyFrom(other);
        this.port = other.port;
        this.webDevelopmentMode = other.webDevelopmentMode;
    }
}