Class SSIServletExternalResolver

  • All Implemented Interfaces:
    SSIExternalResolver

    public class SSIServletExternalResolver
    extends java.lang.Object
    implements SSIExternalResolver
    An implementation of SSIExternalResolver that is used with servlets.
    • Field Detail

      • VARIABLE_NAMES

        protected final java.lang.String[] VARIABLE_NAMES
        Standard CGI variable names exposed to SSI.
      • context

        protected final ServletContext context
        The servlet context for resource access.
      • isVirtualWebappRelative

        protected final boolean isVirtualWebappRelative
        Whether virtual paths are relative to the webapp.
      • debug

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

        protected final java.lang.String inputEncoding
        Character encoding for included file content.
    • Constructor Detail

      • SSIServletExternalResolver

        public SSIServletExternalResolver​(ServletContext context,
                                          HttpServletRequest req,
                                          HttpServletResponse res,
                                          boolean isVirtualWebappRelative,
                                          int debug,
                                          java.lang.String inputEncoding)
        Constructor.
        Parameters:
        context - the servlet context
        req - the HTTP servlet request
        res - the HTTP servlet response
        isVirtualWebappRelative - whether virtual paths are relative to the webapp
        debug - debug level
        inputEncoding - character encoding for included file content
    • Method Detail

      • log

        public void log​(java.lang.String message,
                        java.lang.Throwable throwable)
        Log a message with an optional throwable.
        Specified by:
        log in interface SSIExternalResolver
        Parameters:
        message - the message to log
        throwable - the optional throwable
      • addVariableNames

        public void addVariableNames​(java.util.Collection<java.lang.String> variableNames)
        Add standard CGI variable names to the given collection.
        Specified by:
        addVariableNames in interface SSIExternalResolver
        Parameters:
        variableNames - the collection to add variable names to
      • getReqAttributeIgnoreCase

        protected java.lang.Object getReqAttributeIgnoreCase​(java.lang.String targetName)
        Get a request attribute by name, case-insensitive.
        Parameters:
        targetName - the attribute name
        Returns:
        the attribute value or null
      • isNameReserved

        protected boolean isNameReserved​(java.lang.String name)
        Check if a name is reserved (java., javax., sun., jakarta., org.apache.catalina. and org.apache.tomcat. prefixes).
        Parameters:
        name - the name to check
        Returns:
        true if the name is reserved
      • setVariableValue

        public void setVariableValue​(java.lang.String name,
                                     java.lang.String value)
        Set an SSI variable value as a request attribute.
        Specified by:
        setVariableValue in interface SSIExternalResolver
        Parameters:
        name - the variable name
        value - the variable value
      • getVariableValue

        public java.lang.String getVariableValue​(java.lang.String name)
        Get the value of an SSI variable.
        Specified by:
        getVariableValue in interface SSIExternalResolver
        Parameters:
        name - the variable name
        Returns:
        the variable value or null
      • getCGIVariable

        protected java.lang.String getCGIVariable​(java.lang.String name)
        Get the value of a CGI variable by name.
        Parameters:
        name - the CGI variable name
        Returns:
        the variable value or null
      • getCurrentDate

        public java.util.Date getCurrentDate()
        Get the current date.
        Specified by:
        getCurrentDate in interface SSIExternalResolver
        Returns:
        the current date
      • nullToEmptyString

        protected java.lang.String nullToEmptyString​(java.lang.String string)
        Convert null to an empty string.
        Parameters:
        string - the input string
        Returns:
        the string or empty string if null
      • getPathWithoutFileName

        protected java.lang.String getPathWithoutFileName​(java.lang.String servletPath)
        Get the path portion without the file name.
        Parameters:
        servletPath - the servlet path
        Returns:
        the path without file name or null
      • getPathWithoutContext

        protected java.lang.String getPathWithoutContext​(java.lang.String contextPath,
                                                         java.lang.String servletPath)
        Remove the context path prefix from a servlet path.
        Parameters:
        contextPath - the context path
        servletPath - the servlet path
        Returns:
        the path without context prefix
      • getAbsolutePath

        protected java.lang.String getAbsolutePath​(java.lang.String path)
                                            throws java.io.IOException
        Resolve a relative path to an absolute normalized path.
        Parameters:
        path - the relative path
        Returns:
        the absolute normalized path
        Throws:
        java.io.IOException - if path normalization fails
      • getServletContextAndPathFromNonVirtualPath

        protected SSIServletExternalResolver.ServletContextAndPath getServletContextAndPathFromNonVirtualPath​(java.lang.String nonVirtualPath)
                                                                                                       throws java.io.IOException
        Resolve a non-virtual (relative) path to a servlet context and path.
        Parameters:
        nonVirtualPath - the non-virtual path
        Returns:
        the servlet context and resolved path
        Throws:
        java.io.IOException - if the path is invalid
      • getServletContextAndPathFromVirtualPath

        protected SSIServletExternalResolver.ServletContextAndPath getServletContextAndPathFromVirtualPath​(java.lang.String virtualPath)
                                                                                                    throws java.io.IOException
        Resolve a virtual path to a servlet context and path.
        Parameters:
        virtualPath - the virtual path
        Returns:
        the servlet context and resolved path
        Throws:
        java.io.IOException - if the path cannot be resolved
      • isRootContext

        protected boolean isRootContext​(ServletContext servletContext)
        Check if the given servlet context is the root context.
        Parameters:
        servletContext - the servlet context
        Returns:
        true if the context is the root
      • getServletContextAndPath

        protected SSIServletExternalResolver.ServletContextAndPath getServletContextAndPath​(java.lang.String originalPath,
                                                                                            boolean virtual)
                                                                                     throws java.io.IOException
        Resolve a path to a servlet context and path.
        Parameters:
        originalPath - the original path
        virtual - whether the path is virtual
        Returns:
        the servlet context and resolved path
        Throws:
        java.io.IOException - if the path cannot be resolved
      • getURLConnection

        protected java.net.URLConnection getURLConnection​(java.lang.String originalPath,
                                                          boolean virtual)
                                                   throws java.io.IOException
        Get a URL connection for the given path.
        Parameters:
        originalPath - the original path
        virtual - whether the path is virtual
        Returns:
        the URL connection
        Throws:
        java.io.IOException - if the resource is not found
      • getFileLastModified

        public long getFileLastModified​(java.lang.String path,
                                        boolean virtual)
                                 throws java.io.IOException
        Get the last modified time of a file.
        Specified by:
        getFileLastModified in interface SSIExternalResolver
        Parameters:
        path - the file path
        virtual - whether the path is virtual
        Returns:
        the last modified time in milliseconds
        Throws:
        java.io.IOException - if the file cannot be accessed
      • getFileSize

        public long getFileSize​(java.lang.String path,
                                boolean virtual)
                         throws java.io.IOException
        Get the size of a file.
        Specified by:
        getFileSize in interface SSIExternalResolver
        Parameters:
        path - the file path
        virtual - whether the path is virtual
        Returns:
        the file size in bytes or -1 if unknown
        Throws:
        java.io.IOException - if the file cannot be accessed
      • getFileText

        public java.lang.String getFileText​(java.lang.String originalPath,
                                            boolean virtual)
                                     throws java.io.IOException
        Get the text content of a file.
        Specified by:
        getFileText in interface SSIExternalResolver
        Parameters:
        originalPath - the original file path
        virtual - whether the path is virtual
        Returns:
        the file content as text
        Throws:
        java.io.IOException - if the file cannot be read