Class AbstractFileProvider

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

public abstract class AbstractFileProvider extends Object implements org.apache.wiki.api.providers.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.
  • Field Details

  • Constructor Details

  • Method Details

    • initialize

      public void initialize(org.apache.wiki.api.core.Engine engine, Properties properties) throws org.apache.wiki.api.exceptions.NoRequiredPropertyException, IOException, FileNotFoundException
      Specified by:
      initialize in interface org.apache.wiki.api.providers.WikiProvider
      Throws:
      FileNotFoundException - If the specified page directory does not exist.
      IOException - In case the specified page directory is a file, not a directory.
      org.apache.wiki.api.exceptions.NoRequiredPropertyException
    • 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)
      Specified by:
      pageExists in interface org.apache.wiki.api.providers.PageProvider
    • pageExists

      public boolean pageExists(String page, int version)
      Specified by:
      pageExists in interface org.apache.wiki.api.providers.PageProvider
    • getPageText

      public String getPageText(String page, int version) throws org.apache.wiki.api.exceptions.ProviderException
      This implementation just returns the current version, as filesystem does not provide versioning information for now.
      Specified by:
      getPageText in interface org.apache.wiki.api.providers.PageProvider
      Throws:
      org.apache.wiki.api.exceptions.ProviderException
    • obfuscate

      public String obfuscate(String pageContent)
      An api hook to provide obfuscation of data before it's written to disk. Useful for wiring in your own custom encryption mechanism if so desired.
      Parameters:
      pageContent -
      Returns:
      Since:
      3.0.0
    • deobfuscate

      public String deobfuscate(String pageContent)
      An api hook to provide deobfuscation of data before it's written to disk. Useful for wiring in your own custom decryption mechanism if so desired.
      Parameters:
      pageContent -
      Returns:
      Since:
      3.0.0
    • putPageText

      public void putPageText(org.apache.wiki.api.core.Page page, String text) throws org.apache.wiki.api.exceptions.ProviderException
      Specified by:
      putPageText in interface org.apache.wiki.api.providers.PageProvider
      Throws:
      org.apache.wiki.api.exceptions.ProviderException
    • getAllPages

      public Collection<org.apache.wiki.api.core.Page> getAllPages() throws org.apache.wiki.api.exceptions.ProviderException
      Specified by:
      getAllPages in interface org.apache.wiki.api.providers.PageProvider
      Throws:
      org.apache.wiki.api.exceptions.ProviderException
    • getAllChangedSince

      public Collection<org.apache.wiki.api.core.Page> getAllChangedSince(Date date)
      Does not work.
      Specified by:
      getAllChangedSince in interface org.apache.wiki.api.providers.PageProvider
      Parameters:
      date -
      Returns:
    • getPageCount

      public int getPageCount()
      Specified by:
      getPageCount in interface org.apache.wiki.api.providers.PageProvider
    • findPages

      public Collection<org.apache.wiki.api.search.SearchResult> findPages(org.apache.wiki.api.search.QueryItem[] query)
      Iterates through all WikiPages, matches them against the given query, and returns a Collection of SearchResult objects.
      Specified by:
      findPages in interface org.apache.wiki.api.providers.PageProvider
    • getPageInfo

      public org.apache.wiki.api.core.Page getPageInfo(String page, int version) throws org.apache.wiki.api.exceptions.ProviderException
      Always returns the latest version, since FileSystemProvider does not support versioning.
      Specified by:
      getPageInfo in interface org.apache.wiki.api.providers.PageProvider
      Throws:
      org.apache.wiki.api.exceptions.ProviderException
    • getVersionHistory

      public List<org.apache.wiki.api.core.Page> getVersionHistory(String page) throws org.apache.wiki.api.exceptions.ProviderException
      The FileSystemProvider provides only one version.
      Specified by:
      getVersionHistory in interface org.apache.wiki.api.providers.PageProvider
      Throws:
      org.apache.wiki.api.exceptions.ProviderException
    • getProviderInfo

      Specified by:
      getProviderInfo in interface org.apache.wiki.api.providers.WikiProvider
    • deleteVersion

      public void deleteVersion(String pageName, int version) throws org.apache.wiki.api.exceptions.ProviderException
      Specified by:
      deleteVersion in interface org.apache.wiki.api.providers.PageProvider
      Throws:
      org.apache.wiki.api.exceptions.ProviderException
    • deletePage

      public void deletePage(String pageName) throws org.apache.wiki.api.exceptions.ProviderException
      Specified by:
      deletePage in interface org.apache.wiki.api.providers.PageProvider
      Throws:
      org.apache.wiki.api.exceptions.ProviderException
    • setCustomProperties

      protected void setCustomProperties(org.apache.wiki.api.core.Page page, Properties properties)
      Set the custom properties provided into the given page.
      Since:
      2.10.2
    • getCustomProperties

      protected void getCustomProperties(org.apache.wiki.api.core.Page page, Properties defaultProperties) throws IOException
      Get custom properties using addCustomProperties(Page, Properties), validate them using validateCustomPageProperties(Properties) and add them to default properties provided
      Throws:
      IOException
      Since:
      2.10.2
    • addCustomProperties

      protected Properties addCustomProperties(org.apache.wiki.api.core.Page page, 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(Properties customProperties) throws 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:
      IOException
      Since:
      2.10.2