Package 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 org.apache.velocity.tools.generic.ImportSupportProvides 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 Modifier and Type Class Description protected static classViewImportSupport.ImportResponseWrapperWraps responses to allow us to retrieve results as Strings.protected static classViewImportSupport.SafeClosingHttpURLConnectionReader
-
Field Summary
Fields Modifier and Type Field Description protected javax.servlet.ServletContextapplicationprotected javax.servlet.http.HttpServletRequestrequestprotected javax.servlet.http.HttpServletResponseresponse
-
Constructor Summary
Constructors Constructor Description ViewImportSupport()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.io.ReaderacquireLocalURLReader(java.lang.String url)protected java.lang.StringacquireLocalURLString(java.lang.String url)protected java.io.ReaderacquireRemoteURLReader(java.lang.String url)protected java.lang.StringacquireRemoteURLString(java.lang.String url)protected voidconfigure(org.apache.velocity.tools.generic.ValueParser values)protected java.net.URLgetFileResource(java.lang.String resource)protected java.lang.StringmergeQueryStrings(java.lang.String url)Merge original parameters into the query stringvoidsetRequest(javax.servlet.http.HttpServletRequest request)Sets the currentHttpServletRequest.voidsetResponse(javax.servlet.http.HttpServletResponse response)Sets the currentHttpServletResponse.voidsetServletContext(javax.servlet.ServletContext application)Sets theServletContext.static java.lang.StringstripSession(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
-
-
-
-
Method Detail
-
configure
protected void configure(org.apache.velocity.tools.generic.ValueParser values)
- Overrides:
configurein classorg.apache.velocity.tools.generic.ImportSupport
-
setRequest
public void setRequest(javax.servlet.http.HttpServletRequest request)
Sets the currentHttpServletRequest. This is required for this tool to operate and will throw a NullPointerException if this is not set or is set tonull.- Parameters:
request- servlet request
-
setResponse
public void setResponse(javax.servlet.http.HttpServletResponse response)
Sets the currentHttpServletResponse. This is required for this tool to operate and will throw a NullPointerException if this is not set or is set tonull.- Parameters:
response- servlet response
-
setServletContext
public void setServletContext(javax.servlet.ServletContext application)
Sets theServletContext. This is required for this tool to operate and will throw a NullPointerException if this is not set or is set tonull.- Parameters:
application- servlet context
-
acquireRemoteURLString
protected java.lang.String acquireRemoteURLString(java.lang.String url) throws java.io.IOException- Overrides:
acquireRemoteURLStringin classorg.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:
acquireLocalURLStringin classorg.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:
acquireRemoteURLReaderin classorg.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:
acquireLocalURLReaderin classorg.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:
getFileResourcein classorg.apache.velocity.tools.generic.ImportSupport- Throws:
java.lang.Exception
-
-