Package org.codelibs.fess.helper
Class SystemHelper
java.lang.Object
org.codelibs.fess.helper.SystemHelper
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 Summary
FieldsModifier and TypeFieldDescriptionA map of design JSP file names.protected longThe end-of-life timestamp for the application.protected StringThe encoding for filtering paths.protected final AtomicBooleanA flag to indicate if the system should be forcefully stopped.A cache for language items.protected intThe major version number.protected intThe minor version number.protected AtomicIntegerThe previous state of the cluster.protected StringThe product version string.A list of shutdown hooks to be executed on system shutdown.protected String[]An array of supported language codes.A map of listeners for configuration updates.protected StringThe version of the Fess application.A set of names of threads that are currently waiting. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabbreviateLongText(String str) Abbreviates a long text string.voidaddDesignJspFileName(String key, String value) Adds a design JSP file name to the map.voidaddShutdownHook(Runnable hook) Adds a shutdown hook.voidaddUpdateConfigListener(String name, Supplier<String> listener) Adds a listener for configuration updates.booleanCalibrates the CPU load.booleancalibrateCpuLoad(long timeoutInMillis) Calibrates the CPU load with a timeout.protected booleancontainsDigit(String password) Checks if the password contains at least one digit.protected booleancontainsLowercase(String password) Checks if the password contains at least one lowercase letter.protected booleancontainsSpecialChar(String password) Checks if the password contains at least one special character.protected booleancontainsUppercase(String password) Checks if the password contains at least one uppercase letter.protected StringcreateSearchRole(String type, String name) Creates a search role string.createTempFile(String prefix, String suffix) Creates a temporary file.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.shortGets the current system CPU usage percentage.voiddestroy()Destroys the SystemHelper and executes shutdown hooks.encodeUrlFilter(String path) Encodes a URL path for filtering.generateDocId(Map<String, Object> map) Generates a document ID.Gets the current time as a Date object.Gets the current time as a LocalDateTime object.longGets the current time in milliseconds.protected StringgetDefaultHelpLink(String url) Gets the default help link for a given URL.protected FilegetDesignJspFile(String path) Gets a design JSP file for a given path.getDesignJspFileName(String fileName) Gets the design JSP file name for a given key.Gets an array of design JSP file names.Gets a map of environment variables.Gets the resolved online help link for end-of-life information.getFilteredEnvMap(String keyPattern) Gets a map of filtered environment variables.Gets the link to the Fess forum.getHelpLink(String name) Gets the help link for a specific page.protected StringgetHelpUrl(String url) Gets the help URL for a given base URL.Gets the hostname of the local machine.Gets the resolved online help link for the installation guide.Gets the instance ID for this Fess instance.getLanguageItems(Locale locale) Gets a list of language items for a given locale.Returns the current log level for LLM-related packages.Gets the path to the log file.Gets the current log level.intGets the major version number.intGets the minor version number.Gets the product version string.org.lastaflute.web.response.HtmlResponsegetRedirectResponseToLogin(org.lastaflute.web.response.HtmlResponse response) Gets the redirect response to the login page.org.lastaflute.web.response.HtmlResponsegetRedirectResponseToRoot(org.lastaflute.web.response.HtmlResponse response) Gets the redirect response to the root page.protected org.lastaflute.web.servlet.request.RequestManagerGets the request manager.shortGets the search engine CPU usage percentage.getSearchRoleByGroup(String name) Gets the search role for a given group.getSearchRoleByRole(String name) Gets the search role for a given role.getSearchRoleByUser(String name) Gets the search role for a given user.protected shortGets the system CPU usage percentage.Gets the username of the current user.Gets the version of the Fess application.voidinit()Initializes the SystemHelper.booleanisChangedClusterState(int status) Checks if the cluster state has changed.booleanisEoled()Checks if the application has reached its end-of-life.booleanChecks if the system is in a force-stop state.booleanisStorageEnabled(org.codelibs.fess.mylasta.direction.FessConfig fessConfig) Determines whether object storage is enabled for the given configuration.booleanisUserPermission(String permission) Checks if a permission string is a user permission.normalizeConfigPath(String path) Normalizes a configuration path.normalizeHtmlLang(String value) Normalizes an HTML language string.normalizeLang(String value) Normalizes a language string.protected voidparseProjectProperties(Path propPath) Parses project properties from the given path.Refreshes the design JSP files for all virtual hosts.voidReloads the application configuration.voidreloadConfiguration(boolean resetJobs) Reloads the application configuration.voidsetForceStop(boolean b) Sets the force-stop state of the system.voidsetLlmLogLevel(String level) Sets the log level for LLM-related packages.voidsetLogLevel(String level) Sets the log level for the application.voidsetSearchEngineCpuPercent(short percent) Sets the search engine CPU usage percentage.voidsetSystemCpuCheckInterval(long systemCpuCheckInterval) Sets the interval for checking the system CPU load.voidsetupAdminHtmlData(org.lastaflute.web.TypicalAction action, org.lastaflute.web.ruts.process.ActionRuntime runtime) Sets up administrative HTML data for a given action.voidsetupSearchHtmlData(org.lastaflute.web.TypicalAction action, org.lastaflute.web.ruts.process.ActionRuntime runtime) Sets up search HTML data for a given action.Updates the application configuration.voidUpdates system properties from the application configuration.validatePassword(String password) Validates a password against configured password policy requirements.voidWaits for all waiting threads to complete.
-
Field Details
-
designJspFileNameMap
A map of design JSP file names. -
forceStop
A flag to indicate if the system should be forcefully stopped. -
langItemsCache
A cache for language items. -
filterPathEncoding
The encoding for filtering paths. -
supportedLanguages
An array of supported language codes. -
shutdownHookList
A list of shutdown hooks to be executed on system shutdown. -
previousClusterState
The previous state of the cluster. -
version
The version of the Fess application. -
majorVersion
protected int majorVersionThe major version number. -
minorVersion
protected int minorVersionThe minor version number. -
productVersion
The product version string. -
eolTime
protected long eolTimeThe end-of-life timestamp for the application. -
updateConfigListenerMap
A map of listeners for configuration updates. -
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
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
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
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
Gets the current time as a LocalDateTime object.- Returns:
- The current time.
-
getLogFilePath
Gets the path to the log file.- Returns:
- The log file path.
-
encodeUrlFilter
Encodes a URL path for filtering.- Parameters:
path- The path to encode.- Returns:
- The encoded path.
-
normalizeConfigPath
Normalizes a configuration path.- Parameters:
path- The path to normalize.- Returns:
- The normalized path.
-
getForumLink
Gets the link to the Fess forum.- Returns:
- The forum link.
-
getHelpLink
Gets the help link for a specific page.- Parameters:
name- The name of the help page.- Returns:
- The help link.
-
getHelpUrl
Gets the help URL for a given base URL.- Parameters:
url- The base URL.- Returns:
- The localized help URL.
-
getDefaultHelpLink
Gets the default help link for a given URL.- Parameters:
url- The URL.- Returns:
- The default help link.
-
getInstallationLink
Gets the resolved online help link for the installation guide.- Returns:
- The localized installation help URL.
-
getEolLink
Gets the resolved online help link for end-of-life information.- Returns:
- The localized end-of-life help URL.
-
addDesignJspFileName
Adds a design JSP file name to the map.- Parameters:
key- The key for the JSP file.value- The file name.
-
getDesignJspFileName
Gets the design JSP file name for a given key.- Parameters:
fileName- The key for the JSP file.- Returns:
- The file name.
-
getDesignJspFileNames
Gets an array of design JSP file names.- Returns:
- An array of pairs of keys and file names.
-
refreshDesignJspFiles
Refreshes the design JSP files for all virtual hosts.- Returns:
- A list of paths to the refreshed files.
-
getDesignJspFile
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
Generates a document ID.- Parameters:
map- A map of data for the document.- Returns:
- A unique document ID.
-
abbreviateLongText
Abbreviates a long text string.- Parameters:
str- The string to abbreviate.- Returns:
- The abbreviated string.
-
normalizeHtmlLang
Normalizes an HTML language string.- Parameters:
value- The language string to normalize.- Returns:
- The normalized language string.
-
normalizeLang
Normalizes a language string.- Parameters:
value- The language string to normalize.- Returns:
- The normalized language string.
-
getLanguageItems
Gets a list of language items for a given locale.- Parameters:
locale- The locale.- Returns:
- A list of language items.
-
addShutdownHook
Adds a shutdown hook.- Parameters:
hook- The shutdown hook to add.
-
getHostname
Gets the hostname of the local machine.- Returns:
- The hostname.
-
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 isStorageType.GCS(which has an implicit default endpoint).- Parameters:
fessConfig- the configuration to inspect (may benull)- Returns:
trueif storage is enabled,falseotherwise
-
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
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
Gets the search role for a given user.- Parameters:
name- The username.- Returns:
- The search role.
-
getSearchRoleByGroup
Gets the search role for a given group.- Parameters:
name- The group name.- Returns:
- The search role.
-
getSearchRoleByRole
Gets the search role for a given role.- Parameters:
name- The role name.- Returns:
- The search role.
-
createSearchRole
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
Updates the application configuration.- Returns:
- A string containing the results of the update.
-
addUpdateConfigListener
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
Sets the log level for the application.- Parameters:
level- The log level to set.
-
getLogLevel
Gets the current log level.- Returns:
- The current log level.
-
setLlmLogLevel
Sets the log level for LLM-related packages.- Parameters:
level- the log level to set
-
getLlmLogLevel
Returns the current log level for LLM-related packages.- Returns:
- the LLM log level
-
createTempFile
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
Gets a map of filtered environment variables.- Parameters:
keyPattern- The pattern to filter environment variable keys.- Returns:
- A map of filtered environment variables.
-
getEnvMap
Gets a map of environment variables.- Returns:
- A map of environment variables.
-
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
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
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
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
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
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
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
-