Class ViewImportSupport

java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.ImportSupport
org.apache.velocity.tools.view.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 Details

    • application

      protected javax.servlet.ServletContext application
    • request

      protected javax.servlet.http.HttpServletRequest request
    • response

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

    • ViewImportSupport

      public ViewImportSupport()
  • Method Details

    • 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 String acquireRemoteURLString(String url) throws 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:
      IOException - if thrown by underlying code
    • acquireLocalURLString

      protected String acquireLocalURLString(String url) throws 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:
      IOException - if not allowed or if thrown by underlying code
    • acquireRemoteURLReader

      protected Reader acquireRemoteURLReader(String url) throws 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:
      IOException - if not allowed or thrown by underlying code
    • acquireLocalURLReader

      protected Reader acquireLocalURLReader(String url) throws 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:
      IOException - if thrown by underlying code
    • stripSession

      public static String stripSession(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 String mergeQueryStrings(String url)
      Merge original parameters into the query string
      Parameters:
      url - the url to include
      Returns:
      the merged url
    • getFileResource

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