|
|||||||||
| Home >> All >> echopoint >> [ template overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
echopoint.template
Class SwitchedDataSource

java.lang.Objectechopoint.template.SwitchedDataSource
- All Implemented Interfaces:
- DataSource
- public class SwitchedDataSource
- extends java.lang.Object
- implements DataSource
- extends java.lang.Object
SwitchedDataSource allows you to use a
3 step strategy for finding HTML template data.
Step 1:
This class will first look for the existence of a file and if it
exists then it will use it as the template data source. The file
name is defined as fileDirectoryPrefix + fileOrResourceName
Step 2:
Faling that, if you provide an EchoInstance, it will retrieve the
javax.servlet.ServletContext from the instance and attempt to
load it using javax.servlet.ServletContext.getResource(java.lang.String)
and the fileOrResourceName. This step allows you to
access resources in your web application that are not under a
class path directory.
Step 3:
If ServletContext.getResource() fails or the EchoIntance is null, it will then attempt to load the template data as a class resource via Class.getResource(java.lang.String).
This class is useful when moving between development and production. For example, in development your templates may reside in your web project source directory (probably under source control).
Then when you move to production, they will reside as class resources under the web application servlet context root directory or WEB-INF/classes directory of your web application.
This class will allow for easier template changes during development and testing and then use class loading in production.
You would use this class something like this :
In the above example theds = new SwitchedDataSource( "/java/myproject/finance/src", "/com/bankwest/templates/login.html", getEchoInstance()); template.setTemplate(ds);
SwitchedDataSource will
first look for the template data as a File in :
Then if this file cant be found it will load the template data as a ServletContext resource using the name :"/java/myproject/finance/src/com/bankwest/templates/login.html"
Finally if this files it will load the template data as a Class resource using the name :"/com/bankwest/templates/login.html"
"/com/bankwest/templates/login.html"
| Field Summary | |
private CachedFileDataSource |
cachedDS
|
| Constructor Summary | |
SwitchedDataSource(java.lang.String fileDirectoryPrefix,
java.lang.String fileOrResourceName)
Constructs a SwitchedDataSource that
locates the template data using the following strategy :
|
|
SwitchedDataSource(java.lang.String fileDirectoryPrefix,
java.lang.String fileOrResourceName,
nextapp.echo.EchoInstance echoInstance)
Constructs a SwitchedDataSource that
locates the template data using the following strategy :
|
|
SwitchedDataSource(java.lang.String fileDirectoryPrefix,
java.lang.String fileOrResourceName,
nextapp.echo.EchoInstance echoInstance,
java.lang.String encoding,
java.lang.Class resourceClass)
Constructs a SwitchedDataSource that
locates the template data using the following strategy :
|
|
SwitchedDataSource(java.lang.String fileDirectoryPrefix,
java.lang.String fileOrResourceName,
java.lang.String encoding)
Constructs a SwitchedDataSource that
locates the template data using the following strategy :
|
|
| Method Summary | |
java.lang.String |
getCanonicalName()
Returns a canonical name of this DataSource. |
java.lang.String |
getCharacterEncoding()
This returns the encoding of the DataSource. |
java.io.Reader |
getInputReader()
Gets an Reader of this DataSource. |
long |
lastModified()
Returns the time the content of this DataSource was last modified. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
cachedDS
private CachedFileDataSource cachedDS
| Constructor Detail |
SwitchedDataSource
public SwitchedDataSource(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName) throws java.io.IOException
- Constructs a
SwitchedDataSourcethat locates the template data using the following strategy :Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName'
Step 2 : failing that, it will a Class.getResource(fileOrResourceName)
SwitchedDataSource
public SwitchedDataSource(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName, nextapp.echo.EchoInstance echoInstance) throws java.io.IOException
- Constructs a
SwitchedDataSourcethat locates the template data using the following strategy :Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName'
Step 2 : failing that, it uses the EchoInstance to locate the URL via ServletContext.getResource(fileOrResourceName), if the EchoInstance is not null.
Step 3 : failing that, it will a Class.getResource(fileOrResourceName)
SwitchedDataSource
public SwitchedDataSource(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName, java.lang.String encoding) throws java.io.IOException, java.io.UnsupportedEncodingException
- Constructs a
SwitchedDataSourcethat locates the template data using the following strategy :Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName'
Step 2 : failing that, it uses the EchoInstance to locate the URL via ServletContext.getResource(fileOrResourceName), if the EchoInstance is not null.
Step 3 : failing that, it will a Class.getResource(fileOrResourceName)
SwitchedDataSource
public SwitchedDataSource(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName, nextapp.echo.EchoInstance echoInstance, java.lang.String encoding, java.lang.Class resourceClass) throws java.io.IOException, java.io.UnsupportedEncodingException
- Constructs a
SwitchedDataSourcethat locates the template data using the following strategy :Step 1 : Looks for a file called 'fileDirectoryPrefix + fileOrResourceName'
Step 2 : failing that, it uses the EchoInstance to locate the URL via ServletContext.getResource(fileOrResourceName), if the EchoInstance is not null.
Step 3 : failing that, it will a Class.getResource(fileOrResourceName)
| Method Detail |
getCanonicalName
public java.lang.String getCanonicalName()
- Description copied from interface:
DataSource - Returns a canonical name of this DataSource.
The name returned here is used to look up the parsing result of the internal caching, so it should differ for all different Sources :-) May return
nullif this Source is supposed to be parsed each time. The canonical name would be something like a filename or an URL.- Specified by:
getCanonicalNamein interfaceDataSource
getCharacterEncoding
public java.lang.String getCharacterEncoding()
- Description copied from interface:
DataSource - This returns the encoding of the DataSource. This should be used by the
DataSource when returning a localised Reader within getInputReader().
- Specified by:
getCharacterEncodingin interfaceDataSource
getInputReader
public java.io.Reader getInputReader() throws java.io.IOException
- Description copied from interface:
DataSource - Gets an Reader of this DataSource.
Note that this method may be called twice if the page has to be parsed first. So you probably have to implement a buffer if your underlying source is transient ..
- Specified by:
getInputReaderin interfaceDataSource
lastModified
public long lastModified()
- Description copied from interface:
DataSource - Returns the time the content of this DataSource
was last modified.
The return value is used to decide whether to reparse a Source or not. Reparsing is done if the value returned here differs from the value returned at the last processing time. This may not return a 'real' time, it needs just to be comparable to itself; so some sort of version counter would be perfect as well.
- Specified by:
lastModifiedin interfaceDataSource
|
|||||||||
| Home >> All >> echopoint >> [ template overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
echopoint.template.SwitchedDataSource