Class SSIProcessor


  • public class SSIProcessor
    extends java.lang.Object
    The entry point to SSI processing. This class does the actual parsing, delegating to the SSIMediator, SSICommand, and SSIExternalResolver as necessary.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean allowExec
      Whether exec commands are allowed.
      protected static java.lang.String COMMAND_END
      The end pattern
      protected static java.lang.String COMMAND_START
      The start pattern
      protected java.util.HashMap<java.lang.String,​SSICommand> commands
      Map of registered SSI command names to their handlers.
      protected int debug
      Debug level for SSI processing.
      protected SSIExternalResolver ssiExternalResolver
      External resolver for file and variable access.
    • Constructor Summary

      Constructors 
      Constructor Description
      SSIProcessor​(SSIExternalResolver ssiExternalResolver, int debug, boolean allowExec)
      Creates a new SSI processor with the given configuration.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addBuiltinCommands()
      Registers all built-in SSI commands.
      void addCommand​(java.lang.String name, SSICommand command)
      Registers a custom SSI command handler.
      protected boolean charCmp​(java.lang.String buf, int index, java.lang.String command)
      Compares a substring of the buffer with the given command string.
      protected boolean isQuote​(char c)
      Checks if the given character is a quote character.
      protected boolean isSpace​(char c)
      Checks if the given character is a whitespace character.
      protected java.lang.String[] parseParamNames​(java.lang.StringBuilder cmd, int start)
      Parse a StringBuilder and take out the param type token.
      protected java.lang.String[] parseParamValues​(java.lang.StringBuilder cmd, int start, int count)
      Parse a StringBuilder and take out the param token.
      long process​(java.io.Reader reader, long lastModifiedDate, java.io.PrintWriter writer)
      Process a file with server-side commands, reading from reader and writing the processed version to writer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COMMAND_START

        protected static final java.lang.String COMMAND_START
        The start pattern
        See Also:
        Constant Field Values
      • COMMAND_END

        protected static final java.lang.String COMMAND_END
        The end pattern
        See Also:
        Constant Field Values
      • ssiExternalResolver

        protected final SSIExternalResolver ssiExternalResolver
        External resolver for file and variable access.
      • commands

        protected final java.util.HashMap<java.lang.String,​SSICommand> commands
        Map of registered SSI command names to their handlers.
      • debug

        protected final int debug
        Debug level for SSI processing.
      • allowExec

        protected final boolean allowExec
        Whether exec commands are allowed.
    • Constructor Detail

      • SSIProcessor

        public SSIProcessor​(SSIExternalResolver ssiExternalResolver,
                            int debug,
                            boolean allowExec)
        Creates a new SSI processor with the given configuration.
        Parameters:
        ssiExternalResolver - the external resolver for file/variable access
        debug - the debug level
        allowExec - whether exec commands are allowed
    • Method Detail

      • addBuiltinCommands

        protected void addBuiltinCommands()
        Registers all built-in SSI commands.
      • addCommand

        public void addCommand​(java.lang.String name,
                               SSICommand command)
        Registers a custom SSI command handler.
        Parameters:
        name - the command name
        command - the command handler
      • process

        public long process​(java.io.Reader reader,
                            long lastModifiedDate,
                            java.io.PrintWriter writer)
                     throws java.io.IOException
        Process a file with server-side commands, reading from reader and writing the processed version to writer. NOTE: We really should be doing this in a streaming way rather than converting it to an array first.
        Parameters:
        reader - the reader to read the file containing SSIs from
        lastModifiedDate - resource last modification date
        writer - the writer to write the file with the SSIs processed.
        Returns:
        the most current modified date resulting from any SSI commands
        Throws:
        java.io.IOException - when things go horribly awry. Should be unlikely since the SSICommand usually catches 'normal' IOExceptions.
      • parseParamNames

        protected java.lang.String[] parseParamNames​(java.lang.StringBuilder cmd,
                                                     int start)
        Parse a StringBuilder and take out the param type token. Called from requestHandler
        Parameters:
        cmd - a value of type 'StringBuilder'
        start - index on which parsing will start
        Returns:
        an array with the parameter names
      • parseParamValues

        protected java.lang.String[] parseParamValues​(java.lang.StringBuilder cmd,
                                                      int start,
                                                      int count)
        Parse a StringBuilder and take out the param token. Called from requestHandler
        Parameters:
        cmd - a value of type 'StringBuilder'
        start - index on which parsing will start
        count - number of values which should be parsed
        Returns:
        an array with the parameter values
      • charCmp

        protected boolean charCmp​(java.lang.String buf,
                                  int index,
                                  java.lang.String command)
        Compares a substring of the buffer with the given command string.
        Parameters:
        buf - the buffer to search
        index - the starting index
        command - the command string to match
        Returns:
        true if the substring matches the command
      • isSpace

        protected boolean isSpace​(char c)
        Checks if the given character is a whitespace character.
        Parameters:
        c - the character to check
        Returns:
        true if the character is a space, tab, newline, or carriage return
      • isQuote

        protected boolean isQuote​(char c)
        Checks if the given character is a quote character.
        Parameters:
        c - the character to check
        Returns:
        true if the character is a single, double, or backtick quote