public abstract class CachingPageSource extends JxpPageSource
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
CachingPageSource()
Constructor
(default use 200 cache limit, unlimit timeout)
|
CachingPageSource(int cacheSize)
Constructor
|
CachingPageSource(int cacheSize,
int timeout)
Constructor
|
Modifier and Type | Method and Description |
---|---|
(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
|
private org.onemind.commons.java.datastructure.MruMap _pageCache
private boolean _caching
private boolean _invalidateCacheOnParseError
private java.util.HashMap _pageStaticVariables
private java.lang.String _encoding
public CachingPageSource()
public CachingPageSource(int cacheSize)
cacheSize
- The default cache sizepublic CachingPageSource(int cacheSize, int timeout)
cacheSize
- The default cache sizetimeout
- time to expire inactive cachepublic final JxpPage getJxpPage(java.lang.String id) throws JxpPageNotFoundException
getJxpPage
in class JxpPageSource
id
- the idJxpPageNotFoundException
- if the page cannot be foundprotected final void invalidatePageCache(JxpPage page)
page
- the pagepublic final boolean isCaching()
public final void setCaching(boolean b)
b
- true if caching onpublic final AstJxpDocument getJxpDocument(JxpPage page) throws JxpPageParseException
getJxpDocument
in class JxpPageSource
page
- the JxpPageJxpPageParseException
protected abstract boolean isExpired(CachedJxpPage page)
page
- the pageprotected abstract boolean hasStream(java.lang.String pageName)
pageName
- the page nameprotected abstract java.io.InputStream loadStream(CachedJxpPage page) throws java.io.IOException
pageName
- the pagejava.io.IOException
public final boolean isJxpPageCached(java.lang.String id)
id
- the idfinal java.lang.Object declarePageStaticVariable(JxpPage page, java.lang.String name, java.lang.Object value)
page
- the pagename
- the namevalue
- the valuefinal boolean hasPageStaticVariable(JxpPage page, java.lang.String name)
page
- the pagename
- the namefinal java.lang.Object getPageStaticVariable(JxpPage page, java.lang.String name)
page
- the pagename
- the namapublic java.lang.StringBuffer getErrorSource(JxpPage page, int line, int col) throws java.io.IOException
getErrorSource
in class JxpPageSource
page
- the pageline
- the linecol
- the columnjava.io.IOException
- if there's IO problemfinal java.lang.Object assignPageStaticVariable(CachedJxpPage page, java.lang.String name, java.lang.Object value)
page
- name
- value
- protected final void purgeStaticVariables(CachedJxpPage page)
page
- the pagepublic final void setEncoding(java.lang.String encoding)
encoding
- the encodingpublic final java.lang.String getEncoding()
public final boolean hasJxpPage(java.lang.String id)
hasJxpPage
in class JxpPageSource
id
- the id