Package org.apache.velocity.tools.view
Class ImportSupport
- java.lang.Object
-
- org.apache.velocity.tools.view.ImportSupport
-
- Direct Known Subclasses:
ImportTool,TilesTool
public abstract class ImportSupport extends Object
Provides methods to import arbitrary local or remote resources as strings.
Based on ImportSupport from the JSTL taglib by Shawn Bayern
- Since:
- VelocityTools 2.0
- Version:
- $Revision$ $Date$
- Author:
- Marino A. Jonsson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classImportSupport.ImportResponseWrapperWraps responses to allow us to retrieve results as Strings.protected static classImportSupport.SafeClosingHttpURLConnectionReader
-
Field Summary
Fields Modifier and Type Field Description protected javax.servlet.ServletContextapplicationprotected static StringDEFAULT_ENCODINGDefault character encoding for response.protected org.apache.velocity.runtime.log.LogLOGprotected javax.servlet.http.HttpServletRequestrequestprotected javax.servlet.http.HttpServletResponseresponseprotected static StringVALID_SCHEME_CHARS
-
Constructor Summary
Constructors Constructor Description ImportSupport()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ReaderacquireReader(String url)protected StringacquireString(String url)static StringgetContentTypeAttribute(String input, String name)Get the value associated with a content-type attribute.static booleanisAbsoluteUrl(String url)Returns true if our current URL is absolute, false otherwise.voidsetLog(org.apache.velocity.runtime.log.Log log)voidsetRequest(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 StringstripSession(String url)Strips a servlet session ID from url.
-
-
-
Field Detail
-
VALID_SCHEME_CHARS
protected static final String VALID_SCHEME_CHARS
- See Also:
- Constant Field Values
-
DEFAULT_ENCODING
protected static final String DEFAULT_ENCODING
Default character encoding for response.- See Also:
- Constant Field Values
-
LOG
protected org.apache.velocity.runtime.log.Log LOG
-
application
protected javax.servlet.ServletContext application
-
request
protected javax.servlet.http.HttpServletRequest request
-
response
protected javax.servlet.http.HttpServletResponse response
-
-
Method Detail
-
setLog
public void setLog(org.apache.velocity.runtime.log.Log log)
-
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.
-
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.
-
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.
-
acquireString
protected String acquireString(String url) throws IOException, Exception
- Parameters:
url- the URL resource to return as string- Returns:
- the URL resource as string
- Throws:
IOExceptionException
-
acquireReader
protected Reader acquireReader(String url) throws IOException, Exception
- Parameters:
url- the URL to read- Returns:
- a Reader for the InputStream created from the supplied URL
- Throws:
IOExceptionException
-
isAbsoluteUrl
public static boolean isAbsoluteUrl(String url)
Returns true if our current URL is absolute, false otherwise.- Parameters:
url- the url to check out- Returns:
- true if the url is absolute
-
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
-
getContentTypeAttribute
public static String getContentTypeAttribute(String input, String name)
Get the value associated with a content-type attribute. Syntax defined in RFC 2045, section 5.1.- Parameters:
input- the string containing the attributesname- the name of the content-type attribute- Returns:
- the value associated with a content-type attribute
-
-