Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.roller.presentation.velocity
Class DataSourceResourceLoader  view DataSourceResourceLoader download DataSourceResourceLoader.java

java.lang.Object
  extended byorg.apache.velocity.runtime.resource.loader.ResourceLoader
      extended byorg.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 $

Field Summary
private  javax.naming.InitialContext ctx
           
private  javax.sql.DataSource dataSource
           
private  java.lang.String dataSourceName
           
private  java.lang.String keyColumn
           
private  java.lang.String tableName
           
private  java.lang.String templateColumn
           
private  java.lang.String timestampColumn
           
 
Fields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
className, isCachingOn, modificationCheckInterval, rsvc
 
Constructor Summary
DataSourceResourceLoader()
           
 
Method Summary
private  void closeDbConnection(java.sql.Connection conn)
          Closes connection to the datasource
 long getLastModified(org.apache.velocity.runtime.resource.Resource resource)
          Get the last modified time of the InputStream source that was used to create the template.
 java.io.InputStream getResourceStream(java.lang.String name)
          Get an InputStream so that the Runtime can build a template with it.
 void init(org.apache.commons.collections.ExtendedProperties configuration)
          Initialize the template loader with a a resources class.
 boolean isSourceModified(org.apache.velocity.runtime.resource.Resource resource)
          Given a template, check to see if the source of InputStream has been modified.
private  java.sql.Connection openDbConnection()
          gets connection to the datasource specified through the configuration parameters.
private  java.sql.ResultSet readData(java.sql.Connection conn, java.lang.String columnNames, java.lang.String templateName)
          Reads the data from the datasource.
private  long readLastModified(org.apache.velocity.runtime.resource.Resource resource, java.lang.String i_operation)
          Fetches the last modification time of the resource
 
Methods inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
commonInit, getClassName, getModificationCheckInterval, isCachingOn, setCachingOn, setModificationCheckInterval
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Constructor Detail

DataSourceResourceLoader

public DataSourceResourceLoader()
Method Detail

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()