org.apache.wiki.providers
Class AbstractFileProvider

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

public abstract class AbstractFileProvider
extends Object
implements WikiPageProvider

Provides a simple directory based repository for Wiki pages.

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.

This class functions as a superclass to all file based providers.

Since:
2.1.21.

Nested Class Summary
static class AbstractFileProvider.WikiFileFilter
          A simple filter which filters only those filenames which correspond to the file extension used.
 
Field Summary
static String DEFAULT_ENCODING
          The default encoding.
static String FILE_EXT
          All files should have this extension to be recognized as JSPWiki files.
protected  String m_encoding
           
protected  WikiEngine m_engine
           
static String PROP_PAGEDIR
          Name of the property that defines where page directories are.
 
Fields inherited from interface org.apache.wiki.WikiProvider
LATEST_VERSION
 
Constructor Summary
AbstractFileProvider()
           
 
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.
protected  File findPage(String page)
          Finds a Wiki page from the page repository.
 Collection findPages(QueryItem[] query)
          Iterates through all WikiPages, matches them against the given query, and returns a Collection of SearchResult objects.
 Collection getAllChangedSince(Date date)
          Does not work.
 Collection getAllPages()
          Returns all pages.
 int getPageCount()
          Gets the number of 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.
protected  String mangleName(String pagename)
          This makes sure that the queried page name is still readable by the file system.
 boolean pageExists(String page)
          Return true, if page exists.
 boolean pageExists(String page, 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".
protected  String unmangleName(String filename)
          This makes the reverse of mangleName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.wiki.providers.WikiPageProvider
movePage
 

Field Detail

m_encoding

protected String m_encoding

m_engine

protected WikiEngine m_engine

PROP_PAGEDIR

public static final String PROP_PAGEDIR
Name of the property that defines where page directories are.

See Also:
Constant Field Values

FILE_EXT

public static final String FILE_EXT
All files should have this extension to be recognized as JSPWiki files. We default to .txt, because that is probably easiest for Windows users, and guarantees correct handling.

See Also:
Constant Field Values

DEFAULT_ENCODING

public static final String DEFAULT_ENCODING
The default encoding.

See Also:
Constant Field Values
Constructor Detail

AbstractFileProvider

public AbstractFileProvider()
Method Detail

initialize

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

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

mangleName

protected String mangleName(String pagename)
This makes sure that the queried page name is still readable by the file system. For example, all XML entities and slashes are encoded with the percent notation.

Parameters:
pagename - The name to mangle
Returns:
The mangled name.

unmangleName

protected String unmangleName(String filename)
This makes the reverse of mangleName.

Parameters:
filename - The filename to unmangle
Returns:
The unmangled name.

findPage

protected File findPage(String page)
Finds a Wiki page from the page repository.

Parameters:
page - The name of the page.
Returns:
A File to the page. May be null.

pageExists

public boolean pageExists(String page)
Return true, if page exists.

Specified by:
pageExists in interface WikiPageProvider
Parameters:
page - The page name.
Returns:
true, if the page exists; false otherwise.

pageExists

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

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

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
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:
{@inheritDoc}
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
Parameters:
page - The WikiPage to save
text - The text to save.
Throws:
ProviderException - If something goes wrong.

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
Returns:
A collection of WikiPages
Throws:
ProviderException - If something goes wrong.

getAllChangedSince

public Collection getAllChangedSince(Date date)
Does not work.

Specified by:
getAllChangedSince in interface WikiPageProvider
Parameters:
date - The date to check from
Returns:
A Collection of WikiPages

getPageCount

public int getPageCount()
Gets the number of pages.

Specified by:
getPageCount in interface WikiPageProvider
Returns:
The number of pages in the repository

findPages

public Collection findPages(QueryItem[] query)
Iterates through all WikiPages, matches them against the given query, and returns a Collection of SearchResult objects.

Specified by:
findPages in interface WikiPageProvider
Parameters:
query - An array of QueryItems to match
Returns:
A Collection of WikiPages.

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
Parameters:
page - The page name
version - The version number
Returns:
A filled WikiPage.
Throws:
{@inheritDoc}
ProviderException - If something goes wrong.

getVersionHistory

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

Specified by:
getVersionHistory in interface WikiPageProvider
Parameters:
page - The name of the page to get the history from.
Returns:
A collection of WikiPages.
Throws:
{@inheritDoc}
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
Returns:
A string describing the provider.

deleteVersion

public void deleteVersion(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:
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
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.


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