public abstract class AbstractFileProvider extends Object implements WikiPageProvider
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.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractFileProvider.WikiFileFilter
A simple filter which filters only those filenames which correspond to the
file extension used.
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ENCODING
The default encoding.
|
static int |
DEFAULT_MAX_PROPKEYLENGTH |
static int |
DEFAULT_MAX_PROPLIMIT |
static int |
DEFAULT_MAX_PROPVALUELENGTH |
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 int |
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.
|
static int |
MAX_PROPLIMIT
This parameter limits the number of custom page properties allowed on a page
|
static int |
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.
|
static String |
PROP_CUSTOMPROP_MAXKEYLENGTH |
static String |
PROP_CUSTOMPROP_MAXLIMIT |
static String |
PROP_CUSTOMPROP_MAXVALUELENGTH |
static String |
PROP_PAGEDIR
Name of the property that defines where page directories are.
|
LATEST_VERSION
Constructor and Description |
---|
AbstractFileProvider() |
Modifier and Type | Method and Description |
---|---|
protected Properties |
addCustomProperties(WikiPage page,
Properties props)
By default all page attributes that start with "@" are returned as custom properties.
|
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<SearchResult> |
findPages(QueryItem[] query)
Iterates through all WikiPages, matches them against the given query,
and returns a Collection of SearchResult objects.
|
Collection<WikiPage> |
getAllChangedSince(Date date)
Does not work.
|
Collection<WikiPage> |
getAllPages()
Returns all pages.
|
protected void |
getCustomProperties(WikiPage page,
Properties defaultProperties)
Get custom properties using
addCustomProperties(WikiPage, Properties) , validate them using validateCustomPageProperties(Properties)
and add them to default properties provided |
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<WikiPage> |
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 void |
setCustomProperties(WikiPage page,
Properties properties)
Set the custom properties provided into the given page.
|
protected String |
unmangleName(String filename)
This makes the reverse of mangleName.
|
protected void |
validateCustomPageProperties(Properties customProperties)
Default validation, validates that key and value is ASCII
StringUtils.isAsciiPrintable() and within lengths set up in jspwiki-custom.properties. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
movePage
protected String m_encoding
protected WikiEngine m_engine
public static final String PROP_CUSTOMPROP_MAXLIMIT
public static final String PROP_CUSTOMPROP_MAXKEYLENGTH
public static final String PROP_CUSTOMPROP_MAXVALUELENGTH
public static final int DEFAULT_MAX_PROPLIMIT
public static final int DEFAULT_MAX_PROPKEYLENGTH
public static final int DEFAULT_MAX_PROPVALUELENGTH
public static int MAX_PROPLIMIT
public static int MAX_PROPKEYLENGTH
public static int MAX_PROPVALUELENGTH
public static final String PROP_PAGEDIR
public static final String FILE_EXT
public static final String DEFAULT_ENCODING
public AbstractFileProvider()
public void initialize(WikiEngine engine, Properties properties) throws NoRequiredPropertyException, IOException, FileNotFoundException
initialize
in interface WikiProvider
engine
- WikiEngine to own this providerproperties
- A set of properties used to initialize this providerFileNotFoundException
- 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 setprotected String mangleName(String pagename)
pagename
- The name to mangleprotected String unmangleName(String filename)
filename
- The filename to unmangleprotected File findPage(String page)
page
- The name of the page.public boolean pageExists(String page)
pageExists
in interface WikiPageProvider
page
- The page name.public boolean pageExists(String page, int version)
pageExists
in interface WikiPageProvider
page
- The page name to check forversion
- The version to checkpublic String getPageText(String page, int version) throws ProviderException
getPageText
in interface WikiPageProvider
page
- Name of the page to fetch.version
- Version of the page to fetch.{@inheritDoc}
ProviderException
- If something goes wrong.public void putPageText(WikiPage page, String text) throws ProviderException
putPageText
in interface WikiPageProvider
page
- The WikiPage to savetext
- The text to save.ProviderException
- If something goes wrong.public Collection<WikiPage> getAllPages() throws ProviderException
getAllPages
in interface WikiPageProvider
ProviderException
- If something goes wrong.public Collection<WikiPage> getAllChangedSince(Date date)
getAllChangedSince
in interface WikiPageProvider
date
- The date to check frompublic int getPageCount()
getPageCount
in interface WikiPageProvider
public Collection<SearchResult> findPages(QueryItem[] query)
findPages
in interface WikiPageProvider
query
- An array of QueryItems to matchpublic WikiPage getPageInfo(String page, int version) throws ProviderException
getPageInfo
in interface WikiPageProvider
page
- The page nameversion
- The version number{@inheritDoc}
ProviderException
- If something goes wrong.public List<WikiPage> getVersionHistory(String page) throws ProviderException
getVersionHistory
in interface WikiPageProvider
page
- The name of the page to get the history from.{@inheritDoc}
ProviderException
- If something goes wrong.public String getProviderInfo()
getProviderInfo
in interface WikiProvider
public void deleteVersion(String pageName, int version) throws ProviderException
deleteVersion
in interface WikiPageProvider
pageName
- Name of the page to be removed.version
- Version of the page to be removed. May be LATEST_VERSION.ProviderException
- If the page cannot be removed for some reason.public void deletePage(String pageName) throws ProviderException
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...
deletePage
in interface WikiPageProvider
pageName
- Name of the page to be removed completely.ProviderException
- If the page could not be removed for some reason.protected void setCustomProperties(WikiPage page, Properties properties)
protected void getCustomProperties(WikiPage page, Properties defaultProperties) throws IOException
addCustomProperties(WikiPage, Properties)
, validate them using validateCustomPageProperties(Properties)
and add them to default properties providedIOException
protected Properties addCustomProperties(WikiPage page, Properties props)
validateCustomPageProperties(Properties)
page
- the current pageprops
- the default properties of this pageprotected void validateCustomPageProperties(Properties customProperties) throws IOException
StringUtils.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-856customProperties
- the custom page properties being addedIOException
Copyright © 2001-2019 The Apache Software Foundation. All rights reserved.