Class SSIMediator
java.lang.Object
org.apache.catalina.ssi.SSIMediator
Allows the different SSICommand implementations to share data/talk to each other.
Acts as the central hub for SSI processing, managing variables, configuration, and file access.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringName of this class, used for variable name scoping.protected final SSIConditionalStateState tracker for nested conditional directives.protected StringCurrent error message configuration.protected StringCurrent size format configuration.protected StringCurrent time format configuration.protected static final StringDefault error message displayed when a directive fails.protected static final StringDefault size format (abbreviated).protected static final StringDefault time format string for date/time variables.protected static final StringEncoding constant for HTML entity encoding.protected static final StringEncoding constant for no encoding.protected static final StringEncoding constant for URL encoding.protected intNumber of regex match groups from the last match operation.protected final longLast modified date of the document being processed.protected final SSIExternalResolverExternal resolver for file and variable access.protected StrftimeStrftime formatter for date/time formatting. -
Constructor Summary
ConstructorsConstructorDescriptionSSIMediator(SSIExternalResolver ssiExternalResolver, long lastModifiedDate) Creates a new mediator with the given external resolver and document last modified date. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidClears all regex match group variables.protected StringEncodes the given value using the specified encoding type.protected StringformatDate(Date date, TimeZone timeZone) Formats a date using the configured strftime pattern and the given time zone.Returns the conditional state tracker for nested if/else/endif directives.Returns the current error message configuration.Returns the current size format configuration.Returns the current time format configuration.longgetFileLastModified(String path, boolean virtual) Returns the last modified timestamp of the specified file.longgetFileSize(String path, boolean virtual) Returns the size of the specified file in bytes.getFileText(String path, boolean virtual) Returns the text content of the specified file.Returns the collection of all available variable names, including built-in and external variables.getVariableValue(String variableName) Returns the value of the named variable with no encoding applied.getVariableValue(String variableName, String encoding) Returns the value of the named variable with the specified encoding applied.protected booleanisNameReserved(String name) Checks whether the given variable name is reserved by this class.voidLogs a message without an associated throwable.voidLogs a message with an associated throwable.protected voidpopulateMatchGroups(Matcher matcher) Populates match group variables from the given regex matcher.voidsetConfigErrMsg(String configErrMsg) Sets the error message displayed when a directive fails.voidsetConfigSizeFmt(String configSizeFmt) Sets the size format for fsize output.voidsetConfigTimeFmt(String configTimeFmt) Sets the time format string for date/time variables.voidsetConfigTimeFmt(String configTimeFmt, boolean fromConstructor) Sets the time format string and updates date variables accordingly.protected voidsetDateVariables(boolean fromConstructor) Updates the built-in date variables (DATE_GMT, DATE_LOCAL, LAST_MODIFIED).voidsetVariableValue(String variableName, String variableValue) Sets the value of the named variable.Applies variable substitution to the specified String and returns the new resolved string.
-
Field Details
-
ENCODING_NONE
-
ENCODING_ENTITY
-
ENCODING_URL
-
DEFAULT_CONFIG_ERR_MSG
Default error message displayed when a directive fails.- See Also:
-
DEFAULT_CONFIG_TIME_FMT
Default time format string for date/time variables.- See Also:
-
DEFAULT_CONFIG_SIZE_FMT
-
configErrMsg
Current error message configuration. -
configTimeFmt
Current time format configuration. -
configSizeFmt
Current size format configuration. -
className
Name of this class, used for variable name scoping. -
ssiExternalResolver
External resolver for file and variable access. -
lastModifiedDate
protected final long lastModifiedDateLast modified date of the document being processed. -
strftime
Strftime formatter for date/time formatting. -
conditionalState
State tracker for nested conditional directives. -
lastMatchCount
protected int lastMatchCountNumber of regex match groups from the last match operation.
-
-
Constructor Details
-
SSIMediator
Creates a new mediator with the given external resolver and document last modified date.- Parameters:
ssiExternalResolver- the external resolver for file/variable accesslastModifiedDate- the last modified date of the document being processed
-
-
Method Details
-
setConfigErrMsg
Sets the error message displayed when a directive fails.- Parameters:
configErrMsg- the error message to use
-
setConfigTimeFmt
Sets the time format string for date/time variables.- Parameters:
configTimeFmt- the time format string
-
setConfigTimeFmt
Sets the time format string and updates date variables accordingly.- Parameters:
configTimeFmt- the time format stringfromConstructor- true if called from the constructor
-
setConfigSizeFmt
Sets the size format for fsize output.- Parameters:
configSizeFmt- the size format string
-
getConfigErrMsg
Returns the current error message configuration.- Returns:
- the error message
-
getConfigTimeFmt
Returns the current time format configuration.- Returns:
- the time format string
-
getConfigSizeFmt
Returns the current size format configuration.- Returns:
- the size format string
-
getConditionalState
Returns the conditional state tracker for nested if/else/endif directives.- Returns:
- the conditional state
-
getVariableNames
Returns the collection of all available variable names, including built-in and external variables.- Returns:
- the collection of variable names
-
getFileSize
Returns the size of the specified file in bytes.- Parameters:
path- the file pathvirtual- true for virtual path, false for physical path- Returns:
- the file size in bytes
- Throws:
IOException- if the file cannot be accessed
-
getFileLastModified
Returns the last modified timestamp of the specified file.- Parameters:
path- the file pathvirtual- true for virtual path, false for physical path- Returns:
- the last modified time in milliseconds
- Throws:
IOException- if the file cannot be accessed
-
getFileText
Returns the text content of the specified file.- Parameters:
path- the file pathvirtual- true for virtual path, false for physical path- Returns:
- the file content as a string
- Throws:
IOException- if the file cannot be read
-
isNameReserved
Checks whether the given variable name is reserved by this class.- Parameters:
name- the variable name to check- Returns:
- true if the name is reserved
-
getVariableValue
-
setVariableValue
-
getVariableValue
Returns the value of the named variable with the specified encoding applied.- Parameters:
variableName- the name of the variableencoding- the encoding to apply (none, entity, url)- Returns:
- the variable value, or null if not found
-
substituteVariables
-
formatDate
-
encode
-
log
Logs a message without an associated throwable.- Parameters:
message- the log message
-
log
-
setDateVariables
protected void setDateVariables(boolean fromConstructor) Updates the built-in date variables (DATE_GMT, DATE_LOCAL, LAST_MODIFIED).- Parameters:
fromConstructor- true if called from the constructor
-
clearMatchGroups
protected void clearMatchGroups()Clears all regex match group variables. -
populateMatchGroups
Populates match group variables from the given regex matcher.- Parameters:
matcher- the regex matcher containing the groups
-