|
EchoPoint 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object echopoint.template.SwitchedDataSource
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"
URLKit.locate(String, String, EchoInstance, Class)
Constructor Summary | |
SwitchedDataSource(java.lang.String fileDirectoryPrefix,
java.lang.String fileOrResourceName)
Constructs a SwitchedDataSource that
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(java.lang.String fileDirectoryPrefix,
java.lang.String fileOrResourceName,
nextapp.echo.EchoInstance echoInstance)
Constructs a SwitchedDataSource that
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.
|
|
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 :
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.
|
|
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 :
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.
|
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 |
Constructor Detail |
public SwitchedDataSource(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName) throws java.io.IOException
SwitchedDataSource
that
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)
fileDirectoryPrefix
- - the directory prefix to use when looking
initially for the File. May be null.fileOrResourceName
- - the file or class resource name to use.
java.io.IOException
java.io.UnsupportedEncodingException
Class.getResource(java.lang.String)
,
URLKit.locate(String, String, EchoInstance, Class)
public SwitchedDataSource(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName, nextapp.echo.EchoInstance echoInstance) throws java.io.IOException
SwitchedDataSource
that
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)
fileDirectoryPrefix
- - the directory prefix to use when looking
initially for the File. May be null.fileOrResourceName
- - the file or class resource name to use.echoInstance
- - the EchoInstance to retreive the ServletContext from. This
can be null, in which case ServletContext resource loading
will not be used.
java.io.IOException
java.io.UnsupportedEncodingException
Class.getResource(java.lang.String)
,
URLKit.locate(String, String, EchoInstance, Class)
public SwitchedDataSource(java.lang.String fileDirectoryPrefix, java.lang.String fileOrResourceName, java.lang.String encoding) throws java.io.IOException, java.io.UnsupportedEncodingException
SwitchedDataSource
that
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)
fileDirectoryPrefix
- - the directory prefix to use when looking
initially for the File. May be null.fileOrResourceName
- - the file or class resource name to use.encoding
- - the character encoding to use when reading the data
java.io.IOException
java.io.UnsupportedEncodingException
Class.getResource(java.lang.String)
,
URLKit.locate(String, String, EchoInstance, Class)
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
SwitchedDataSource
that
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)
fileDirectoryPrefix
- - the directory prefix to use when looking
initially for the File. May be null.fileOrResourceName
- - the file or class resource name to use.echoInstance
- - the EchoInstance to retreive the ServletContext from. This
can be null, in which case ServletContext resource loading
will not be used.encoding
- - the character encoding to use when reading the dataresourceClass
- - the class to use when loading the resource data via
Class.getResource(java.lang.String)
java.io.IOException
java.io.UnsupportedEncodingException
Class.getResource(java.lang.String)
,
URLKit.locate(String, String, EchoInstance, Class)
Method Detail |
public java.lang.String getCanonicalName()
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 null
if this Source is supposed
to be parsed each time. The canonical name would be something
like a filename or an URL.
getCanonicalName
in interface DataSource
DataSource.getCanonicalName()
public java.lang.String getCharacterEncoding()
DataSource
getCharacterEncoding
in interface DataSource
DataSource.getCharacterEncoding()
public java.io.Reader getInputReader() throws java.io.IOException
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 ..
getInputReader
in interface DataSource
java.io.IOException
DataSource.getInputReader()
public long lastModified()
DataSource
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.
lastModified
in interface DataSource
DataSource.lastModified()
|
EchoPoint 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |