Class BeetRootConfigurationManager

java.lang.Object
ch.autumo.beetroot.BeetRootConfigurationManager

public class BeetRootConfigurationManager extends Object
Configuration manager.
  • Field Details

    • LOG

      protected static final org.slf4j.Logger LOG
    • appVersion

      public static String appVersion
      Application version.
    • isWithinDesktop

      protected boolean isWithinDesktop
  • Method Details

    • getInstance

      public static BeetRootConfigurationManager getInstance()
      Get configuration manager.
      Returns:
      manager
    • getAppVersion

      public static String 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

      public String updateProperty(String key, String value)
      Update or add a value to the internal properties.
      Parameters:
      key - key
      value - vane
      Returns:
      old value if any or null
    • initialize

      public void initialize(String relativePath) throws Exception
      Initialize with path 'ROOTPATH/<given-path-and-file>'. No resource paths!
      Parameters:
      relativePath - relative path
      Throws:
      Exception - exception
    • initialize

      public void initialize() throws Exception
      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 main initializeWithFullPath(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

      public void initializeWithFullPath(String configFilePath) throws Exception
      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

      public void initializeDesktop(String desktopCfgFile, String appName) throws Exception
      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

      public String getLanguage(String langCode)
      Get language.
      Parameters:
      langCode - language code
      Returns:
      full language name
    • getHtmlInputMapType

      public String getHtmlInputMapType(String columnName)
      Get HTML input map type.
      Parameters:
      columnName - column name
      Returns:
      HTML input map type or null
    • getHtmlInputMapPattern

      public String getHtmlInputMapPattern(String columnName)
      Get HTML input map pattern.
      Parameters:
      columnName - column name
      Returns:
      HTML input map pattern or null
    • getFullConfigBasePath

      public String getFullConfigBasePath()
      Returns the full base path, where the base configuration is.
      Returns:
      base path
    • getConfigFileName

      public String 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

      public String getRootPath()
      Get app root path.
      Returns:
      root path
    • getString

      public String getString(String key)
      Get a string value.
      Parameters:
      key - key
      Returns:
      string value
    • getString

      public String getString(String key, String defaultVal)
      Get a string value or default value if non-existent.
      Parameters:
      key - key
      defaultVal - default value
      Returns:
      string value
    • getStringNoWarn

      public String getStringNoWarn(String key)
      Get a string value; no warning if value is not available.
      Parameters:
      key - key
      Returns:
      string value
    • getKeys

      public String[] getKeys(String keyPrefix)
      Get all keys starting with a specific key-prefix.
      Parameters:
      keyPrefix - key prefix, e.g. 'dispatcher_'
      Returns:
      collected values
    • getValues

      public String[] getValues(String keyPrefix)
      Get all values starting with a specific key-prefix.
      Parameters:
      keyPrefix - key prefix, e.g. 'dispatcher_'
      Returns:
      collected values
    • getInt

      public int getInt(String key)
      Get integer value.
      Parameters:
      key - key
      Returns:
      integer value
    • getInt

      public int getInt(String key, int defaultVal)
      Get integer value.
      Parameters:
      key - key
      defaultVal - default value or default value if non-existent.
      Returns:
      integer value
    • getIntNoWarn

      public int getIntNoWarn(String key)
      Get integer value; no warning if value is not available.
      Parameters:
      key - key
      Returns:
      integer value
    • getYesOrNo

      public boolean getYesOrNo(String key, String defaultVal)
      Get yes (true) or no (false), or the default value if the configuration is missing.
      Parameters:
      key - key
      defaultVal - default value
      Returns:
      true or false
    • getYesOrNo

      public boolean getYesOrNo(String key)
      Get yes (true) or no (false), if the configuration is messed up false is returned.
      Parameters:
      key - key
      Returns:
      true or false
    • getYesOrNoNoWarn

      public boolean getYesOrNoNoWarn(String key)
      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

      public String getDecodedString(String key, SecureApplication app) throws UtilsException
      Decode encrypted value, if it is encrypted by beetRoot standards! See 'encoder.sh'.
      Parameters:
      key - key
      app - secure application
      Returns:
      encrypted value
      Throws:
      UtilsException - if decoding fails
    • getAppRoles

      public String[] 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

      public String[] getSepValuesNoWarn(String key)
      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

      public String[] getSepValues(String key)
      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

      public List<String> getMimeTypes(String key)
      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

      public String getServletName()
      Get servlet name if any (only in servlet context)
      Returns:
      servlet name
    • getXMLModuleConfig

      public Document getXMLModuleConfig(String xmlConfigFile, String moduleName)
      Get XML module root configuration. No resource paths!
      Parameters:
      xmlConfigFile - only the file name, path is concluded by ROOTPATH and cfg-directory
      moduleName - module name
      Returns:
      XML doc root
    • getXMLModuleConfigRelative

      public Document getXMLModuleConfigRelative(String xmlRelativePath, String moduleName)
      Get XML module root configuration. No resource paths!
      Parameters:
      xmlRelativePath - relative path that is concluded with ROOTPATH
      moduleName - module name
      Returns:
      XML doc root
    • getXMLModuleConfigWithFullPath

      public Document getXMLModuleConfigWithFullPath(String xmlConfigFilePath, String moduleName)
      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 path
      moduleName - module name
      Returns:
      XML doc root