org.onemind.jxp
Class CachingPageSource

java.lang.Object
  extended by org.onemind.jxp.JxpPageSource
      extended by org.onemind.jxp.CachingPageSource
Direct Known Subclasses:
ByteArrayPageSource, FilePageSource, ResourceStreamPageSource

public abstract class CachingPageSource
extends JxpPageSource

A caching page source will cache the page source

Author:
TiongHiang Lee (thlee@onemindsoft.org)

Field Summary
private  boolean _caching
          flag to turn caching on/off *
private  java.lang.String _encoding
          the encoding
private  boolean _invalidateCacheOnParseError
          whether invalidate the cache on parse error *
private  org.onemind.commons.java.datastructure.MruMap _pageCache
          the cache *
private  java.util.HashMap _pageStaticVariables
          the page static variables
 
Constructor Summary
CachingPageSource()
          Constructor (default use 200 cache limit, unlimit timeout)
CachingPageSource(int cacheSize)
          Constructor
CachingPageSource(int cacheSize, int timeout)
          Constructor
 
Method Summary
(package private)  java.lang.Object assignPageStaticVariable(CachedJxpPage page, java.lang.String name, java.lang.Object value)
           
(package private)  java.lang.Object declarePageStaticVariable(JxpPage page, java.lang.String name, java.lang.Object value)
          Declare a page static variable
 java.lang.String getEncoding()
          Return the encoding
 java.lang.StringBuffer getErrorSource(JxpPage page, int line, int col)
          Print the error source of this page on given line and column
 AstJxpDocument getJxpDocument(JxpPage page)
          Get the jxp document for the JxpPage
 JxpPage getJxpPage(java.lang.String id)
          Return a jxp page identified by the id
(package private)  java.lang.Object getPageStaticVariable(JxpPage page, java.lang.String name)
          Get the page static variable
 boolean hasJxpPage(java.lang.String id)
          Return whether the jxp page identified by the id exists
(package private)  boolean hasPageStaticVariable(JxpPage page, java.lang.String name)
          Return whether there's a variable declared
protected abstract  boolean hasStream(java.lang.String pageName)
          Whether there's input stream from given page name
protected  void invalidatePageCache(JxpPage page)
          Invalidate the page cache
 boolean isCaching()
          Return whether this is doing caching
protected abstract  boolean isExpired(CachedJxpPage page)
          Whether a page is expired
 boolean isJxpPageCached(java.lang.String id)
          Whehter the page identified by id is cached
protected abstract  java.io.InputStream loadStream(CachedJxpPage page)
          Load the input stream for the page
protected  void purgeStaticVariables(CachedJxpPage page)
          Purge the static variables for a page
 void setCaching(boolean b)
          Set caching on/off
 void setEncoding(java.lang.String encoding)
          Set the encoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_pageCache

private org.onemind.commons.java.datastructure.MruMap _pageCache
the cache *


_caching

private boolean _caching
flag to turn caching on/off *


_invalidateCacheOnParseError

private boolean _invalidateCacheOnParseError
whether invalidate the cache on parse error *


_pageStaticVariables

private java.util.HashMap _pageStaticVariables
the page static variables


_encoding

private java.lang.String _encoding
the encoding

Constructor Detail

CachingPageSource

public CachingPageSource()
Constructor (default use 200 cache limit, unlimit timeout)


CachingPageSource

public CachingPageSource(int cacheSize)
Constructor

Parameters:
cacheSize - The default cache size

CachingPageSource

public CachingPageSource(int cacheSize,
                         int timeout)
Constructor

Parameters:
cacheSize - The default cache size
timeout - time to expire inactive cache
Method Detail

getJxpPage

public final JxpPage getJxpPage(java.lang.String id)
                         throws JxpPageNotFoundException
Return a jxp page identified by the id

Specified by:
getJxpPage in class JxpPageSource
Parameters:
id - the id
Returns:
the jxp page
Throws:
JxpPageNotFoundException - if the page cannot be found

invalidatePageCache

protected final void invalidatePageCache(JxpPage page)
Invalidate the page cache

Parameters:
page - the page

isCaching

public final boolean isCaching()
Return whether this is doing caching

Returns:
true if caching

setCaching

public final void setCaching(boolean b)
Set caching on/off

Parameters:
b - true if caching on

getJxpDocument

public final AstJxpDocument getJxpDocument(JxpPage page)
                                    throws JxpPageParseException
Get the jxp document for the JxpPage

Specified by:
getJxpDocument in class JxpPageSource
Parameters:
page - the JxpPage
Returns:
the AstJxpDocument
Throws:
JxpPageParseException

isExpired

protected abstract boolean isExpired(CachedJxpPage page)
Whether a page is expired

Parameters:
page - the page
Returns:
true if expired

hasStream

protected abstract boolean hasStream(java.lang.String pageName)
Whether there's input stream from given page name

Parameters:
pageName - the page name
Returns:
true if has input stream

loadStream

protected abstract java.io.InputStream loadStream(CachedJxpPage page)
                                           throws java.io.IOException
Load the input stream for the page

Parameters:
pageName - the page
Returns:
the input stream
Throws:
java.io.IOException

isJxpPageCached

public final boolean isJxpPageCached(java.lang.String id)
Whehter the page identified by id is cached

Parameters:
id - the id
Returns:
true if cached

declarePageStaticVariable

final java.lang.Object declarePageStaticVariable(JxpPage page,
                                                 java.lang.String name,
                                                 java.lang.Object value)
Declare a page static variable

Parameters:
page - the page
name - the name
value - the value

hasPageStaticVariable

final boolean hasPageStaticVariable(JxpPage page,
                                    java.lang.String name)
Return whether there's a variable declared

Parameters:
page - the page
name - the name
Returns:
true if declared

getPageStaticVariable

final java.lang.Object getPageStaticVariable(JxpPage page,
                                             java.lang.String name)
Get the page static variable

Parameters:
page - the page
name - the nama
Returns:
the value

getErrorSource

public java.lang.StringBuffer getErrorSource(JxpPage page,
                                             int line,
                                             int col)
                                      throws java.io.IOException
Print the error source of this page on given line and column

Specified by:
getErrorSource in class JxpPageSource
Parameters:
page - the page
line - the line
col - the column
Returns:
the StringBuffer
Throws:
java.io.IOException - if there's IO problem

assignPageStaticVariable

final java.lang.Object assignPageStaticVariable(CachedJxpPage page,
                                                java.lang.String name,
                                                java.lang.Object value)
Parameters:
page -
name -
value -
Returns:

purgeStaticVariables

protected final void purgeStaticVariables(CachedJxpPage page)
Purge the static variables for a page

Parameters:
page - the page

setEncoding

public final void setEncoding(java.lang.String encoding)
Set the encoding

Parameters:
encoding - the encoding

getEncoding

public final java.lang.String getEncoding()
Return the encoding

Returns:
the encoding

hasJxpPage

public final boolean hasJxpPage(java.lang.String id)
Return whether the jxp page identified by the id exists

Specified by:
hasJxpPage in class JxpPageSource
Parameters:
id - the id
Returns:
true if exists