org.apache.velocity.tools.view

## 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 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

### Nested Class Summary

Nested Classes
`protected static class` `ViewImportSupport.ImportResponseWrapper` Wraps responses to allow us to retrieve results as Strings.
`protected static class` `ViewImportSupport.SafeClosingHttpURLConnectionReader`

### Field Summary

Fields
`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`

### Constructor Summary

Constructors
Constructor and Description
`ViewImportSupport()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected Reader` `acquireLocalURLReader(String url)`
`protected String` `acquireLocalURLString(String url)`
`protected Reader` `acquireRemoteURLReader(String url)`
`protected String` `acquireRemoteURLString(String url)`
`protected void` `configure(ValueParser values)`
`protected URL` `getFileResource(String resource)`
`protected String` `mergeQueryStrings(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 String` `stripSession(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(ValueParser values)

Overrides:
  `configure` in class `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 `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 `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 `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 `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 `ImportSupport`
Throws:
  `Exception`