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 java.lang.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
`static class` `AbstractFileProvider.WikiFileFilter` A simple filter which filters only those filenames which correspond to the file extension used.

### Field Summary

Fields
`static java.lang.String` `DEFAULT_ENCODING` The default encoding.
`static int` `DEFAULT_MAX_PROPKEYLENGTH`
`static int` `DEFAULT_MAX_PROPLIMIT`
`static int` `DEFAULT_MAX_PROPVALUELENGTH`
`static java.lang.String` `FILE_EXT` All files should have this extension to be recognized as JSPWiki files.
`protected java.lang.String` `m_encoding`
`protected Engine` `m_engine`
`static int` `MAX_PROPKEYLENGTH` This number limits the length of a custom page property key length.
`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.
`static java.lang.String` `PROP_CUSTOMPROP_MAXKEYLENGTH`
`static java.lang.String` `PROP_CUSTOMPROP_MAXLIMIT`
`static java.lang.String` `PROP_CUSTOMPROP_MAXVALUELENGTH`
`static java.lang.String` `PROP_PAGEDIR` Name of the property that defines where page directories are.

### Fields inherited from interface org.apache.wiki.api.providers.WikiProvider

`LATEST_VERSION`

### Constructor Summary

Constructors
`AbstractFileProvider()`

### Method Summary

All Methods Instance Methods Concrete Methods
`protected java.util.Properties` `addCustomProperties​(Page page, java.util.Properties props)` By default all page attributes that start with "@" are returned as custom properties.
`void` `deletePage​(java.lang.String pageName)`
`void` `deleteVersion​(java.lang.String pageName, int version)`
`protected java.io.File` `findPage​(java.lang.String page)` Finds a Wiki page from the page repository.
`java.util.Collection<SearchResult>` `findPages​(QueryItem[] query)` Iterates through all WikiPages, matches them against the given query, and returns a Collection of SearchResult objects.
`java.util.Collection<Page>` `getAllChangedSince​(java.util.Date date)` Does not work.
`java.util.Collection<Page>` `getAllPages()`
`protected void` `getCustomProperties​(Page page, java.util.Properties defaultProperties)` Get custom properties using `addCustomProperties(Page, Properties)`, validate them using `validateCustomPageProperties(Properties)` and add them to default properties provided
`int` `getPageCount()`
`Page` `getPageInfo​(java.lang.String page, int version)` Always returns the latest version, since FileSystemProvider does not support versioning.
`java.lang.String` `getPageText​(java.lang.String page, int version)` This implementation just returns the current version, as filesystem does not provide versioning information for now.
`java.lang.String` `getProviderInfo()`
`java.util.List<Page>` `getVersionHistory​(java.lang.String page)` The FileSystemProvider provides only one version.
`void` `initialize​(Engine engine, java.util.Properties properties)`
`protected java.lang.String` `mangleName​(java.lang.String pagename)` This makes sure that the queried page name is still readable by the file system.
`boolean` `pageExists​(java.lang.String page)`
`boolean` `pageExists​(java.lang.String page, int version)`
`void` `putPageText​(Page page, java.lang.String text)`
`protected void` `setCustomProperties​(Page page, java.util.Properties properties)` Set the custom properties provided into the given page.
`protected java.lang.String` `unmangleName​(java.lang.String filename)` This makes the reverse of mangleName.
`protected void` `validateCustomPageProperties​(java.util.Properties customProperties)` Default validation, validates that key and value is ASCII `StringUtils.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, wait`

### Methods inherited from interface org.apache.wiki.api.providers.PageProvider

`movePage`

### Field Detail

#### m_encoding

    protected java.lang.String m_encoding

#### m_engine

    protected Engine m_engine

#### PROP_CUSTOMPROP_MAXLIMIT

    public static final java.lang.String PROP_CUSTOMPROP_MAXLIMIT

See Also:
  Constant Field Values

#### PROP_CUSTOMPROP_MAXKEYLENGTH

    public static final java.lang.String PROP_CUSTOMPROP_MAXKEYLENGTH

See Also:
  Constant Field Values

#### PROP_CUSTOMPROP_MAXVALUELENGTH

    public static final java.lang.String PROP_CUSTOMPROP_MAXVALUELENGTH

See Also:
  Constant Field Values

#### DEFAULT_MAX_PROPLIMIT

    public static final int DEFAULT_MAX_PROPLIMIT

See Also:
  Constant Field Values

#### DEFAULT_MAX_PROPKEYLENGTH

    public static final int DEFAULT_MAX_PROPKEYLENGTH

See Also:
  Constant Field Values

#### DEFAULT_MAX_PROPVALUELENGTH

    public static final int DEFAULT_MAX_PROPVALUELENGTH

See Also:
  Constant Field Values

#### MAX_PROPLIMIT

    public static int MAX_PROPLIMIT

This parameter limits the number of custom page properties allowed on a page

#### MAX_PROPKEYLENGTH

    public 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.

#### MAX_PROPVALUELENGTH

    public 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.

#### PROP_PAGEDIR

    public static final java.lang.String PROP_PAGEDIR

Name of the property that defines where page directories are.

See Also:
  Constant Field Values

#### FILE_EXT

    public static final java.lang.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 java.lang.String DEFAULT_ENCODING

The default encoding.

### Constructor Detail

#### AbstractFileProvider

    public AbstractFileProvider()

### Method Detail

#### initialize

    public void initialize​(Engine engine,
                           java.util.Properties properties)
                    throws NoRequiredPropertyException,
                           java.io.IOException,
                           java.io.FileNotFoundException

Specified by:
  `initialize` in interface `WikiProvider`
Throws:
  `java.io.FileNotFoundException` - If the specified page directory does not exist.
  `java.io.IOException` - In case the specified page directory is a file, not a directory.
  `NoRequiredPropertyException`

#### mangleName

    protected java.lang.String mangleName​(java.lang.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 java.lang.String unmangleName​(java.lang.String filename)

This makes the reverse of mangleName.

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

#### findPage

    protected java.io.File findPage​(java.lang.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​(java.lang.String page)

Specified by:
  `pageExists` in interface `PageProvider`

#### pageExists

    public boolean pageExists​(java.lang.String page,
                              int version)

Specified by:
  `pageExists` in interface `PageProvider`

#### getPageText

    public java.lang.String getPageText​(java.lang.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 `PageProvider`
Throws:
  `ProviderException`

#### putPageText

    public void putPageText​(Page page,
                            java.lang.String text)
                     throws ProviderException

Specified by:
  `putPageText` in interface `PageProvider`
Throws:
  `ProviderException`

#### getAllPages

    public java.util.Collection<Page> getAllPages()
                                           throws ProviderException

Specified by:
  `getAllPages` in interface `PageProvider`
Throws:
  `ProviderException`

#### getAllChangedSince

    public java.util.Collection<Page> getAllChangedSince​(java.util.Date date)

Does not work.

Specified by:
  `getAllChangedSince` in interface `PageProvider`
Parameters:
  `date` -
Returns:

#### getPageCount

    public int getPageCount()

Specified by:
  `getPageCount` in interface `PageProvider`

#### findPages

    public java.util.Collection<SearchResult> 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 `PageProvider`

#### getPageInfo

    public Page getPageInfo​(java.lang.String page,
                            int version)
                     throws ProviderException

Always returns the latest version, since FileSystemProvider does not support versioning.

Specified by:
  `getPageInfo` in interface `PageProvider`
Throws:
  `ProviderException`

#### getVersionHistory

    public java.util.List<Page> getVersionHistory​(java.lang.String page)
                                           throws ProviderException

The FileSystemProvider provides only one version.

Specified by:
  `getVersionHistory` in interface `PageProvider`
Throws:
  `ProviderException`

#### getProviderInfo

    public java.lang.String getProviderInfo()

Specified by:
  `getProviderInfo` in interface `WikiProvider`

#### deleteVersion

    public void deleteVersion​(java.lang.String pageName,
                              int version)
                       throws ProviderException

Specified by:
  `deleteVersion` in interface `PageProvider`
Throws:
  `ProviderException`

#### deletePage

    public void deletePage​(java.lang.String pageName)
                    throws ProviderException

Specified by:
  `deletePage` in interface `PageProvider`
Throws:
  `ProviderException`

#### setCustomProperties

    protected void setCustomProperties​(Page page,
                                       java.util.Properties properties)

Set the custom properties provided into the given page.

Since:
  2.10.2

#### getCustomProperties

    protected void getCustomProperties​(Page page,
                                       java.util.Properties defaultProperties)
                                throws java.io.IOException

Get custom properties using `addCustomProperties(Page, Properties)`, validate them using `validateCustomPageProperties(Properties)` and add them to default properties provided

Throws:
  `java.io.IOException`
Since:
  2.10.2

#### addCustomProperties

    protected java.util.Properties addCustomProperties​(Page page,
                                                       java.util.Properties props)

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 by `validateCustomPageProperties(Properties)`

Parameters:
  `page` - the current page
  `props` - the default properties of this page
Returns:
  default implementation returns empty Properties.
Since:
  2.10.2

#### validateCustomPageProperties

    protected void validateCustomPageProperties​(java.util.Properties customProperties)
                                         throws java.io.IOException

Default validation, validates that key and value is ASCII `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-856

Parameters:
  `customProperties` - the custom page properties being added
Throws:
  `java.io.IOException`
Since:
  2.10.2