Package org.apache.wiki.providers
Class AbstractFileProvider
java.lang.Object
org.apache.wiki.providers.AbstractFileProvider
- All Implemented Interfaces:
PageProvider,WikiProvider
- Direct Known Subclasses:
FileSystemProvider,VersioningFileProvider
public abstract class AbstractFileProvider extends Object implements PageProvider
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
Nested Classes Modifier and Type Class Description static classAbstractFileProvider.WikiFileFilterA simple filter which filters only those filenames which correspond to the file extension used. -
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_ENCODINGThe default encoding.static intDEFAULT_MAX_PROPKEYLENGTHstatic intDEFAULT_MAX_PROPLIMITstatic intDEFAULT_MAX_PROPVALUELENGTHstatic StringFILE_EXTAll files should have this extension to be recognized as JSPWiki files.protected Stringm_encodingprotected Enginem_enginestatic intMAX_PROPKEYLENGTHThis number limits the length of a custom page property key length.static intMAX_PROPLIMITThis parameter limits the number of custom page properties allowed on a pagestatic intMAX_PROPVALUELENGTHThis number limits the length of a custom page property value length.static StringPROP_CUSTOMPROP_MAXKEYLENGTHstatic StringPROP_CUSTOMPROP_MAXLIMITstatic StringPROP_CUSTOMPROP_MAXVALUELENGTHstatic StringPROP_PAGEDIRName of the property that defines where page directories are.Fields inherited from interface org.apache.wiki.api.providers.WikiProvider
LATEST_VERSION -
Constructor Summary
Constructors Constructor Description AbstractFileProvider() -
Method Summary
Modifier and Type Method Description protected PropertiesaddCustomProperties(Page page, Properties props)By default all page attributes that start with "@" are returned as custom properties.voiddeletePage(String pageName)Removes an entire page from the repository.voiddeleteVersion(String pageName, int version)Removes a specific version from the repository.protected FilefindPage(String page)Finds a Wiki page from the page repository.Collection<SearchResult>findPages(QueryItem[] query)Iterates through all WikiPages, matches them against the given query, and returns a Collection of SearchResult objects.Collection<Page>getAllChangedSince(Date date)Does not work.Collection<Page>getAllPages()Returns all pages.protected voidgetCustomProperties(Page page, Properties defaultProperties)Get custom properties usingaddCustomProperties(Page, Properties), validate them usingvalidateCustomPageProperties(Properties)and add them to default properties providedintgetPageCount()Gets the number of pages.PagegetPageInfo(String page, int version)Always returns the latest version, since FileSystemProvider does not support versioning.StringgetPageText(String page, int version)This implementation just returns the current version, as filesystem does not provide versioning information for now.StringgetProviderInfo()Return a valid HTML string for information.List<Page>getVersionHistory(String page)The FileSystemProvider provides only one version.voidinitialize(Engine engine, Properties properties)Initializes the page provider.protected StringmangleName(String pagename)This makes sure that the queried page name is still readable by the file system.booleanpageExists(String page)Return true, if page exists.booleanpageExists(String page, int version)Return true, if page with a particular version exists.voidputPageText(Page page, String text)Attempts to save the page text for page "page".protected voidsetCustomProperties(Page page, Properties properties)Set the custom properties provided into the given page.protected StringunmangleName(String filename)This makes the reverse of mangleName.protected voidvalidateCustomPageProperties(Properties customProperties)Default validation, validates that key and value is ASCIIStringUtils.isAsciiPrintable()and within lengths set up in jspwiki-custom.properties.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.wiki.api.providers.PageProvider
movePage
-
Field Details
-
m_encoding
-
m_engine
-
PROP_CUSTOMPROP_MAXLIMIT
- See Also:
- Constant Field Values
-
PROP_CUSTOMPROP_MAXKEYLENGTH
- See Also:
- Constant Field Values
-
PROP_CUSTOMPROP_MAXVALUELENGTH
- See Also:
- Constant Field Values
-
DEFAULT_MAX_PROPLIMIT
- See Also:
- Constant Field Values
-
DEFAULT_MAX_PROPKEYLENGTH
- See Also:
- Constant Field Values
-
DEFAULT_MAX_PROPVALUELENGTH
- See Also:
- Constant Field Values
-
MAX_PROPLIMIT
This parameter limits the number of custom page properties allowed on a page -
MAX_PROPKEYLENGTH
This number limits the length of a custom page property key length. The default value here designed with future JDBC providers in mind. -
MAX_PROPVALUELENGTH
This number limits the length of a custom page property value length. The default value here designed with future JDBC providers in mind. -
PROP_PAGEDIR
Name of the property that defines where page directories are.- See Also:
- Constant Field Values
-
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
The default encoding.
-
-
Constructor Details
-
AbstractFileProvider
public AbstractFileProvider()
-
-
Method Details
-
initialize
public void initialize(Engine engine, Properties properties) throws NoRequiredPropertyException, IOException, FileNotFoundExceptionInitializes the page provider.- Specified by:
initializein interfaceWikiProvider- Parameters:
engine- Engine to own this providerproperties- 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
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
This makes the reverse of mangleName.- Parameters:
filename- The filename to unmangle- Returns:
- The unmangled name.
-
findPage
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
Return true, if page exists.- Specified by:
pageExistsin interfacePageProvider- Parameters:
page- The page name.- Returns:
- true, if the page exists; false otherwise.
-
pageExists
Return true, if page with a particular version exists.- Specified by:
pageExistsin interfacePageProvider- Parameters:
page- The page name to check forversion- The version to check- Returns:
- True, if page exists; false otherwise.
-
getPageText
This implementation just returns the current version, as filesystem does not provide versioning information for now. Gets a specific version out of the repository.- Specified by:
getPageTextin interfacePageProvider- 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
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
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
Does not work.- Specified by:
getAllChangedSincein interfacePageProvider- Parameters:
date- The date to check from- Returns:
- A Collection of WikiPages
-
getPageCount
Gets the number of pages.- Specified by:
getPageCountin interfacePageProvider- Returns:
- The number of pages in the repository
-
findPages
Iterates through all WikiPages, matches them against the given query, and returns a Collection of SearchResult objects. 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
Always returns the latest version, since FileSystemProvider does not support versioning. Returns info about the page.- Specified by:
getPageInfoin interfacePageProvider- Parameters:
page- The page nameversion- The version number- Returns:
- A filled WikiPage.
- Throws:
ProviderException- If something goes wrong.
-
getVersionHistory
The FileSystemProvider provides only one version. Returns version history. Each element should be a WikiPage.- Specified by:
getVersionHistoryin interfacePageProvider- Parameters:
page- The name of the page to get the history from.- Returns:
- A collection of WikiPages.
- Throws:
ProviderException- If something goes wrong.
-
getProviderInfo
Return a valid HTML string for information. May be anything.- Specified by:
getProviderInfoin interfaceWikiProvider- Returns:
- A string describing the provider.
-
deleteVersion
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
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.
-
setCustomProperties
Set the custom properties provided into the given page.- Since:
- 2.10.2
-
getCustomProperties
Get custom properties usingaddCustomProperties(Page, Properties), validate them usingvalidateCustomPageProperties(Properties)and add them to default properties provided- Throws:
IOException- Since:
- 2.10.2
-
addCustomProperties
By default all page attributes that start with "@" are returned as custom properties. This can be overwritten by custom FileSystemProviders to save additional properties. CustomPageProperties are validated byvalidateCustomPageProperties(Properties)- Parameters:
page- the current pageprops- the default properties of this page- Returns:
- default implementation returns empty Properties.
- Since:
- 2.10.2
-
validateCustomPageProperties
Default validation, validates that key and value is ASCIIStringUtils.isAsciiPrintable()and within lengths set up in jspwiki-custom.properties. This can be overwritten by custom FileSystemProviders to validate additional properties See https://issues.apache.org/jira/browse/JSPWIKI-856- Parameters:
customProperties- the custom page properties being added- Throws:
IOException- Since:
- 2.10.2
-