Package org.apache.catalina.ssi
Class SSIMediator
- java.lang.Object
-
- org.apache.catalina.ssi.SSIMediator
-
public class SSIMediator extends java.lang.ObjectAllows 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
Fields Modifier and Type Field Description protected java.lang.StringclassNameName of this class, used for variable name scoping.protected SSIConditionalStateconditionalStateState tracker for nested conditional directives.protected java.lang.StringconfigErrMsgCurrent error message configuration.protected java.lang.StringconfigSizeFmtCurrent size format configuration.protected java.lang.StringconfigTimeFmtCurrent time format configuration.protected static java.lang.StringDEFAULT_CONFIG_ERR_MSGDefault error message displayed when a directive fails.protected static java.lang.StringDEFAULT_CONFIG_SIZE_FMTDefault size format (abbreviated).protected static java.lang.StringDEFAULT_CONFIG_TIME_FMTDefault time format string for date/time variables.protected static java.lang.StringENCODING_ENTITYEncoding constant for HTML entity encoding.protected static java.lang.StringENCODING_NONEEncoding constant for no encoding.protected static java.lang.StringENCODING_URLEncoding constant for URL encoding.protected intlastMatchCountNumber of regex match groups from the last match operation.protected longlastModifiedDateLast modified date of the document being processed.protected SSIExternalResolverssiExternalResolverExternal resolver for file and variable access.protected StrftimestrftimeStrftime formatter for date/time formatting.
-
Constructor Summary
Constructors Constructor Description SSIMediator(SSIExternalResolver ssiExternalResolver, long lastModifiedDate)Creates a new mediator with the given external resolver and document last modified date.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclearMatchGroups()Clears all regex match group variables.protected java.lang.Stringencode(java.lang.String value, java.lang.String encoding)Encodes the given value using the specified encoding type.protected java.lang.StringformatDate(java.util.Date date, java.util.TimeZone timeZone)Formats a date using the configured strftime pattern and the given time zone.SSIConditionalStategetConditionalState()Returns the conditional state tracker for nested if/else/endif directives.java.lang.StringgetConfigErrMsg()Returns the current error message configuration.java.lang.StringgetConfigSizeFmt()Returns the current size format configuration.java.lang.StringgetConfigTimeFmt()Returns the current time format configuration.longgetFileLastModified(java.lang.String path, boolean virtual)Returns the last modified timestamp of the specified file.longgetFileSize(java.lang.String path, boolean virtual)Returns the size of the specified file in bytes.java.lang.StringgetFileText(java.lang.String path, boolean virtual)Returns the text content of the specified file.java.util.Collection<java.lang.String>getVariableNames()Returns the collection of all available variable names, including built-in and external variables.java.lang.StringgetVariableValue(java.lang.String variableName)Returns the value of the named variable with no encoding applied.java.lang.StringgetVariableValue(java.lang.String variableName, java.lang.String encoding)Returns the value of the named variable with the specified encoding applied.protected booleanisNameReserved(java.lang.String name)Checks whether the given variable name is reserved by this class.voidlog(java.lang.String message)Logs a message without an associated throwable.voidlog(java.lang.String message, java.lang.Throwable throwable)Logs a message with an associated throwable.protected voidpopulateMatchGroups(java.util.regex.Matcher matcher)Populates match group variables from the given regex matcher.voidsetConfigErrMsg(java.lang.String configErrMsg)Sets the error message displayed when a directive fails.voidsetConfigSizeFmt(java.lang.String configSizeFmt)Sets the size format for fsize output.voidsetConfigTimeFmt(java.lang.String configTimeFmt)Sets the time format string for date/time variables.voidsetConfigTimeFmt(java.lang.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(java.lang.String variableName, java.lang.String variableValue)Sets the value of the named variable.java.lang.StringsubstituteVariables(java.lang.String val)Applies variable substitution to the specified String and returns the new resolved string.
-
-
-
Field Detail
-
ENCODING_NONE
protected static final java.lang.String ENCODING_NONE
Encoding constant for no encoding.- See Also:
- Constant Field Values
-
ENCODING_ENTITY
protected static final java.lang.String ENCODING_ENTITY
Encoding constant for HTML entity encoding.- See Also:
- Constant Field Values
-
ENCODING_URL
protected static final java.lang.String ENCODING_URL
Encoding constant for URL encoding.- See Also:
- Constant Field Values
-
DEFAULT_CONFIG_ERR_MSG
protected static final java.lang.String DEFAULT_CONFIG_ERR_MSG
Default error message displayed when a directive fails.- See Also:
- Constant Field Values
-
DEFAULT_CONFIG_TIME_FMT
protected static final java.lang.String DEFAULT_CONFIG_TIME_FMT
Default time format string for date/time variables.- See Also:
- Constant Field Values
-
DEFAULT_CONFIG_SIZE_FMT
protected static final java.lang.String DEFAULT_CONFIG_SIZE_FMT
Default size format (abbreviated).- See Also:
- Constant Field Values
-
configErrMsg
protected java.lang.String configErrMsg
Current error message configuration.
-
configTimeFmt
protected java.lang.String configTimeFmt
Current time format configuration.
-
configSizeFmt
protected java.lang.String configSizeFmt
Current size format configuration.
-
className
protected final java.lang.String className
Name of this class, used for variable name scoping.
-
ssiExternalResolver
protected final SSIExternalResolver ssiExternalResolver
External resolver for file and variable access.
-
lastModifiedDate
protected final long lastModifiedDate
Last modified date of the document being processed.
-
strftime
protected Strftime strftime
Strftime formatter for date/time formatting.
-
conditionalState
protected final SSIConditionalState conditionalState
State tracker for nested conditional directives.
-
lastMatchCount
protected int lastMatchCount
Number of regex match groups from the last match operation.
-
-
Constructor Detail
-
SSIMediator
public SSIMediator(SSIExternalResolver ssiExternalResolver, long lastModifiedDate)
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 Detail
-
setConfigErrMsg
public void setConfigErrMsg(java.lang.String configErrMsg)
Sets the error message displayed when a directive fails.- Parameters:
configErrMsg- the error message to use
-
setConfigTimeFmt
public void setConfigTimeFmt(java.lang.String configTimeFmt)
Sets the time format string for date/time variables.- Parameters:
configTimeFmt- the time format string
-
setConfigTimeFmt
public void setConfigTimeFmt(java.lang.String configTimeFmt, boolean fromConstructor)Sets the time format string and updates date variables accordingly.- Parameters:
configTimeFmt- the time format stringfromConstructor- true if called from the constructor
-
setConfigSizeFmt
public void setConfigSizeFmt(java.lang.String configSizeFmt)
Sets the size format for fsize output.- Parameters:
configSizeFmt- the size format string
-
getConfigErrMsg
public java.lang.String getConfigErrMsg()
Returns the current error message configuration.- Returns:
- the error message
-
getConfigTimeFmt
public java.lang.String getConfigTimeFmt()
Returns the current time format configuration.- Returns:
- the time format string
-
getConfigSizeFmt
public java.lang.String getConfigSizeFmt()
Returns the current size format configuration.- Returns:
- the size format string
-
getConditionalState
public SSIConditionalState getConditionalState()
Returns the conditional state tracker for nested if/else/endif directives.- Returns:
- the conditional state
-
getVariableNames
public java.util.Collection<java.lang.String> getVariableNames()
Returns the collection of all available variable names, including built-in and external variables.- Returns:
- the collection of variable names
-
getFileSize
public long getFileSize(java.lang.String path, boolean virtual) throws java.io.IOExceptionReturns 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:
java.io.IOException- if the file cannot be accessed
-
getFileLastModified
public long getFileLastModified(java.lang.String path, boolean virtual) throws java.io.IOExceptionReturns 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:
java.io.IOException- if the file cannot be accessed
-
getFileText
public java.lang.String getFileText(java.lang.String path, boolean virtual) throws java.io.IOExceptionReturns 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:
java.io.IOException- if the file cannot be read
-
isNameReserved
protected boolean isNameReserved(java.lang.String name)
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
public java.lang.String getVariableValue(java.lang.String variableName)
Returns the value of the named variable with no encoding applied.- Parameters:
variableName- the name of the variable- Returns:
- the variable value, or null if not found
-
setVariableValue
public void setVariableValue(java.lang.String variableName, java.lang.String variableValue)Sets the value of the named variable. Reserved names cannot be set.- Parameters:
variableName- the name of the variablevariableValue- the value to set, or null to remove
-
getVariableValue
public java.lang.String getVariableValue(java.lang.String variableName, java.lang.String encoding)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
public java.lang.String substituteVariables(java.lang.String val)
Applies variable substitution to the specified String and returns the new resolved string.- Parameters:
val- The value which should be checked- Returns:
- the value after variable substitution
-
formatDate
protected java.lang.String formatDate(java.util.Date date, java.util.TimeZone timeZone)Formats a date using the configured strftime pattern and the given time zone.- Parameters:
date- the date to formattimeZone- the time zone to use, or null for the default- Returns:
- the formatted date string
-
encode
protected java.lang.String encode(java.lang.String value, java.lang.String encoding)Encodes the given value using the specified encoding type.- Parameters:
value- the value to encodeencoding- the encoding type (none, entity, url)- Returns:
- the encoded value
-
log
public void log(java.lang.String message)
Logs a message without an associated throwable.- Parameters:
message- the log message
-
log
public void log(java.lang.String message, java.lang.Throwable throwable)Logs a message with an associated throwable.- Parameters:
message- the log messagethrowable- the associated throwable
-
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
protected void populateMatchGroups(java.util.regex.Matcher matcher)
Populates match group variables from the given regex matcher.- Parameters:
matcher- the regex matcher containing the groups
-
-