java.lang.Object
org.apache.velocity.runtime.resource.loader.ResourceLoader
org.roller.presentation.velocity.DatabaseResourceLoader
- public class DatabaseResourceLoader
- extends org.apache.velocity.runtime.resource.loader.ResourceLoader
This is a simple template file loader that loads templates
from a Database instead of plain files.
Dave Johnson: Modified to use a regular old JDBC connection
specified by driver class and connection URL.
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 =Database
resource.loader.1.description = Roller Database Resource Loader
resource.loader.1.class = org.roller.presentation.velocity.DatabaseResourceLoader
resource.loader.1.resource.jdbc_class = driver_class
resource.loader.1.resource.jdbc_url = connection_url
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: DatabaseResourceLoader.java,v 1.3 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 |
jdbcClass
private java.lang.String jdbcClass
jdbcUrl
private java.lang.String jdbcUrl
jdbcUser
private java.lang.String jdbcUser
jdbcPassword
private java.lang.String jdbcPassword
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
DatabaseResourceLoader
public DatabaseResourceLoader()
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()