Stirling-PDF/src/main/java/stirling/software/SPDF/config/AppConfig.java

78 lines
2.4 KiB
Java
Raw Normal View History

2023-08-13 02:15:26 +02:00
package stirling.software.SPDF.config;
2023-08-26 13:27:52 +02:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
2023-08-13 02:15:26 +02:00
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
2023-08-26 13:27:52 +02:00
import org.springframework.core.env.Environment;
2023-08-13 02:15:26 +02:00
@Configuration
public class AppConfig {
2023-08-26 13:27:52 +02:00
@Value("${login.enabled:false}")
private boolean defaultLoginEnabled;
@Value("${ui.homeName:Stirling PDF}")
private String defaultAppName;
@Value("${ui.homeDescription:null}")
private String defaultHomeText;
@Value("${ui.navbarName:Stirling PDF}")
private String defaultNavBarText;
@Bean(name = "loginEnabled")
2023-08-13 02:15:26 +02:00
public boolean loginEnabled() {
2023-08-26 13:27:52 +02:00
return getBooleanValue("login.enabled", defaultLoginEnabled);
2023-08-13 02:15:26 +02:00
}
2023-08-26 13:27:52 +02:00
2023-08-13 02:15:26 +02:00
@Bean(name = "appName")
public String appName() {
2023-08-26 13:27:52 +02:00
return getStringValue("APP_HOME_NAME", defaultAppName);
2023-08-13 02:15:26 +02:00
}
@Bean(name = "appVersion")
public String appVersion() {
String version = getClass().getPackage().getImplementationVersion();
return (version != null) ? version : "0.0.0";
}
@Bean(name = "homeText")
public String homeText() {
2023-08-26 13:27:52 +02:00
return getStringValue("APP_HOME_DESCRIPTION", defaultHomeText);
2023-08-13 02:15:26 +02:00
}
@Bean(name = "navBarText")
public String navBarText() {
2023-08-26 13:27:52 +02:00
String navBarText = getStringValue("APP_NAVBAR_NAME", null);
if (navBarText == null) {
navBarText = getStringValue("APP_HOME_NAME", defaultNavBarText);
}
return navBarText;
}
private boolean getBooleanValue(String key, boolean defaultValue) {
String value = System.getProperty(key);
if (value == null)
value = System.getenv(key);
return (value != null) ? Boolean.valueOf(value) : defaultValue;
}
2023-08-13 02:15:26 +02:00
2023-08-26 13:27:52 +02:00
private String getStringValue(String key, String defaultValue) {
String value = System.getProperty(key);
if (value == null)
value = System.getenv(key);
return (value != null) ? value : defaultValue;
}
@Bean(name = "rateLimit")
public boolean rateLimit() {
String appName = System.getProperty("rateLimit");
if (appName == null)
appName = System.getenv("rateLimit");
System.out.println("rateLimit=" + appName);
return (appName != null) ? Boolean.valueOf(appName) : false;
2023-08-13 02:15:26 +02:00
}
2023-08-26 13:27:52 +02:00
}