java.lang.Object
org.apache.velocity.runtime.resource.loader.ResourceLoader
org.roller.presentation.velocity.DataSourceResourceLoader
- public class DataSourceResourceLoader
- extends org.apache.velocity.runtime.resource.loader.ResourceLoader
This is a simple template file loader that loads templates
from a DataSource instead of plain files.
It can be configured with a datasource name, a table name,
id column (name), content column (the template body) and a
timestamp column (for last modification info).
Example configuration snippet for velocity.properties:
resource.loader.1.public.name = DataSource
resource.loader.1.description = Velocity DataSource Resource Loader
resource.loader.1.class = org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader
resource.loader.1.resource.datasource = jdbc/SomeDS
resource.loader.1.resource.table = template_table
resource.loader.1.resource.keycolumn = template_id
resource.loader.1.resource.templatecolumn = template_definition
resource.loader.1.resource.timestampcolumn = template_timestamp
resource.loader.1.cache = false
resource.loader.1.modificationCheckInterval = 60
- Version:
- $Id: DataSourceResourceLoader.java,v 1.2 2002/08/09 17:21:42 mraible Exp $
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
dataSourceName
private java.lang.String dataSourceName
tableName
private java.lang.String tableName
keyColumn
private java.lang.String keyColumn
templateColumn
private java.lang.String templateColumn
timestampColumn
private java.lang.String timestampColumn
ctx
private javax.naming.InitialContext ctx
dataSource
private javax.sql.DataSource dataSource
DataSourceResourceLoader
public DataSourceResourceLoader()
init
public void init(org.apache.commons.collections.ExtendedProperties configuration)
- Description copied from class:
org.apache.velocity.runtime.resource.loader.ResourceLoader
- Initialize the template loader with a
a resources class.
isSourceModified
public boolean isSourceModified(org.apache.velocity.runtime.resource.Resource resource)
- Description copied from class:
org.apache.velocity.runtime.resource.loader.ResourceLoader
- Given a template, check to see if the source of InputStream
has been modified.
getLastModified
public long getLastModified(org.apache.velocity.runtime.resource.Resource resource)
- Description copied from class:
org.apache.velocity.runtime.resource.loader.ResourceLoader
- Get the last modified time of the InputStream source
that was used to create the template. We need the template
here because we have to extract the name of the template
in order to locate the InputStream source.
getResourceStream
public java.io.InputStream getResourceStream(java.lang.String name)
throws org.apache.velocity.exception.ResourceNotFoundException
- Get an InputStream so that the Runtime can build a
template with it.
readLastModified
private long readLastModified(org.apache.velocity.runtime.resource.Resource resource,
java.lang.String i_operation)
- Fetches the last modification time of the resource
openDbConnection
private java.sql.Connection openDbConnection()
throws java.lang.Exception
- gets connection to the datasource specified through the configuration
parameters.
closeDbConnection
private void closeDbConnection(java.sql.Connection conn)
- Closes connection to the datasource
readData
private java.sql.ResultSet readData(java.sql.Connection conn,
java.lang.String columnNames,
java.lang.String templateName)
throws java.sql.SQLException
- Reads the data from the datasource. It simply does the following query :
SELECT columnNames FROM tableName WHERE keyColumn
= 'templateName'
where keyColumn is a class member set in init()