org.apache.velocity.tools.view
Class ImportSupport

java.lang.Object
  extended by org.apache.velocity.tools.view.ImportSupport
Direct Known Subclasses:
ImportTool, TilesTool

public abstract class ImportSupport
extends java.lang.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: 591088 $ $Date: 2007-11-01 10:11:41 -0700 (Thu, 01 Nov 2007) $
Author:
Marino A. Jonsson

Nested Class Summary
protected static class ImportSupport.ImportResponseWrapper
          Wraps responses to allow us to retrieve results as Strings.
protected static class ImportSupport.SafeClosingHttpURLConnectionReader
           
 
Field Summary
protected  javax.servlet.ServletContext application
           
protected static java.lang.String DEFAULT_ENCODING
          Default character encoding for response.
protected  org.apache.velocity.runtime.log.Log LOG
           
protected  javax.servlet.http.HttpServletRequest request
           
protected  javax.servlet.http.HttpServletResponse response
           
protected static java.lang.String VALID_SCHEME_CHARS
           
 
Constructor Summary
ImportSupport()
           
 
Method Summary
protected  java.io.Reader acquireReader(java.lang.String url)
           
protected  java.lang.String acquireString(java.lang.String url)
           
static java.lang.String getContentTypeAttribute(java.lang.String input, java.lang.String name)
          Get the value associated with a content-type attribute.
static boolean isAbsoluteUrl(java.lang.String url)
          Returns true if our current URL is absolute, false otherwise.
 void setLog(org.apache.velocity.runtime.log.Log log)
           
 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALID_SCHEME_CHARS

protected static final java.lang.String VALID_SCHEME_CHARS
See Also:
Constant Field Values

DEFAULT_ENCODING

protected static final java.lang.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
Constructor Detail

ImportSupport

public ImportSupport()
Method Detail

setLog

public void setLog(org.apache.velocity.runtime.log.Log log)

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.


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.


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.


acquireString

protected java.lang.String acquireString(java.lang.String url)
                                  throws java.io.IOException,
                                         java.lang.Exception
Parameters:
url - the URL resource to return as string
Returns:
the URL resource as string
Throws:
java.io.IOException
java.lang.Exception

acquireReader

protected java.io.Reader acquireReader(java.lang.String url)
                                throws java.io.IOException,
                                       java.lang.Exception
Parameters:
url - the URL to read
Returns:
a Reader for the InputStream created from the supplied URL
Throws:
java.io.IOException
java.lang.Exception

isAbsoluteUrl

public static boolean isAbsoluteUrl(java.lang.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 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

getContentTypeAttribute

public static java.lang.String getContentTypeAttribute(java.lang.String input,
                                                       java.lang.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 attributes
name - the name of the content-type attribute
Returns:
the value associated with a content-type attribute


Copyright (c) 2003-2007 Apache Software Foundation