Class SSIMediator


  • public class SSIMediator
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String className
      Name of this class, used for variable name scoping.
      protected SSIConditionalState conditionalState
      State tracker for nested conditional directives.
      protected java.lang.String configErrMsg
      Current error message configuration.
      protected java.lang.String configSizeFmt
      Current size format configuration.
      protected java.lang.String configTimeFmt
      Current time format configuration.
      protected static java.lang.String DEFAULT_CONFIG_ERR_MSG
      Default error message displayed when a directive fails.
      protected static java.lang.String DEFAULT_CONFIG_SIZE_FMT
      Default size format (abbreviated).
      protected static java.lang.String DEFAULT_CONFIG_TIME_FMT
      Default time format string for date/time variables.
      protected static java.lang.String ENCODING_ENTITY
      Encoding constant for HTML entity encoding.
      protected static java.lang.String ENCODING_NONE
      Encoding constant for no encoding.
      protected static java.lang.String ENCODING_URL
      Encoding constant for URL encoding.
      protected int lastMatchCount
      Number of regex match groups from the last match operation.
      protected long lastModifiedDate
      Last modified date of the document being processed.
      protected SSIExternalResolver ssiExternalResolver
      External resolver for file and variable access.
      protected Strftime strftime
      Strftime 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 void clearMatchGroups()
      Clears all regex match group variables.
      protected java.lang.String encode​(java.lang.String value, java.lang.String encoding)
      Encodes the given value using the specified encoding type.
      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.
      SSIConditionalState getConditionalState()
      Returns the conditional state tracker for nested if/else/endif directives.
      java.lang.String getConfigErrMsg()
      Returns the current error message configuration.
      java.lang.String getConfigSizeFmt()
      Returns the current size format configuration.
      java.lang.String getConfigTimeFmt()
      Returns the current time format configuration.
      long getFileLastModified​(java.lang.String path, boolean virtual)
      Returns the last modified timestamp of the specified file.
      long getFileSize​(java.lang.String path, boolean virtual)
      Returns the size of the specified file in bytes.
      java.lang.String getFileText​(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.String getVariableValue​(java.lang.String variableName)
      Returns the value of the named variable with no encoding applied.
      java.lang.String getVariableValue​(java.lang.String variableName, java.lang.String encoding)
      Returns the value of the named variable with the specified encoding applied.
      protected boolean isNameReserved​(java.lang.String name)
      Checks whether the given variable name is reserved by this class.
      void log​(java.lang.String message)
      Logs a message without an associated throwable.
      void log​(java.lang.String message, java.lang.Throwable throwable)
      Logs a message with an associated throwable.
      protected void populateMatchGroups​(java.util.regex.Matcher matcher)
      Populates match group variables from the given regex matcher.
      void setConfigErrMsg​(java.lang.String configErrMsg)
      Sets the error message displayed when a directive fails.
      void setConfigSizeFmt​(java.lang.String configSizeFmt)
      Sets the size format for fsize output.
      void setConfigTimeFmt​(java.lang.String configTimeFmt)
      Sets the time format string for date/time variables.
      void setConfigTimeFmt​(java.lang.String configTimeFmt, boolean fromConstructor)
      Sets the time format string and updates date variables accordingly.
      protected void setDateVariables​(boolean fromConstructor)
      Updates the built-in date variables (DATE_GMT, DATE_LOCAL, LAST_MODIFIED).
      void setVariableValue​(java.lang.String variableName, java.lang.String variableValue)
      Sets the value of the named variable.
      java.lang.String substituteVariables​(java.lang.String val)
      Applies variable substitution to the specified String and returns the new resolved string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 access
        lastModifiedDate - 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 string
        fromConstructor - 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.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:
        java.io.IOException - if the file cannot be accessed
      • getFileLastModified

        public long getFileLastModified​(java.lang.String path,
                                        boolean virtual)
                                 throws java.io.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:
        java.io.IOException - if the file cannot be accessed
      • getFileText

        public java.lang.String getFileText​(java.lang.String path,
                                            boolean virtual)
                                     throws java.io.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:
        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 variable
        variableValue - 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 variable
        encoding - 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 format
        timeZone - 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 encode
        encoding - 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 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​(java.util.regex.Matcher matcher)
        Populates match group variables from the given regex matcher.
        Parameters:
        matcher - the regex matcher containing the groups