Class SSIMediator

java.lang.Object
org.apache.catalina.ssi.SSIMediator

public class SSIMediator extends Object
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 Details

    • ENCODING_NONE

      protected static final String ENCODING_NONE
      Encoding constant for no encoding.
      See Also:
    • ENCODING_ENTITY

      protected static final String ENCODING_ENTITY
      Encoding constant for HTML entity encoding.
      See Also:
    • ENCODING_URL

      protected static final String ENCODING_URL
      Encoding constant for URL encoding.
      See Also:
    • DEFAULT_CONFIG_ERR_MSG

      protected static final String DEFAULT_CONFIG_ERR_MSG
      Default error message displayed when a directive fails.
      See Also:
    • DEFAULT_CONFIG_TIME_FMT

      protected static final String DEFAULT_CONFIG_TIME_FMT
      Default time format string for date/time variables.
      See Also:
    • DEFAULT_CONFIG_SIZE_FMT

      protected static final String DEFAULT_CONFIG_SIZE_FMT
      Default size format (abbreviated).
      See Also:
    • configErrMsg

      protected String configErrMsg
      Current error message configuration.
    • configTimeFmt

      protected String configTimeFmt
      Current time format configuration.
    • configSizeFmt

      protected String configSizeFmt
      Current size format configuration.
    • className

      protected final 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 Details

    • 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 access
      lastModifiedDate - the last modified date of the document being processed
  • Method Details

    • setConfigErrMsg

      public void setConfigErrMsg(String configErrMsg)
      Sets the error message displayed when a directive fails.
      Parameters:
      configErrMsg - the error message to use
    • setConfigTimeFmt

      public void setConfigTimeFmt(String configTimeFmt)
      Sets the time format string for date/time variables.
      Parameters:
      configTimeFmt - the time format string
    • setConfigTimeFmt

      public void setConfigTimeFmt(String configTimeFmt, boolean fromConstructor)
      Sets the time format string and updates date variables accordingly.
      Parameters:
      configTimeFmt - the time format string
      fromConstructor - true if called from the constructor
    • setConfigSizeFmt

      public void setConfigSizeFmt(String configSizeFmt)
      Sets the size format for fsize output.
      Parameters:
      configSizeFmt - the size format string
    • getConfigErrMsg

      public String getConfigErrMsg()
      Returns the current error message configuration.
      Returns:
      the error message
    • getConfigTimeFmt

      public String getConfigTimeFmt()
      Returns the current time format configuration.
      Returns:
      the time format string
    • getConfigSizeFmt

      public 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 Collection<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(String path, boolean virtual) throws IOException
      Returns the size of the specified file in bytes.
      Parameters:
      path - the file path
      virtual - true for virtual path, false for physical path
      Returns:
      the file size in bytes
      Throws:
      IOException - if the file cannot be accessed
    • getFileLastModified

      public long getFileLastModified(String path, boolean virtual) throws IOException
      Returns the last modified timestamp of the specified file.
      Parameters:
      path - the file path
      virtual - true for virtual path, false for physical path
      Returns:
      the last modified time in milliseconds
      Throws:
      IOException - if the file cannot be accessed
    • getFileText

      public String getFileText(String path, boolean virtual) throws IOException
      Returns the text content of the specified file.
      Parameters:
      path - the file path
      virtual - true for virtual path, false for physical path
      Returns:
      the file content as a string
      Throws:
      IOException - if the file cannot be read
    • isNameReserved

      protected boolean isNameReserved(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 String getVariableValue(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(String variableName, String variableValue)
      Sets the value of the named variable. Reserved names cannot be set.
      Parameters:
      variableName - the name of the variable
      variableValue - the value to set, or null to remove
    • getVariableValue

      public String getVariableValue(String variableName, String encoding)
      Returns the value of the named variable with the specified encoding applied.
      Parameters:
      variableName - the name of the variable
      encoding - the encoding to apply (none, entity, url)
      Returns:
      the variable value, or null if not found
    • substituteVariables

      public String substituteVariables(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 String formatDate(Date date, TimeZone timeZone)
      Formats a date using the configured strftime pattern and the given time zone.
      Parameters:
      date - the date to format
      timeZone - the time zone to use, or null for the default
      Returns:
      the formatted date string
    • encode

      protected String encode(String value, String encoding)
      Encodes the given value using the specified encoding type.
      Parameters:
      value - the value to encode
      encoding - the encoding type (none, entity, url)
      Returns:
      the encoded value
    • log

      public void log(String message)
      Logs a message without an associated throwable.
      Parameters:
      message - the log message
    • log

      public void log(String message, Throwable throwable)
      Logs a message with an associated throwable.
      Parameters:
      message - the log message
      throwable - 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(Matcher matcher)
      Populates match group variables from the given regex matcher.
      Parameters:
      matcher - the regex matcher containing the groups