Package org.apache.wiki.providers
Class CachingProvider
- java.lang.Object
-
- org.apache.wiki.providers.CachingProvider
-
- All Implemented Interfaces:
PageProvider,WikiProvider
public class CachingProvider extends java.lang.Object implements PageProvider
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 does not detect if someone has modified the page externally, not through JSPWiki routines.
Heavily based on ideas by Chris Brooking.
Since 2.10 uses the Ehcache library.
- Since:
- 1.6.4
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCACHE_NAMEName of the regular page cache.static intDEFAULT_CACHECAPACITYstatic intDEFAULT_CACHETIMETOIDLESECONDSstatic intDEFAULT_CACHETIMETOLIVESECONDSstatic java.lang.StringHISTORYCACHE_NAMEName of the page history cache.static java.lang.StringTEXTCACHE_NAMEName of the page text cache.-
Fields inherited from interface org.apache.wiki.api.providers.WikiProvider
LATEST_VERSION
-
-
Constructor Summary
Constructors Constructor Description CachingProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeletePage(java.lang.String pageName)Removes an entire page from the repository.voiddeleteVersion(java.lang.String pageName, int version)Removes a specific version from the repository.java.util.Collection<SearchResult>findPages(QueryItem[] query)Finds pages based on the query.java.util.Collection<Page>getAllChangedSince(java.util.Date date)Gets a list of recent changes.java.util.Collection<Page>getAllPages()Returns all pages.intgetPageCount()Gets the number of pages.PagegetPageInfo(java.lang.String pageName, int version)Returns info about the page.java.lang.StringgetPageText(java.lang.String pageName, int version)Gets a specific version out of the repository.java.lang.StringgetProviderInfo()Gets the provider class name, and cache statistics (misscount and hitcount of page cache and history cache).PageProvidergetRealProvider()Returns the actual used provider.java.util.List<Page>getVersionHistory(java.lang.String pageName)Returns version history.voidinitialize(Engine engine, java.util.Properties properties)Initializes the page provider.voidmovePage(java.lang.String from, java.lang.String to)Move a pagebooleanpageExists(java.lang.String pageName)Return true, if page exists.booleanpageExists(java.lang.String pageName, int version)Return true, if page with a particular version exists.voidputPageText(Page page, java.lang.String text)Attempts to save the page text for page "page".
-
-
-
Field Detail
-
CACHE_NAME
public static final java.lang.String CACHE_NAME
Name of the regular page cache.- See Also:
- Constant Field Values
-
TEXTCACHE_NAME
public static final java.lang.String TEXTCACHE_NAME
Name of the page text cache.- See Also:
- Constant Field Values
-
HISTORYCACHE_NAME
public static final java.lang.String HISTORYCACHE_NAME
Name of the page history cache.- See Also:
- Constant Field Values
-
DEFAULT_CACHECAPACITY
public static final int DEFAULT_CACHECAPACITY
- See Also:
- Constant Field Values
-
DEFAULT_CACHETIMETOLIVESECONDS
public static final int DEFAULT_CACHETIMETOLIVESECONDS
- See Also:
- Constant Field Values
-
DEFAULT_CACHETIMETOIDLESECONDS
public static final int DEFAULT_CACHETIMETOIDLESECONDS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CachingProvider
public CachingProvider()
-
-
Method Detail
-
initialize
public void initialize(Engine engine, java.util.Properties properties) throws NoRequiredPropertyException, java.io.IOException
Initializes the page provider.- Specified by:
initializein interfaceWikiProvider- Parameters:
engine- Engine to own this providerproperties- A set of properties used to initialize this provider- Throws:
NoRequiredPropertyException- If the provider needs a property which is not found in the property setjava.io.IOException- If there is an IO problem
-
pageExists
public boolean pageExists(java.lang.String pageName, int version)
Return true, if page with a particular version exists.- Specified by:
pageExistsin interfacePageProvider- Parameters:
pageName- The page name to check forversion- The version to check- Returns:
- True, if page exists; false otherwise.
-
pageExists
public boolean pageExists(java.lang.String pageName)
Return true, if page exists.- Specified by:
pageExistsin interfacePageProvider- Parameters:
pageName- The page name.- Returns:
- true, if the page exists; false otherwise.
-
getPageText
public java.lang.String getPageText(java.lang.String pageName, int version) throws ProviderException
Gets a specific version out of the repository.- Specified by:
getPageTextin interfacePageProvider- 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:
ProviderException- If something goes wrong.
-
putPageText
public void putPageText(Page page, java.lang.String text) throws ProviderException
Attempts to save the page text for page "page". Note that the provider creates a new version regardless of what the version parameter of the WikiPage is.- Specified by:
putPageTextin interfacePageProvider- Parameters:
page- The WikiPage to savetext- The text to save.- Throws:
ProviderException- If something goes wrong.
-
getAllPages
public java.util.Collection<Page> getAllPages() throws ProviderException
Returns all pages. Each element in the returned Collection should be a WikiPage.- Specified by:
getAllPagesin interfacePageProvider- Returns:
- A collection of WikiPages
- Throws:
ProviderException- If something goes wrong.
-
getAllChangedSince
public java.util.Collection<Page> getAllChangedSince(java.util.Date date)
Gets a list of recent changes.- Specified by:
getAllChangedSincein interfacePageProvider- Parameters:
date- The date to check from- Returns:
- A Collection of WikiPages
-
getPageCount
public int getPageCount() throws ProviderException
Gets the number of pages.- Specified by:
getPageCountin interfacePageProvider- Returns:
- The number of pages in the repository
- Throws:
ProviderException- If something goes wrong
-
findPages
public java.util.Collection<SearchResult> findPages(QueryItem[] query)
Finds pages based on the query. Only applicable to providers which implement the FastSearch interface. Otherwise JSPWiki will use its internal cache.This method should really be a part of the FastSearch IF.
- Specified by:
findPagesin interfacePageProvider- Parameters:
query- An array of QueryItems to match- Returns:
- A Collection of WikiPages.
-
getPageInfo
public Page getPageInfo(java.lang.String pageName, int version) throws ProviderException
Returns info about the page.- Specified by:
getPageInfoin interfacePageProvider- Parameters:
pageName- The page nameversion- The version number- Returns:
- A filled WikiPage.
- Throws:
ProviderException- If something goes wrong.
-
getVersionHistory
public java.util.List<Page> getVersionHistory(java.lang.String pageName) throws ProviderException
Returns version history. Each element should be a WikiPage.- Specified by:
getVersionHistoryin interfacePageProvider- Parameters:
pageName- The name of the page to get the history from.- Returns:
- A collection of WikiPages.
- Throws:
ProviderException- If something goes wrong.
-
getProviderInfo
public java.lang.String getProviderInfo()
Gets the provider class name, and cache statistics (misscount and hitcount of page cache and history cache).- Specified by:
getProviderInfoin interfaceWikiProvider- Returns:
- A plain string with all the above mentioned values.
-
deleteVersion
public void deleteVersion(java.lang.String pageName, int version) throws ProviderException
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:
deleteVersionin interfacePageProvider- 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(java.lang.String pageName) throws ProviderException
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:
deletePagein interfacePageProvider- 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(java.lang.String from, java.lang.String to) throws ProviderException
Move a page- Specified by:
movePagein interfacePageProvider- 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 PageProvider getRealProvider()
Returns the actual used provider.- Returns:
- The real provider.
- Since:
- 2.0
-
-