Package ch.autumo.beetroot
Class BeetRootConfigurationManager
java.lang.Object
ch.autumo.beetroot.BeetRootConfigurationManager
Configuration manager.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StringApplication version.protected booleanprotected static final org.slf4j.Logger -
Method Summary
Modifier and TypeMethodDescriptionString[]App-roles for the simple role-management (1 role per user, stored in user table).static StringGet application version.Returns the file name of the base configuration.getDecodedString(String key, SecureApplication app) Decode encrypted value, if it is encrypted by beetRoot standards!Returns the full base path, where the base configuration is.getHtmlInputMapPattern(String columnName) Get HTML input map pattern.getHtmlInputMapType(String columnName) Get HTML input map type.static BeetRootConfigurationManagerGet configuration manager.intGet integer value.intGet integer value.intgetIntNoWarn(String key) Get integer value; no warning if value is not available.String[]Get all keys starting with a specific key-prefix.getLanguage(String langCode) Get language.getMimeTypes(String key) Get allowed mime types.Get app root path.String[]getSepValues(String key) Get comma-separated values, e.g.String[]getSepValuesNoWarn(String key) Get comma-separated values, e.g.jakarta.servlet.ServletContextGet servlet contextGet servlet name if any (only in servlet context)Get a string value.Get a string value or default value if non-existent.getStringNoWarn(String key) Get a string value; no warning if value is not available.String[]Get all values starting with a specific key-prefix.getXMLModuleConfig(String xmlConfigFile, String moduleName) Get XML module root configuration.getXMLModuleConfigRelative(String xmlRelativePath, String moduleName) Get XML module root configuration.getXMLModuleConfigWithFullPath(String xmlConfigFilePath, String moduleName) Get XML module root configuration.booleangetYesOrNo(String key) Get yes (true) or no (false), if the configuration is messed up false is returned.booleangetYesOrNo(String key, String defaultVal) Get yes (true) or no (false), or the default value if the configuration is missing.booleangetYesOrNoNoWarn(String key) Get yes (true) or no (false), if the configuration is messed up false is returned.voidInitialize with standard configuration path 'ROOTPATH/cfg/beetroot.cfg'.voidinitialize(String relativePath) Initialize with path 'ROOTPATH/<given-path-and-file>'.voidinitializeDesktop(String desktopCfgFile, String appName) Initialize with desktop configuration which must have been created beforehand by the desktop application!voidinitializeWithFullPath(String configFilePath) Initialize configuration from a specified path, optionally using a servlet context.voidinitializeWithFullPath(String configFilePath, jakarta.servlet.ServletContext servletContext) Initialize configuration from a specified path, optionally using a ServletContext.static booleanHas this configuration manager been initialized?booleanisRemote()Returns true if it doesn't run server-side.booleanReturn true, if this configuration manager runs within a desktop otherwise false.booleanReturn true, if this configuration manager runs within a servlet otherwise false.booleanTranslated templates?updateProperty(String key, String value) Update or add a value to the internal properties.booleanuseCsrf()Use CSRF?booleanUse extended roles?
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG -
appVersion
Application version. -
isWithinDesktop
protected boolean isWithinDesktop
-
-
Method Details
-
getInstance
Get configuration manager.- Returns:
- manager
-
getAppVersion
Get application version.- Returns:
- application version
-
isInitialized
public static boolean isInitialized()Has this configuration manager been initialized?- Returns:
- true if so, otherwise false
-
runsWithinServletContext
public boolean runsWithinServletContext()Return true, if this configuration manager runs within a servlet otherwise false.- Returns:
- true is is within servlet context
-
runsWithinDesktopContext
public boolean runsWithinDesktopContext()Return true, if this configuration manager runs within a desktop otherwise false.- Returns:
- true is is within desktop context
-
isRemote
public boolean isRemote()Returns true if it doesn't run server-side.- Returns:
- false if server-side
-
updateProperty
Update or add a value to the internal properties.- Parameters:
key- keyvalue- vane- Returns:
- old value if any or null
-
initialize
Initialize with path 'ROOTPATH/<given-path-and-file>'. No resource paths!- Parameters:
relativePath- relative path- Throws:
Exception- exception
-
initialize
Initialize with standard configuration path 'ROOTPATH/cfg/beetroot.cfg'. No resource paths!- Throws:
Exception- exception
-
initializeWithFullPath
public void initializeWithFullPath(String configFilePath, jakarta.servlet.ServletContext servletContext) throws Exception Initialize configuration from a specified path, optionally using a ServletContext. This variant allows the configuration to be loaded from the WAR if 'servletContext' is provided. It delegates the actual loading logic to the maininitializeWithFullPath(String)method and then sets servletContext for later supplementary resource loading. The configuration file can be: 1. An external file on the filesystem 2. A resource inside the WAR (if servletContext is not null) 3. A resource on the classpath The method sets 'fullConfigBasePath' and 'cfgFileName' according to the resolved location of the configuration file.- Parameters:
configFilePath- path to the configuration file (absolute, relative in WAR, or classpath)servletContext- the ServletContext, or null if running outside a servlet environment- Throws:
Exception- if the configuration file cannot be found or read
-
initializeWithFullPath
Initialize configuration from a specified path, optionally using a servlet context. This method attempts to load the configuration file from three possible locations: 1. External file on the filesystem. 2. Resource inside the WAR if 'servletContext' is provided. 3. Classpath fallback if neither of the above is found. The base path of the configuration file (`fullConfigBasePath`) is calculated robustly for filesystem files using canonical paths, and normalized for resources inside the WAR or on the classpath to ensure consistent relative path handling. This ensures relative paths, nested directories, or "."/ ".." references are handled correctly. After loading the main configuration, certain core properties are extracted and stored: - CSRF usage - Extended roles - Template translation Additionally, optional or mandatory supplementary property files such as the HTML input map and 'languages.cfg' are loaded using the same three-case handling.- Parameters:
configFilePath- path to the configuration file (absolute path, relative path in WAR, or classpath resource)- Throws:
Exception- if the main configuration file cannot be found or read, or if mandatory supplementary files fail to load
-
initializeDesktop
Initialize with desktop configuration which must have been created beforehand by the desktop application!- Parameters:
desktopCfgFile- only the file name without path, e.g. 'myapp.cfg'appName- application name- Throws:
Exception- exception
-
getLanguage
Get language.- Parameters:
langCode- language code- Returns:
- full language name
-
getHtmlInputMapType
Get HTML input map type.- Parameters:
columnName- column name- Returns:
- HTML input map type or null
-
getHtmlInputMapPattern
Get HTML input map pattern.- Parameters:
columnName- column name- Returns:
- HTML input map pattern or null
-
getFullConfigBasePath
Returns the full base path, where the base configuration is.- Returns:
- base path
-
getConfigFileName
Returns the file name of the base configuration.- Returns:
- file name
-
translateTemplates
public boolean translateTemplates()Translated templates?- Returns:
- true if templates should be translated
-
useExtendedRoles
public boolean useExtendedRoles()Use extended roles?- Returns:
- true if extended roles should be used
-
useCsrf
public boolean useCsrf()Use CSRF?- Returns:
- true if CSRF should be used
-
getRootPath
Get app root path.- Returns:
- root path
-
getString
Get a string value.- Parameters:
key- key- Returns:
- string value
-
getString
Get a string value or default value if non-existent.- Parameters:
key- keydefaultVal- default value- Returns:
- string value
-
getStringNoWarn
Get a string value; no warning if value is not available.- Parameters:
key- key- Returns:
- string value
-
getKeys
Get all keys starting with a specific key-prefix.- Parameters:
keyPrefix- key prefix, e.g. 'dispatcher_'- Returns:
- collected values
-
getValues
Get all values starting with a specific key-prefix.- Parameters:
keyPrefix- key prefix, e.g. 'dispatcher_'- Returns:
- collected values
-
getInt
Get integer value.- Parameters:
key- key- Returns:
- integer value
-
getInt
Get integer value.- Parameters:
key- keydefaultVal- default value or default value if non-existent.- Returns:
- integer value
-
getIntNoWarn
Get integer value; no warning if value is not available.- Parameters:
key- key- Returns:
- integer value
-
getYesOrNo
Get yes (true) or no (false), or the default value if the configuration is missing.- Parameters:
key- keydefaultVal- default value- Returns:
- true or false
-
getYesOrNo
Get yes (true) or no (false), if the configuration is messed up false is returned.- Parameters:
key- key- Returns:
- true or false
-
getYesOrNoNoWarn
Get yes (true) or no (false), if the configuration is messed up false is returned. No warning if key is missing.- Parameters:
key- key- Returns:
- true or false
-
getDecodedString
Decode encrypted value, if it is encrypted by beetRoot standards! See 'encoder.sh'.- Parameters:
key- keyapp- secure application- Returns:
- encrypted value
- Throws:
UtilsException- if decoding fails
-
getAppRoles
App-roles for the simple role-management (1 role per user, stored in user table). Get web app roles.- Returns:
- web app roles
-
getSepValuesNoWarn
Get comma-separated values, e.g. 'a,b,c'. If the configuration is messed up an empty array is returned. No warning if key is missing.- Parameters:
key- key- Returns:
- values
-
getSepValues
Get comma-separated values, e.g. 'a,b,c'. If no values are found an empty array is returned.- Parameters:
key- key- Returns:
- values
-
getMimeTypes
Get allowed mime types.- Parameters:
key- mime type key- Returns:
- allowed mime types
-
getServletContext
public jakarta.servlet.ServletContext getServletContext()Get servlet context- Returns:
- servlet context or null
-
getServletName
Get servlet name if any (only in servlet context)- Returns:
- servlet name
-
getXMLModuleConfig
Get XML module root configuration. No resource paths!- Parameters:
xmlConfigFile- only the file name, path is concluded by ROOTPATH and cfg-directorymoduleName- module name- Returns:
- XML doc root
-
getXMLModuleConfigRelative
Get XML module root configuration. No resource paths!- Parameters:
xmlRelativePath- relative path that is concluded with ROOTPATHmoduleName- module name- Returns:
- XML doc root
-
getXMLModuleConfigWithFullPath
Get XML module root configuration. The given path can be a resource too, but make sure there are no mixed path separators, e.g. "/\"!- Parameters:
xmlConfigFilePath- the full configuration file pathmoduleName- module name- Returns:
- XML doc root
-