Class SystemHelper

java.lang.Object
org.codelibs.fess.helper.SystemHelper

public class SystemHelper extends Object
Helper class for system-level operations and utilities. This class provides methods for managing system properties, handling JSP files, normalizing configurations, and other system-related tasks.
  • Field Details

    • designJspFileNameMap

      protected final Map<String,String> designJspFileNameMap
      A map of design JSP file names.
    • forceStop

      protected final AtomicBoolean forceStop
      A flag to indicate if the system should be forcefully stopped.
    • langItemsCache

      protected com.google.common.cache.LoadingCache<String,List<Map<String,String>>> langItemsCache
      A cache for language items.
    • filterPathEncoding

      protected String filterPathEncoding
      The encoding for filtering paths.
    • supportedLanguages

      protected String[] supportedLanguages
      An array of supported language codes.
    • shutdownHookList

      protected List<Runnable> shutdownHookList
      A list of shutdown hooks to be executed on system shutdown.
    • previousClusterState

      protected AtomicInteger previousClusterState
      The previous state of the cluster.
    • version

      protected String version
      The version of the Fess application.
    • majorVersion

      protected int majorVersion
      The major version number.
    • minorVersion

      protected int minorVersion
      The minor version number.
    • productVersion

      protected String productVersion
      The product version string.
    • eolTime

      protected long eolTime
      The end-of-life timestamp for the application.
    • updateConfigListenerMap

      protected Map<String,Supplier<String>> updateConfigListenerMap
      A map of listeners for configuration updates.
    • waitingThreadNames

      protected Set<String> waitingThreadNames
      A set of names of threads that are currently waiting.
  • Constructor Details

    • SystemHelper

      public SystemHelper()
      Constructs a new system helper.
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes the SystemHelper. This method sets up system properties, caches, and other initial configurations.
    • parseProjectProperties

      protected void parseProjectProperties(Path propPath)
      Parses project properties from the given path.
      Parameters:
      propPath - The path to the project properties file.
      Throws:
      FessSystemException - if the properties file cannot be parsed.
    • destroy

      @PreDestroy public void destroy()
      Destroys the SystemHelper and executes shutdown hooks.
    • getUsername

      public String getUsername()
      Gets the username of the current user.
      Returns:
      The username, or "guest" if not logged in.
    • getRequestManager

      protected org.lastaflute.web.servlet.request.RequestManager getRequestManager()
      Gets the request manager.
      Returns:
      The request manager.
    • getCurrentTime

      public Date getCurrentTime()
      Gets the current time as a Date object.
      Returns:
      The current time.
    • getCurrentTimeAsLong

      public long getCurrentTimeAsLong()
      Gets the current time in milliseconds.
      Returns:
      The current time in milliseconds.
    • getCurrentTimeAsLocalDateTime

      public LocalDateTime getCurrentTimeAsLocalDateTime()
      Gets the current time as a LocalDateTime object.
      Returns:
      The current time.
    • getLogFilePath

      public String getLogFilePath()
      Gets the path to the log file.
      Returns:
      The log file path.
    • encodeUrlFilter

      public String encodeUrlFilter(String path)
      Encodes a URL path for filtering.
      Parameters:
      path - The path to encode.
      Returns:
      The encoded path.
    • normalizeConfigPath

      public String normalizeConfigPath(String path)
      Normalizes a configuration path.
      Parameters:
      path - The path to normalize.
      Returns:
      The normalized path.
    • getForumLink

      public String getForumLink()
      Gets the link to the Fess forum.
      Returns:
      The forum link.
    • getHelpLink

      public String getHelpLink(String name)
      Gets the help link for a specific page.
      Parameters:
      name - The name of the help page.
      Returns:
      The help link.
    • getHelpUrl

      protected String getHelpUrl(String url)
      Gets the help URL for a given base URL.
      Parameters:
      url - The base URL.
      Returns:
      The localized help URL.
    • getDefaultHelpLink

      protected String getDefaultHelpLink(String url)
      Gets the default help link for a given URL.
      Parameters:
      url - The URL.
      Returns:
      The default help link.
    • getInstallationLink

      public String getInstallationLink()
      Gets the resolved online help link for the installation guide.
      Returns:
      The localized installation help URL.
    • getEolLink

      public String getEolLink()
      Gets the resolved online help link for end-of-life information.
      Returns:
      The localized end-of-life help URL.
    • addDesignJspFileName

      public void addDesignJspFileName(String key, String value)
      Adds a design JSP file name to the map.
      Parameters:
      key - The key for the JSP file.
      value - The file name.
    • getDesignJspFileName

      public String getDesignJspFileName(String fileName)
      Gets the design JSP file name for a given key.
      Parameters:
      fileName - The key for the JSP file.
      Returns:
      The file name.
    • getDesignJspFileNames

      public org.codelibs.core.misc.Pair<String,String>[] getDesignJspFileNames()
      Gets an array of design JSP file names.
      Returns:
      An array of pairs of keys and file names.
    • refreshDesignJspFiles

      public List<Path> refreshDesignJspFiles()
      Refreshes the design JSP files for all virtual hosts.
      Returns:
      A list of paths to the refreshed files.
    • getDesignJspFile

      protected File getDesignJspFile(String path)
      Gets a design JSP file for a given path.
      Parameters:
      path - The path to the JSP file.
      Returns:
      The JSP file.
    • isForceStop

      public boolean isForceStop()
      Checks if the system is in a force-stop state.
      Returns:
      true if the system is force-stopping, false otherwise.
    • setForceStop

      public void setForceStop(boolean b)
      Sets the force-stop state of the system.
      Parameters:
      b - true to force-stop the system.
    • generateDocId

      public String generateDocId(Map<String,Object> map)
      Generates a document ID.
      Parameters:
      map - A map of data for the document.
      Returns:
      A unique document ID.
    • abbreviateLongText

      public String abbreviateLongText(String str)
      Abbreviates a long text string.
      Parameters:
      str - The string to abbreviate.
      Returns:
      The abbreviated string.
    • normalizeHtmlLang

      public String normalizeHtmlLang(String value)
      Normalizes an HTML language string.
      Parameters:
      value - The language string to normalize.
      Returns:
      The normalized language string.
    • normalizeLang

      public String normalizeLang(String value)
      Normalizes a language string.
      Parameters:
      value - The language string to normalize.
      Returns:
      The normalized language string.
    • getLanguageItems

      public List<Map<String,String>> getLanguageItems(Locale locale)
      Gets a list of language items for a given locale.
      Parameters:
      locale - The locale.
      Returns:
      A list of language items.
    • addShutdownHook

      public void addShutdownHook(Runnable hook)
      Adds a shutdown hook.
      Parameters:
      hook - The shutdown hook to add.
    • getHostname

      public String getHostname()
      Gets the hostname of the local machine.
      Returns:
      The hostname.
    • getInstanceId

      public String getInstanceId()
      Gets the instance ID for this Fess instance. Combines scheduler.target.name (if configured), hostname, and PID to ensure uniqueness across multiple JVMs on the same host.
      Returns:
      The instance ID.
    • setupAdminHtmlData

      public void setupAdminHtmlData(org.lastaflute.web.TypicalAction action, org.lastaflute.web.ruts.process.ActionRuntime runtime)
      Sets up administrative HTML data for a given action.
      Parameters:
      action - The action to set up data for.
      runtime - The action runtime.
    • isStorageEnabled

      public boolean isStorageEnabled(org.codelibs.fess.mylasta.direction.FessConfig fessConfig)
      Determines whether object storage is enabled for the given configuration. Storage is considered enabled when a bucket is configured and either a custom endpoint is set or the storage type is StorageType.GCS (which has an implicit default endpoint).
      Parameters:
      fessConfig - the configuration to inspect (may be null)
      Returns:
      true if storage is enabled, false otherwise
    • setupSearchHtmlData

      public void setupSearchHtmlData(org.lastaflute.web.TypicalAction action, org.lastaflute.web.ruts.process.ActionRuntime runtime)
      Sets up search HTML data for a given action.
      Parameters:
      action - The action to set up data for.
      runtime - The action runtime.
    • isEoled

      public boolean isEoled()
      Checks if the application has reached its end-of-life.
      Returns:
      true if the application is EOL, false otherwise.
    • isUserPermission

      public boolean isUserPermission(String permission)
      Checks if a permission string is a user permission.
      Parameters:
      permission - The permission string.
      Returns:
      true if it is a user permission, false otherwise.
    • getSearchRoleByUser

      public String getSearchRoleByUser(String name)
      Gets the search role for a given user.
      Parameters:
      name - The username.
      Returns:
      The search role.
    • getSearchRoleByGroup

      public String getSearchRoleByGroup(String name)
      Gets the search role for a given group.
      Parameters:
      name - The group name.
      Returns:
      The search role.
    • getSearchRoleByRole

      public String getSearchRoleByRole(String name)
      Gets the search role for a given role.
      Parameters:
      name - The role name.
      Returns:
      The search role.
    • createSearchRole

      protected String createSearchRole(String type, String name)
      Creates a search role string.
      Parameters:
      type - The type of the role.
      name - The name of the role.
      Returns:
      The search role string.
    • reloadConfiguration

      public void reloadConfiguration()
      Reloads the application configuration.
    • reloadConfiguration

      public void reloadConfiguration(boolean resetJobs)
      Reloads the application configuration.
      Parameters:
      resetJobs - true to reset scheduled jobs.
    • updateSystemProperties

      public void updateSystemProperties()
      Updates system properties from the application configuration.
    • updateConfiguration

      public String updateConfiguration()
      Updates the application configuration.
      Returns:
      A string containing the results of the update.
    • addUpdateConfigListener

      public void addUpdateConfigListener(String name, Supplier<String> listener)
      Adds a listener for configuration updates.
      Parameters:
      name - The name of the listener.
      listener - The listener to add.
    • isChangedClusterState

      public boolean isChangedClusterState(int status)
      Checks if the cluster state has changed.
      Parameters:
      status - The current cluster status.
      Returns:
      true if the state has changed, false otherwise.
    • createValidator

      public org.lastaflute.web.validation.ActionValidator<org.codelibs.fess.mylasta.action.FessMessages> createValidator(org.lastaflute.web.servlet.request.RequestManager requestManager, org.lastaflute.core.message.supplier.UserMessagesCreator<org.codelibs.fess.mylasta.action.FessMessages> messagesCreator, Class<?>[] runtimeGroups)
      Creates a new action validator.
      Parameters:
      requestManager - The request manager.
      messagesCreator - The messages creator.
      runtimeGroups - The runtime groups.
      Returns:
      A new action validator.
    • getRedirectResponseToLogin

      public org.lastaflute.web.response.HtmlResponse getRedirectResponseToLogin(org.lastaflute.web.response.HtmlResponse response)
      Gets the redirect response to the login page.
      Parameters:
      response - The original response.
      Returns:
      The redirect response.
    • getRedirectResponseToRoot

      public org.lastaflute.web.response.HtmlResponse getRedirectResponseToRoot(org.lastaflute.web.response.HtmlResponse response)
      Gets the redirect response to the root page.
      Parameters:
      response - The original response.
      Returns:
      The redirect response.
    • setLogLevel

      public void setLogLevel(String level)
      Sets the log level for the application.
      Parameters:
      level - The log level to set.
    • getLogLevel

      public String getLogLevel()
      Gets the current log level.
      Returns:
      The current log level.
    • setLlmLogLevel

      public void setLlmLogLevel(String level)
      Sets the log level for LLM-related packages.
      Parameters:
      level - the log level to set
    • getLlmLogLevel

      public String getLlmLogLevel()
      Returns the current log level for LLM-related packages.
      Returns:
      the LLM log level
    • createTempFile

      public File createTempFile(String prefix, String suffix)
      Creates a temporary file.
      Parameters:
      prefix - The prefix for the file name.
      suffix - The suffix for the file name.
      Returns:
      The created temporary file.
      Throws:
      org.codelibs.core.exception.IORuntimeException - if the file cannot be created.
    • calibrateCpuLoad

      public boolean calibrateCpuLoad()
      Calibrates the CPU load.
      Returns:
      true if the CPU load is within the acceptable range, false otherwise.
    • calibrateCpuLoad

      public boolean calibrateCpuLoad(long timeoutInMillis)
      Calibrates the CPU load with a timeout.
      Parameters:
      timeoutInMillis - The timeout in milliseconds.
      Returns:
      true if the CPU load is within the acceptable range, false otherwise.
    • waitForNoWaitingThreads

      public void waitForNoWaitingThreads()
      Waits for all waiting threads to complete.
    • getSystemCpuPercent

      protected short getSystemCpuPercent()
      Gets the system CPU usage percentage.
      Returns:
      The system CPU usage percentage.
    • currentSystemCpuPercent

      public short currentSystemCpuPercent()
      Gets the current system CPU usage percentage.
      Returns:
      The system CPU usage percentage.
    • getSearchEngineCpuPercent

      public short getSearchEngineCpuPercent()
      Gets the search engine CPU usage percentage.
      Returns:
      The search engine CPU usage percentage.
    • setSearchEngineCpuPercent

      public void setSearchEngineCpuPercent(short percent)
      Sets the search engine CPU usage percentage.
      Parameters:
      percent - The search engine CPU usage percentage.
    • getFilteredEnvMap

      public Map<String,String> getFilteredEnvMap(String keyPattern)
      Gets a map of filtered environment variables.
      Parameters:
      keyPattern - The pattern to filter environment variable keys.
      Returns:
      A map of filtered environment variables.
    • getEnvMap

      protected Map<String,String> getEnvMap()
      Gets a map of environment variables.
      Returns:
      A map of environment variables.
    • getVersion

      public String getVersion()
      Gets the version of the Fess application.
      Returns:
      The version string.
    • getMajorVersion

      public int getMajorVersion()
      Gets the major version number.
      Returns:
      The major version number.
    • getMinorVersion

      public int getMinorVersion()
      Gets the minor version number.
      Returns:
      The minor version number.
    • getProductVersion

      public String getProductVersion()
      Gets the product version string.
      Returns:
      The product version string.
    • setSystemCpuCheckInterval

      public void setSystemCpuCheckInterval(long systemCpuCheckInterval)
      Sets the interval for checking the system CPU load.
      Parameters:
      systemCpuCheckInterval - The interval in milliseconds.
    • validatePassword

      public String validatePassword(String password)
      Validates a password against configured password policy requirements.
      Parameters:
      password - The password to validate.
      Returns:
      An empty string if the password is valid, or an error key for the validation failure.
    • containsUppercase

      protected boolean containsUppercase(String password)
      Checks if the password contains at least one uppercase letter.
      Parameters:
      password - the password to check
      Returns:
      true if the password contains an uppercase letter, false otherwise
    • containsLowercase

      protected boolean containsLowercase(String password)
      Checks if the password contains at least one lowercase letter.
      Parameters:
      password - the password to check
      Returns:
      true if the password contains a lowercase letter, false otherwise
    • containsDigit

      protected boolean containsDigit(String password)
      Checks if the password contains at least one digit.
      Parameters:
      password - the password to check
      Returns:
      true if the password contains a digit, false otherwise
    • containsSpecialChar

      protected boolean containsSpecialChar(String password)
      Checks if the password contains at least one special character. A special character is defined as any character that is not a letter, digit, or whitespace.
      Parameters:
      password - the password to check
      Returns:
      true if the password contains a special character, false otherwise