org.apache.velocity.tools.generic

## Class ImportSupport

- java.lang.Object
- - org.apache.velocity.tools.generic.SafeConfig
  - - org.apache.velocity.tools.generic.ImportSupport

Direct Known Subclasses:
  JsonTool

    @InvalidScope(value={"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
`protected static class` `ImportSupport.SafeClosingHttpURLConnectionReader`

### Field Summary

Fields
`static String` `RESOURCE_KEY` Configuration key for XmlTool and JsonTool, used to specify a local resource
`static String` `URL_KEY` Configuration key for ImportTool, XmlTool and JsonTool, used to specify a local or remote source URL
`protected static String` `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
`ImportSupport()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected Reader` `acquireLocalURLReader(String url)` Acquire a reader to a local URL - non applicable to the generic version of ImportSupport
`protected String` `acquireLocalURLString(String url)` Aquire the content of a local URL.
`Reader` `acquireReader(String url)` Acquire a reader to an URL
`protected Reader` `acquireRemoteURLReader(String url)` Acquire a reader to a remote URL
`protected String` `acquireRemoteURLString(String url)` Aquire the content of a remote URL.
`String` `acquireString(String url)`
`protected void` `configure(ValueParser values)` Configure import support
`protected URL` `getClasspathResource(String resource)` Classpath entry URL builder
`static String` `getContentTypeAttribute(String input, String name)` Get the value associated with a content-type attribute.
`protected URL` `getFileResource(String resource)` Overridable local file URL builder.
`static String` `getProtocol(String url)` Returns protocol, or null for a local URL
`Reader` `getResourceReader(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.
`String` `getResourceString(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 boolean` `isRemoteURL(String url)` Returns whether an URL is remote or local
`void` `setSafeMode(boolean safe)` Sets or clears safe mode

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

#### VALID_SCHEME_CHARS

    protected static final String VALID_SCHEME_CHARS

See Also:
  Constant Field Values

#### RESOURCE_KEY

    public static final 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 String URL_KEY

Configuration key for ImportTool, XmlTool and JsonTool, used to specify a local or remote source URL

See Also:
  Constant Field Values

### Constructor Detail

#### ImportSupport

    public ImportSupport()

### Method Detail

#### configure

    protected void configure(ValueParser values)

Configure import support

Overrides:
  `configure` in class `SafeConfig`
Parameters:
  `values` - configuration values

#### setSafeMode

    public void setSafeMode(boolean safe)

Sets or clears safe mode

Overrides:
  `setSafeMode` in class `SafeConfig`
Parameters:
  `safe` - flag value

#### acquireString

    public String acquireString(String url)
                         throws IOException

Parameters:
  `url` - the URL resource to return as string
Returns:
  the URL resource as string
Throws:
  `IOException` - if operation failed

#### acquireRemoteURLString

    protected String acquireRemoteURLString(String url)
                                     throws IOException

Aquire the content of a remote URL.

Parameters:
  `url` - remote URL
Returns:
  the URL resource as string
Throws:
  `IOException` - if operation failed

#### acquireLocalURLString

    protected String acquireLocalURLString(String url)
                                    throws IOException

Aquire the content of a local URL.

Parameters:
  `url` - local URL
Returns:
  the URL resource as string
Throws:
  `IOException` - if operation failed

#### acquireReader

    public Reader acquireReader(String url)
                         throws IOException

Acquire a reader to an URL

Parameters:
  `url` - the URL to read
Returns:
  a Reader for the InputStream created from the supplied URL
Throws:
  `IOException` - if operation failed

#### acquireRemoteURLReader

    protected Reader acquireRemoteURLReader(String url)
                                     throws IOException

Acquire a reader to a remote URL

Parameters:
  `url` - the URL to read
Returns:
  a Reader for the InputStream created from the supplied URL
Throws:
  `IOException` - if operation failed

#### acquireLocalURLReader

    protected Reader acquireLocalURLReader(String url)
                                    throws IOException

Acquire 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:
  `IOException` - if operation failed

#### isRemoteURL

    public static boolean isRemoteURL(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 String getProtocol(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 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 attributes
  `name` - the name of the content-type attribute
Returns:
  the value associated with a content-type attribute

#### getResourceString

    public String getResourceString(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 Reader getResourceReader(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 URL getFileResource(String resource)
                           throws Exception

Overridable local file URL builder.

Parameters:
  `resource` - the resource to read
Returns:
  the content of the resource
Throws:
  `Exception` - if operation failed

#### getClasspathResource

    protected URL getClasspathResource(String resource)
                                throws Exception

Classpath entry URL builder

Parameters:
  `resource` - the resource to read
Returns:
  the content of the resource
Throws:
  `Exception` - if operation failed