Class ViewImportSupport


  • public class ViewImportSupport
    extends org.apache.velocity.tools.generic.ImportSupport

    Provides methods to import arbitrary local or remote resources as strings.

    Based on ImportSupport from the JSTL taglib by Shawn Bayern

    Since:
    VelocityTools 3.0
    Version:
    $Revision$ $Date$
    Author:
    Marino A. Jonsson, Claude Brisson
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected javax.servlet.ServletContext application  
      protected javax.servlet.http.HttpServletRequest request  
      protected javax.servlet.http.HttpServletResponse response  
      • Fields inherited from class org.apache.velocity.tools.generic.ImportSupport

        RESOURCE_KEY, URL_KEY, VALID_SCHEME_CHARS
      • Fields inherited from class org.apache.velocity.tools.generic.SafeConfig

        LOCK_CONFIG_KEY, log, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.io.Reader acquireLocalURLReader​(java.lang.String url)  
      protected java.lang.String acquireLocalURLString​(java.lang.String url)  
      protected java.io.Reader acquireRemoteURLReader​(java.lang.String url)  
      protected java.lang.String acquireRemoteURLString​(java.lang.String url)  
      protected void configure​(org.apache.velocity.tools.generic.ValueParser values)  
      protected java.net.URL getFileResource​(java.lang.String resource)  
      protected java.lang.String mergeQueryStrings​(java.lang.String url)
      Merge original parameters into the query string
      void setRequest​(javax.servlet.http.HttpServletRequest request)
      Sets the current HttpServletRequest.
      void setResponse​(javax.servlet.http.HttpServletResponse response)
      Sets the current HttpServletResponse.
      void setServletContext​(javax.servlet.ServletContext application)
      Sets the ServletContext.
      static java.lang.String stripSession​(java.lang.String url)
      Strips a servlet session ID from url.
      • Methods inherited from class org.apache.velocity.tools.generic.ImportSupport

        acquireReader, acquireString, getClasspathResource, getContentTypeAttribute, getProtocol, getResourceReader, getResourceString, isRemoteURL, setSafeMode
      • Methods inherited from class org.apache.velocity.tools.generic.SafeConfig

        configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig
      • Methods inherited from class java.lang.Object

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

      • application

        protected javax.servlet.ServletContext application
      • request

        protected javax.servlet.http.HttpServletRequest request
      • response

        protected javax.servlet.http.HttpServletResponse response
    • Constructor Detail

      • ViewImportSupport

        public ViewImportSupport()
    • Method Detail

      • configure

        protected void configure​(org.apache.velocity.tools.generic.ValueParser values)
        Overrides:
        configure in class org.apache.velocity.tools.generic.ImportSupport
      • setRequest

        public void setRequest​(javax.servlet.http.HttpServletRequest request)
        Sets the current HttpServletRequest. This is required for this tool to operate and will throw a NullPointerException if this is not set or is set to null.
        Parameters:
        request - servlet request
      • setResponse

        public void setResponse​(javax.servlet.http.HttpServletResponse response)
        Sets the current HttpServletResponse. This is required for this tool to operate and will throw a NullPointerException if this is not set or is set to null.
        Parameters:
        response - servlet response
      • setServletContext

        public void setServletContext​(javax.servlet.ServletContext application)
        Sets the ServletContext. This is required for this tool to operate and will throw a NullPointerException if this is not set or is set to null.
        Parameters:
        application - servlet context
      • acquireRemoteURLString

        protected java.lang.String acquireRemoteURLString​(java.lang.String url)
                                                   throws java.io.IOException
        Overrides:
        acquireRemoteURLString in class org.apache.velocity.tools.generic.ImportSupport
        Parameters:
        url - the remote URL resource to return as string
        Returns:
        the URL resource as string
        Throws:
        java.io.IOException - if thrown by underlying code
      • acquireLocalURLString

        protected java.lang.String acquireLocalURLString​(java.lang.String url)
                                                  throws java.io.IOException
        Overrides:
        acquireLocalURLString in class org.apache.velocity.tools.generic.ImportSupport
        Parameters:
        url - the local URL resource to return as string
        Returns:
        the URL resource as string
        Throws:
        java.io.IOException - if not allowed or if thrown by underlying code
      • acquireRemoteURLReader

        protected java.io.Reader acquireRemoteURLReader​(java.lang.String url)
                                                 throws java.io.IOException
        Overrides:
        acquireRemoteURLReader in class org.apache.velocity.tools.generic.ImportSupport
        Parameters:
        url - the URL to read
        Returns:
        a Reader for the InputStream created from the supplied URL
        Throws:
        java.io.IOException - if not allowed or thrown by underlying code
      • acquireLocalURLReader

        protected java.io.Reader acquireLocalURLReader​(java.lang.String url)
                                                throws java.io.IOException
        Overrides:
        acquireLocalURLReader in class org.apache.velocity.tools.generic.ImportSupport
        Parameters:
        url - the URL to read
        Returns:
        a Reader for the InputStream created from the supplied URL
        Throws:
        java.io.IOException - if thrown by underlying code
      • stripSession

        public static java.lang.String stripSession​(java.lang.String url)
        Strips a servlet session ID from url. The session ID is encoded as a URL "path parameter" beginning with "jsessionid=". We thus remove anything we find between ";jsessionid=" (inclusive) and either EOS or a subsequent ';' (exclusive).
        Parameters:
        url - the url to strip the session id from
        Returns:
        the stripped url
      • mergeQueryStrings

        protected java.lang.String mergeQueryStrings​(java.lang.String url)
        Merge original parameters into the query string
        Parameters:
        url - the url to include
        Returns:
        the merged url
      • getFileResource

        protected java.net.URL getFileResource​(java.lang.String resource)
                                        throws java.lang.Exception
        Overrides:
        getFileResource in class org.apache.velocity.tools.generic.ImportSupport
        Throws:
        java.lang.Exception