org.apache.wiki.providers
Class VersioningFileProvider

java.lang.Object
  extended by org.apache.wiki.providers.AbstractFileProvider
      extended by org.apache.wiki.providers.VersioningFileProvider
All Implemented Interfaces:
WikiPageProvider, WikiProvider

public class VersioningFileProvider
extends AbstractFileProvider

Provides a simple directory based repository for Wiki pages. Pages are held in a directory structure:

    Main.txt
    Foobar.txt
    OLD/
       Main/
          1.txt
          2.txt
          page.properties
       Foobar/
          page.properties
  
In this case, "Main" has three versions, and "Foobar" just one version.

The properties file contains the necessary metainformation (such as author) information of the page. DO NOT MESS WITH IT!

All files have ".txt" appended to make life easier for those who insist on using Windows or other software which makes assumptions on the files contents based on its name.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.wiki.providers.AbstractFileProvider
AbstractFileProvider.WikiFileFilter
 
Field Summary
static String PAGEDIR
          Name of the directory where the old versions are stored.
static String PROPERTYFILE
          Name of the property file which stores the metadata.
 
Fields inherited from class org.apache.wiki.providers.AbstractFileProvider
DEFAULT_ENCODING, FILE_EXT, m_encoding, m_engine, PROP_PAGEDIR
 
Fields inherited from interface org.apache.wiki.WikiProvider
LATEST_VERSION
 
Constructor Summary
VersioningFileProvider()
           
 
Method Summary
 void deletePage(String page)
          Removes the relevant page directory under "OLD" -directory as well, but does not remove any extra subdirectories from it.
 void deleteVersion(String page, int version)
          Removes a specific version from the repository.
 Collection getAllPages()
          Returns all pages.
 WikiPage getPageInfo(String page, int version)
          Always returns the latest version, since FileSystemProvider does not support versioning.
 String getPageText(String page, int version)
          This implementation just returns the current version, as filesystem does not provide versioning information for now.
 String getProviderInfo()
          Return a valid HTML string for information.
 List getVersionHistory(String page)
          The FileSystemProvider provides only one version.
 void initialize(WikiEngine engine, Properties properties)
          Initializes the page provider.
 void movePage(String from, String to)
          Move a page
 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 org.apache.wiki.providers.AbstractFileProvider
findPage, findPages, getAllChangedSince, getPageCount, mangleName, pageExists, unmangleName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAGEDIR

public static final String PAGEDIR
Name of the directory where the old versions are stored.

See Also:
Constant Field Values

PROPERTYFILE

public static final String PROPERTYFILE
Name of the property file which stores the metadata.

See Also:
Constant Field Values
Constructor Detail

VersioningFileProvider

public VersioningFileProvider()
Method Detail

initialize

public void initialize(WikiEngine engine,
                       Properties properties)
                throws NoRequiredPropertyException,
                       IOException
Initializes the page provider.

Specified by:
initialize in interface WikiProvider
Overrides:
initialize in class AbstractFileProvider
Parameters:
engine - WikiEngine to own this provider
properties - A set of properties used to initialize this provider
Throws:
NoRequiredPropertyException - If the provider needs a property which is not found in the property set
FileNotFoundException - If the specified page directory does not exist.
IOException - In case the specified page directory is a file, not a directory.

getPageText

public String getPageText(String page,
                          int version)
                   throws ProviderException
This implementation just returns the current version, as filesystem does not provide versioning information for now.

Specified by:
getPageText in interface WikiPageProvider
Overrides:
getPageText in class AbstractFileProvider
Parameters:
page - 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(WikiPage page,
                        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:
putPageText in interface WikiPageProvider
Overrides:
putPageText in class AbstractFileProvider
Parameters:
page - The WikiPage to save
text - The text to save.
Throws:
ProviderException - If something goes wrong.

getPageInfo

public WikiPage getPageInfo(String page,
                            int version)
                     throws ProviderException
Always returns the latest version, since FileSystemProvider does not support versioning.

Specified by:
getPageInfo in interface WikiPageProvider
Overrides:
getPageInfo in class AbstractFileProvider
Parameters:
page - The page name
version - The version number
Returns:
A filled WikiPage.
Throws:
ProviderException - If something goes wrong.

pageExists

public boolean pageExists(String pageName,
                          int version)
Return true, if page with a particular version exists.

Specified by:
pageExists in interface WikiPageProvider
Overrides:
pageExists in class AbstractFileProvider
Parameters:
pageName - The page name to check for
version - The version to check
Returns:
True, if page exists; false otherwise.

getVersionHistory

public List getVersionHistory(String page)
                       throws ProviderException
The FileSystemProvider provides only one version.

Specified by:
getVersionHistory in interface WikiPageProvider
Overrides:
getVersionHistory in class AbstractFileProvider
Parameters:
page - The name of the page to get the history from.
Returns:
A collection of WikiPages.
Throws:
ProviderException - If something goes wrong.

deletePage

public void deletePage(String page)
                throws ProviderException
Removes the relevant page directory under "OLD" -directory as well, but does not remove any extra subdirectories from it. It will only touch those files that it thinks to be WikiPages.

Specified by:
deletePage in interface WikiPageProvider
Overrides:
deletePage in class AbstractFileProvider
Parameters:
page - Name of the page to be removed completely.
Throws:
{@inheritDoc}
ProviderException - If the page could not be removed for some reason.

deleteVersion

public void deleteVersion(String page,
                          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. Deleting versions has never really worked, JSPWiki assumes that version histories are "not gappy". Using deleteVersion() is definitely not recommended.

Specified by:
deleteVersion in interface WikiPageProvider
Overrides:
deleteVersion in class AbstractFileProvider
Parameters:
page - 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.

getAllPages

public Collection getAllPages()
                       throws ProviderException
Returns all pages. Each element in the returned Collection should be a WikiPage.

Specified by:
getAllPages in interface WikiPageProvider
Overrides:
getAllPages in class AbstractFileProvider
Returns:
A collection of WikiPages
Throws:
ProviderException - If something goes wrong.

getProviderInfo

public String getProviderInfo()
Return a valid HTML string for information. May be anything.

Specified by:
getProviderInfo in interface WikiProvider
Overrides:
getProviderInfo in class AbstractFileProvider
Returns:
A string describing the provider.

movePage

public void movePage(String from,
                     String to)
              throws ProviderException
Move a page

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.


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.