Class ImportSupport
- java.lang.Object
-
- org.apache.velocity.tools.generic.SafeConfig
-
- org.apache.velocity.tools.generic.ImportSupport
-
- Direct Known Subclasses:
JsonTool
@InvalidScope({"application","session","request"}) public class ImportSupport extends SafeConfig
Provides methods to import arbitrary local or remote resources as strings, generic version.
Based on ImportSupport from the JSTL taglib by Shawn Bayern
- Since:
- VelocityTools 3.0
- Version:
- $$
- Author:
- Marino A. Jonsson, Claude Brisson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classImportSupport.SafeClosingHttpURLConnectionReader
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringRESOURCE_KEYConfiguration key for XmlTool and JsonTool, used to specify a local resourcestatic java.lang.StringURL_KEYConfiguration key for ImportTool, XmlTool and JsonTool, used to specify a local or remote source URLprotected static java.lang.StringVALID_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 Description ImportSupport()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.io.ReaderacquireLocalURLReader(java.lang.String url)Acquire a reader to a local URL - non applicable to the generic version of ImportSupportprotected java.lang.StringacquireLocalURLString(java.lang.String url)Aquire the content of a local URL.java.io.ReaderacquireReader(java.lang.String url)Acquire a reader to an URLprotected java.io.ReaderacquireRemoteURLReader(java.lang.String url)Acquire a reader to a remote URLprotected java.lang.StringacquireRemoteURLString(java.lang.String url)Aquire the content of a remote URL.java.lang.StringacquireString(java.lang.String url)protected voidconfigure(ValueParser values)Configure import supportprotected java.net.URLgetClasspathResource(java.lang.String resource)Classpath entry URL builderstatic java.lang.StringgetContentTypeAttribute(java.lang.String input, java.lang.String name)Get the value associated with a content-type attribute.protected java.net.URLgetFileResource(java.lang.String resource)Overridable local file URL builder.static java.lang.StringgetProtocol(java.lang.String url)Returns protocol, or null for a local URLjava.io.ReadergetResourceReader(java.lang.String resource)Get a reader of a local resource, first trying with a file (or a webapp resource for the view flavor) then with a classpath entry.java.lang.StringgetResourceString(java.lang.String resource)Fetch a local resource, first trying with a file (or a webapp resource for the view flavor) then with a classpath entry.static booleanisRemoteURL(java.lang.String url)Returns whether an URL is remote or localvoidsetSafeMode(boolean safe)Sets or clears safe mode-
Methods inherited from class org.apache.velocity.tools.generic.SafeConfig
configure, getLog, initLogger, isConfigLocked, isSafeMode, setLockConfig
-
-
-
-
Field Detail
-
VALID_SCHEME_CHARS
protected static final java.lang.String VALID_SCHEME_CHARS
- See Also:
- Constant Field Values
-
RESOURCE_KEY
public static final java.lang.String RESOURCE_KEY
Configuration key for XmlTool and JsonTool, used to specify a local resource- See Also:
- Constant Field Values
-
URL_KEY
public static final java.lang.String URL_KEY
Configuration key for ImportTool, XmlTool and JsonTool, used to specify a local or remote source URL- See Also:
- Constant Field Values
-
-
Method Detail
-
configure
protected void configure(ValueParser values)
Configure import support- Overrides:
configurein classSafeConfig- Parameters:
values- configuration values
-
setSafeMode
public void setSafeMode(boolean safe)
Sets or clears safe mode- Overrides:
setSafeModein classSafeConfig- Parameters:
safe- flag value
-
acquireString
public java.lang.String acquireString(java.lang.String url) throws java.io.IOException- Parameters:
url- the URL resource to return as string- Returns:
- the URL resource as string
- Throws:
java.io.IOException- if operation failed
-
acquireRemoteURLString
protected java.lang.String acquireRemoteURLString(java.lang.String url) throws java.io.IOExceptionAquire the content of a remote URL.- Parameters:
url- remote URL- Returns:
- the URL resource as string
- Throws:
java.io.IOException- if operation failed
-
acquireLocalURLString
protected java.lang.String acquireLocalURLString(java.lang.String url) throws java.io.IOExceptionAquire the content of a local URL.- Parameters:
url- local URL- Returns:
- the URL resource as string
- Throws:
java.io.IOException- if operation failed
-
acquireReader
public java.io.Reader acquireReader(java.lang.String url) throws java.io.IOExceptionAcquire a reader to an URL- Parameters:
url- the URL to read- Returns:
- a Reader for the InputStream created from the supplied URL
- Throws:
java.io.IOException- if operation failed
-
acquireRemoteURLReader
protected java.io.Reader acquireRemoteURLReader(java.lang.String url) throws java.io.IOExceptionAcquire a reader to a remote URL- Parameters:
url- the URL to read- Returns:
- a Reader for the InputStream created from the supplied URL
- Throws:
java.io.IOException- if operation failed
-
acquireLocalURLReader
protected java.io.Reader acquireLocalURLReader(java.lang.String url) throws java.io.IOExceptionAcquire a reader to a local URL - non applicable to the generic version of ImportSupport- Parameters:
url- the URL to read- Returns:
- a Reader for the InputStream created from the supplied URL
- Throws:
java.io.IOException- if operation failed
-
isRemoteURL
public static boolean isRemoteURL(java.lang.String url)
Returns whether an URL is remote or local- Parameters:
url- the url to check out- Returns:
- wether the URL is remote
-
getProtocol
public static java.lang.String getProtocol(java.lang.String url)
Returns protocol, or null for a local URL- Parameters:
url- the url to check out- Returns:
- found protocol or null for a local 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 attributesname- the name of the content-type attribute- Returns:
- the value associated with a content-type attribute
-
getResourceString
public java.lang.String getResourceString(java.lang.String resource)
Fetch a local resource, first trying with a file (or a webapp resource for the view flavor) then with a classpath entry.- Parameters:
resource- the resource to read- Returns:
- the content of the resource
-
getResourceReader
public java.io.Reader getResourceReader(java.lang.String resource)
Get a reader of a local resource, first trying with a file (or a webapp resource for the view flavor) then with a classpath entry.- Parameters:
resource- the resource to read- Returns:
- a reader of the resource
-
getFileResource
protected java.net.URL getFileResource(java.lang.String resource) throws java.lang.ExceptionOverridable local file URL builder.- Parameters:
resource- the resource to read- Returns:
- the content of the resource
- Throws:
java.lang.Exception- if operation failed
-
getClasspathResource
protected java.net.URL getClasspathResource(java.lang.String resource) throws java.lang.ExceptionClasspath entry URL builder- Parameters:
resource- the resource to read- Returns:
- the content of the resource
- Throws:
java.lang.Exception- if operation failed
-
-