com.ecyrd.jspwiki.providers
Class CachingProvider

java.lang.Object
  extended by com.ecyrd.jspwiki.providers.CachingProvider
All Implemented Interfaces:
VersioningProvider, WikiPageProvider, WikiProvider

public class CachingProvider
extends Object
implements WikiPageProvider, VersioningProvider

Provides a caching page provider. This class rests on top of a real provider class and provides a cache to speed things up. Only if the cache copy of the page text has expired, we fetch it from the provider.

This class also detects if someone has modified the page externally, not through JSPWiki routines, and throws the proper RepositoryModifiedException.

Heavily based on ideas by Chris Brooking.

Since 2.1.52 uses the OSCache library from OpenSymphony.

Since:
1.6.4
Author:
Janne Jalkanen
See Also:
RepositoryModifiedException

Field Summary
static String PROP_CACHECAPACITY
           
static String PROP_CACHECHECKINTERVAL
          Defines, in seconds, the amount of time a text will live in the cache at most before requiring a refresh.
 
Fields inherited from interface com.ecyrd.jspwiki.WikiProvider
LATEST_VERSION
 
Constructor Summary
CachingProvider()
           
 
Method Summary
 void deletePage(String pageName)
          Removes an entire page from the repository.
 void deleteVersion(String pageName, int version)
          Removes a specific version from the repository.
 Collection findPages(QueryItem[] query)
          Finds pages based on the query.
 Collection getAllChangedSince(Date date)
          Gets a list of recent changes.
 Collection getAllPages()
          Returns all pages.
 int getPageCount()
          Gets the number of pages.
 WikiPage getPageInfo(String pageName, int version)
          Returns info about the page.
 String getPageText(String pageName, int version)
          Gets a specific version out of the repository.
 String getProviderInfo()
          Return a valid HTML string for information.
 WikiPageProvider getRealProvider()
          Returns the actual used provider.
 List getVersionHistory(String pageName)
          Returns version history.
 void initialize(WikiEngine engine, Properties properties)
          Initializes the page provider.
 void movePage(String from, String to)
          Move a page
 boolean pageExists(String pageName)
          Return true, if page exists.
 boolean pageExists(String pageName, int version)
          Return true, if page with a particular version exists.
 void putPageText(WikiPage page, String text)
          Attempts to save the page text for page "page".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_CACHECHECKINTERVAL

public static final String PROP_CACHECHECKINTERVAL
Defines, in seconds, the amount of time a text will live in the cache at most before requiring a refresh.

See Also:
Constant Field Values

PROP_CACHECAPACITY

public static final String PROP_CACHECAPACITY
See Also:
Constant Field Values
Constructor Detail

CachingProvider

public CachingProvider()
Method Detail

initialize

public void initialize(WikiEngine engine,
                       Properties properties)
                throws NoRequiredPropertyException,
                       IOException
Description copied from interface: WikiProvider
Initializes the page provider.

Specified by:
initialize in interface WikiProvider
Throws:
NoRequiredPropertyException
IOException

pageExists

public boolean pageExists(String pageName,
                          int version)
Description copied from interface: VersioningProvider
Return true, if page with a particular version exists.

Specified by:
pageExists in interface VersioningProvider

pageExists

public boolean pageExists(String pageName)
Description copied from interface: WikiPageProvider
Return true, if page exists.

Specified by:
pageExists in interface WikiPageProvider

getPageText

public String getPageText(String pageName,
                          int version)
                   throws ProviderException,
                          RepositoryModifiedException
Description copied from interface: WikiPageProvider
Gets a specific version out of the repository.

Specified by:
getPageText in interface WikiPageProvider
Parameters:
pageName - Name of the page to fetch.
version - Version of the page to fetch.
Returns:
The content of the page, or null, if the page does not exist.
Throws:
RepositoryModifiedException - If the page has been externally modified.
ProviderException

putPageText

public void putPageText(WikiPage page,
                        String text)
                 throws ProviderException
Description copied from interface: WikiPageProvider
Attempts to save the page text for page "page".

Specified by:
putPageText in interface WikiPageProvider
Throws:
ProviderException

getAllPages

public Collection getAllPages()
                       throws ProviderException
Description copied from interface: WikiPageProvider
Returns all pages. Each element in the returned Collection should be a WikiPage.

Specified by:
getAllPages in interface WikiPageProvider
Throws:
ProviderException

getAllChangedSince

public Collection getAllChangedSince(Date date)
Description copied from interface: WikiPageProvider
Gets a list of recent changes.

Specified by:
getAllChangedSince in interface WikiPageProvider

getPageCount

public int getPageCount()
                 throws ProviderException
Description copied from interface: WikiPageProvider
Gets the number of pages.

Specified by:
getPageCount in interface WikiPageProvider
Throws:
ProviderException

findPages

public Collection findPages(QueryItem[] query)
Description copied from interface: WikiPageProvider
Finds pages based on the query.

Specified by:
findPages in interface WikiPageProvider

getPageInfo

public WikiPage getPageInfo(String pageName,
                            int version)
                     throws ProviderException,
                            RepositoryModifiedException
Description copied from interface: WikiPageProvider
Returns info about the page.

Specified by:
getPageInfo in interface WikiPageProvider
Throws:
ProviderException
RepositoryModifiedException

getVersionHistory

public List getVersionHistory(String pageName)
                       throws ProviderException
Description copied from interface: WikiPageProvider
Returns version history. Each element should be a WikiPage.

Specified by:
getVersionHistory in interface WikiPageProvider
Returns:
A collection of wiki pages.
Throws:
ProviderException

getProviderInfo

public String getProviderInfo()
Description copied from interface: WikiProvider
Return a valid HTML string for information. May be anything.

Specified by:
getProviderInfo in interface WikiProvider

deleteVersion

public void deleteVersion(String pageName,
                          int version)
                   throws ProviderException
Description copied from interface: WikiPageProvider
Removes a specific version from the repository. The implementations should really do no more security checks, since that is the domain of the PageManager. Just delete it as efficiently as you can.

Specified by:
deleteVersion in interface WikiPageProvider
Parameters:
pageName - Name of the page to be removed.
version - Version of the page to be removed. May be LATEST_VERSION.
Throws:
ProviderException - If the page cannot be removed for some reason.

deletePage

public void deletePage(String pageName)
                throws ProviderException
Description copied from interface: WikiPageProvider
Removes an entire page from the repository. The implementations should really do no more security checks, since that is the domain of the PageManager. Just delete it as efficiently as you can. You should also delete any auxiliary files that belong to this page, IF they were created by this provider.

The reason why this is named differently from deleteVersion() (logically, this method should be an overloaded version) is that I want to be absolutely sure I don't accidentally use the wrong method. With overloading something like that happens sometimes...

Specified by:
deletePage in interface WikiPageProvider
Parameters:
pageName - Name of the page to be removed completely.
Throws:
ProviderException - If the page could not be removed for some reason.

movePage

public void movePage(String from,
                     String to)
              throws ProviderException
Description copied from interface: WikiPageProvider
Move a page

Specified by:
movePage in interface WikiPageProvider
Parameters:
from - Name of the page to move.
to - New name of the page.
Throws:
ProviderException - If the page could not be moved for some reason.

getRealProvider

public WikiPageProvider getRealProvider()
Returns the actual used provider.

Since:
2.0