Class DefaultPageManager

java.lang.Object
org.apache.wiki.pages.DefaultPageManager
All Implemented Interfaces:
EventListener, org.apache.wiki.event.WikiEventListener, PageManager

public class DefaultPageManager extends Object implements PageManager
Manages the WikiPages. This class functions as an unified interface towards the page providers. It handles initialization and management of the providers, and provides utility methods for accessing the contents.

Saving a page is a two-stage Task; first the pre-save operations and then the actual save. See the descriptions of the tasks for further information.

Since:
2.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     

    Fields inherited from interface org.apache.wiki.pages.PageManager

    PROP_LOCKEXPIRY, PROP_PAGEPROVIDER
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultPageManager(org.apache.wiki.api.core.Engine engine, Properties props)
    Creates a new PageManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    actionPerformed(org.apache.wiki.event.WikiEvent event)
    Listens for WikiSecurityEvent.PROFILE_NAME_CHANGED events.
    protected boolean
    changeAcl(org.apache.wiki.api.core.Page page, Principal[] oldPrincipals, Principal newPrincipal)
    For a single wiki page, replaces all Acl entries matching a supplied array of Principals with a new Principal.
    void
    deletePage(String pageName)
    Deletes a page or an attachment completely, including all versions.
    void
    deletePage(org.apache.wiki.api.core.Page page)
    Deletes an entire page, all versions, all traces.
    void
    deleteVersion(org.apache.wiki.api.core.Page page)
    Deletes only a specific version of a WikiPage.
    protected final void
    fireEvent(int type, String pagename)
    Fires a WikiPageEvent of the provided type and page name to all registered listeners.
    Returns a list of currently applicable locks.
    Collection<org.apache.wiki.api.core.Page>
    Returns all pages in some random order.
    getCurrentLock(org.apache.wiki.api.core.Page page)
    Returns the current lock owner of a page.
    Returns the provider name.
    protected org.apache.wiki.api.core.Engine
    Returns the Engine to which this PageManager belongs to.
    org.apache.wiki.api.core.Page
    getPage(String pagereq)
    Finds the corresponding WikiPage object based on the page name.
    org.apache.wiki.api.core.Page
    getPage(String pagereq, int version)
    Finds the corresponding WikiPage object base on the page name and version.
    org.apache.wiki.api.core.Page
    getPageInfo(String pageName, int version)
    Finds a WikiPage object describing a particular page and version.
    Returns the configured PageSorter.
    getPageText(String pageName, int version)
    Fetches the page text from the repository.
    org.apache.wiki.api.providers.PageProvider
    Returns the page provider currently in use.
    Returns a human-readable description of the current provider.
    getPureText(String page, int version)
    Returns the pure text of a page, no conversions.
    Set<org.apache.wiki.api.core.Page>
    Returns a Collection of WikiPages, sorted in time order of last change (i.e. first object is the most recently changed).
    getText(String page, int version)
    Returns the un-HTMLized text of the given version of a page.
    int
    Returns the total count of all pages in the repository.
    <T extends org.apache.wiki.api.core.Page>
    List<T>
    Gets a version history of page.
    lockPage(org.apache.wiki.api.core.Page page, String user)
    Locks page for editing.
    boolean
    pageExists(String pageName)
    Returns true, if the page exists (any version) on the underlying WikiPageProvider.
    boolean
    pageExists(String pageName, int version)
    Checks for existence of a specific page and version on the underlying WikiPageProvider.
    void
    putPageText(org.apache.wiki.api.core.Page page, String content)
    Puts the page text into the repository.
    void
    saveText(org.apache.wiki.api.core.Context context, String text)
    Writes the WikiText of a page into the page repository.
    void
    Marks a page free to be written again.
    boolean
    Returns true, if the requested page (or an alias) exists.
    boolean
    wikiPageExists(String page, int version)
    Returns true, if the requested page (or an alias) exists with the requested version.

    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.pages.PageManager

    getPureText, getText, getText, pageExists, wikiPageExists
  • Field Details

  • Constructor Details

    • DefaultPageManager

      public DefaultPageManager(org.apache.wiki.api.core.Engine engine, Properties props) throws NoSuchElementException, org.apache.wiki.api.exceptions.WikiException
      Creates a new PageManager.
      Parameters:
      engine - Engine instance
      props - Properties to use for initialization
      Throws:
      NoSuchElementException - "jspwiki.pageProvider" property not found on Engine properties
      org.apache.wiki.api.exceptions.WikiException - If anything goes wrong, you get this.
  • Method Details

    • getProvider

      public org.apache.wiki.api.providers.PageProvider getProvider()
      Returns the page provider currently in use.
      Specified by:
      getProvider in interface PageManager
      Returns:
      A WikiPageProvider instance.
      See Also:
    • getAllPages

      public Collection<org.apache.wiki.api.core.Page> getAllPages() throws org.apache.wiki.api.exceptions.ProviderException
      Returns all pages in some random order. If you need just the page names, please see ReferenceManager#findCreated(), which is probably a lot faster. This method may cause repository access.
      Specified by:
      getAllPages in interface PageManager
      Returns:
      A Collection of WikiPage objects.
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If the backend has problems.
      See Also:
    • getPageText

      public String getPageText(String pageName, int version) throws org.apache.wiki.api.exceptions.ProviderException
      Fetches the page text from the repository. This method also does some sanity checks, like checking for the pageName validity, etc. Also, if the page repository has been modified externally, it is smart enough to handle such occurrences.
      Specified by:
      getPageText in interface PageManager
      Parameters:
      pageName - The name of the page to fetch.
      version - The version to find
      Returns:
      The page content as a raw string
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If the backend has issues.
      See Also:
    • getPureText

      public String getPureText(String page, int version)
      Returns the pure text of a page, no conversions. Use this if you are writing something that depends on the parsing of the page. Note that you should always check for page existence through pageExists() before attempting to fetch the page contents. This method is pretty similar to PageManager.getPageText(String, int), except that it doesn't throw ProviderException, it logs and swallows them.
      Specified by:
      getPureText in interface PageManager
      Parameters:
      page - The name of the page to fetch.
      version - If WikiPageProvider.LATEST_VERSION, then uses the latest version.
      Returns:
      The page contents. If the page does not exist, returns an empty string.
      See Also:
    • getText

      public String getText(String page, int version)
      Returns the un-HTMLized text of the given version of a page. This method also replaces the < and & -characters with their respective HTML entities, thus making it suitable for inclusion on an HTML page. If you want to have the page text without any conversions, use PageManager.getPureText(String, int).
      Specified by:
      getText in interface PageManager
      Parameters:
      page - WikiName of the page to fetch
      version - Version of the page to fetch
      Returns:
      WikiText.
      See Also:
    • saveText

      public void saveText(org.apache.wiki.api.core.Context context, String text) throws org.apache.wiki.api.exceptions.WikiException
      Description copied from interface: PageManager
      Writes the WikiText of a page into the page repository. If the jspwiki.properties file contains the property jspwiki.approver.workflow.saveWikiPage and its value resolves to a valid user, Group or Role, this method will place a Decision in the approver's workflow inbox and throw a DecisionRequiredException. If the submitting user is authenticated and the page save is rejected, a notification will be placed in the user's decision queue.
      Specified by:
      saveText in interface PageManager
      Parameters:
      context - The current WikiContext
      text - The Wiki markup for the page.
      Throws:
      org.apache.wiki.api.exceptions.WikiException - if the save operation encounters an error during the save operation. If the page-save operation requires approval, the exception will be of type DecisionRequiredException. Individual PageFilters, such as the SpamFilter may also throw a RedirectException.
    • getEngine

      protected org.apache.wiki.api.core.Engine getEngine()
      Returns the Engine to which this PageManager belongs to.
      Returns:
      The Engine object.
    • putPageText

      public void putPageText(org.apache.wiki.api.core.Page page, String content) throws org.apache.wiki.api.exceptions.ProviderException
      Puts the page text into the repository. Note that this method does NOT update JSPWiki internal data structures, and therefore you should always use saveText()
      Specified by:
      putPageText in interface PageManager
      Parameters:
      page - Page to save
      content - Wikimarkup to save
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If something goes wrong in the saving phase
      See Also:
    • lockPage

      public PageLock lockPage(org.apache.wiki.api.core.Page page, String user)
      Locks page for editing. Note, however, that the PageManager will in no way prevent you from actually editing this page; the lock is just for information.
      Specified by:
      lockPage in interface PageManager
      Parameters:
      page - WikiPage to lock
      user - Username to use for locking
      Returns:
      null, if page could not be locked.
      See Also:
    • unlockPage

      public void unlockPage(PageLock lock)
      Marks a page free to be written again. If there has not been a lock, will fail quietly.
      Specified by:
      unlockPage in interface PageManager
      Parameters:
      lock - A lock acquired in lockPage(). Safe to be null.
      See Also:
    • getCurrentLock

      public PageLock getCurrentLock(org.apache.wiki.api.core.Page page)
      Returns the current lock owner of a page. If the page is not locked, will return null.
      Specified by:
      getCurrentLock in interface PageManager
      Parameters:
      page - The page to check the lock for
      Returns:
      Current lock, or null, if there is no lock
      See Also:
    • getActiveLocks

      Returns a list of currently applicable locks. Note that by the time you get the list, the locks may have already expired, so use this only for informational purposes.
      Specified by:
      getActiveLocks in interface PageManager
      Returns:
      List of PageLock objects, detailing the locks. If no locks exist, returns an empty list.
      See Also:
    • getPage

      public org.apache.wiki.api.core.Page getPage(String pagereq)
      Finds the corresponding WikiPage object based on the page name. It always finds the latest version of a page.
      Specified by:
      getPage in interface PageManager
      Parameters:
      pagereq - The name of the page to look for.
      Returns:
      A WikiPage object, or null, if the page by the name could not be found.
      See Also:
    • getPage

      public org.apache.wiki.api.core.Page getPage(String pagereq, int version)
      Finds the corresponding WikiPage object base on the page name and version.
      Specified by:
      getPage in interface PageManager
      Parameters:
      pagereq - The name of the page to look for.
      version - The version number to look for. May be WikiProvider.LATEST_VERSION, in which case it will look for the latest version (and this method then becomes the equivalent of getPage(String).
      Returns:
      A WikiPage object, or null, if the page could not be found; or if there is no such version of the page.
      See Also:
    • getPageInfo

      public org.apache.wiki.api.core.Page getPageInfo(String pageName, int version) throws org.apache.wiki.api.exceptions.ProviderException
      Finds a WikiPage object describing a particular page and version.
      Specified by:
      getPageInfo in interface PageManager
      Parameters:
      pageName - The name of the page
      version - A version number
      Returns:
      A WikiPage object, or null, if the page does not exist
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If there is something wrong with the page name or the repository
      See Also:
    • getVersionHistory

      public <T extends org.apache.wiki.api.core.Page> List<T> getVersionHistory(String pageName)
      Gets a version history of page. Each element in the returned List is a WikiPage.
      Specified by:
      getVersionHistory in interface PageManager
      Parameters:
      pageName - The name of the page or attachment to fetch history for
      Returns:
      If the page does not exist or there's some problem retrieving the version history, returns null, otherwise a List of WikiPages / Attachments, each corresponding to a different revision of the page / attachment.
      See Also:
    • getCurrentProvider

      Returns the provider name.
      Specified by:
      getCurrentProvider in interface PageManager
      Returns:
      The full class name of the current page provider.
      See Also:
    • getProviderDescription

      Returns a human-readable description of the current provider.
      Specified by:
      getProviderDescription in interface PageManager
      Returns:
      A human-readable description.
      See Also:
    • getTotalPageCount

      public int getTotalPageCount()
      Returns the total count of all pages in the repository. This method is equivalent of calling getAllPages().size(), but it swallows the ProviderException and returns -1 instead of any problems.
      Specified by:
      getTotalPageCount in interface PageManager
      Returns:
      The number of pages, or -1, if there is an error.
      See Also:
    • getRecentChanges

      public Set<org.apache.wiki.api.core.Page> getRecentChanges()
      Returns a Collection of WikiPages, sorted in time order of last change (i.e. first object is the most recently changed). This method also includes attachments.
      Specified by:
      getRecentChanges in interface PageManager
      Returns:
      Set of WikiPage objects.
      See Also:
    • pageExists

      public boolean pageExists(String pageName) throws org.apache.wiki.api.exceptions.ProviderException
      Returns true, if the page exists (any version) on the underlying WikiPageProvider.
      Specified by:
      pageExists in interface PageManager
      Parameters:
      pageName - Name of the page.
      Returns:
      A boolean value describing the existence of a page
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If the backend fails or the name is illegal.
      See Also:
    • pageExists

      public boolean pageExists(String pageName, int version) throws org.apache.wiki.api.exceptions.ProviderException
      Checks for existence of a specific page and version on the underlying WikiPageProvider.
      Specified by:
      pageExists in interface PageManager
      Parameters:
      pageName - Name of the page
      version - The version to check
      Returns:
      true if the page exists, false otherwise
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If backend fails or name is illegal
      See Also:
    • wikiPageExists

      public boolean wikiPageExists(String page)
      Returns true, if the requested page (or an alias) exists. Will consider any version as existing. Will check for all types of WikiPages: wiki pages themselves, attachments and special pages (non-existant references to other pages).
      Specified by:
      wikiPageExists in interface PageManager
      Parameters:
      page - WikiName of the page.
      Returns:
      true, if page (or attachment) exists.
      See Also:
    • wikiPageExists

      public boolean wikiPageExists(String page, int version) throws org.apache.wiki.api.exceptions.ProviderException
      Returns true, if the requested page (or an alias) exists with the requested version. Will check for all types of WikiPages: wiki pages themselves, attachments and special pages (non-existant references to other pages).
      Specified by:
      wikiPageExists in interface PageManager
      Parameters:
      page - Page name
      version - Page version
      Returns:
      True, if page (or alias, or attachment) exists
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If the provider fails.
      See Also:
    • deleteVersion

      public void deleteVersion(org.apache.wiki.api.core.Page page) throws org.apache.wiki.api.exceptions.ProviderException
      Deletes only a specific version of a WikiPage.
      Specified by:
      deleteVersion in interface PageManager
      Parameters:
      page - The page to delete.
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - if the page fails
      See Also:
    • deletePage

      public void deletePage(String pageName) throws org.apache.wiki.api.exceptions.ProviderException
      Deletes a page or an attachment completely, including all versions. If the page does not exist, does nothing.
      Specified by:
      deletePage in interface PageManager
      Parameters:
      pageName - The name of the page.
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If something goes wrong.
      See Also:
    • deletePage

      public void deletePage(org.apache.wiki.api.core.Page page) throws org.apache.wiki.api.exceptions.ProviderException
      Deletes an entire page, all versions, all traces.
      Specified by:
      deletePage in interface PageManager
      Parameters:
      page - The WikiPage to delete
      Throws:
      org.apache.wiki.api.exceptions.ProviderException - If the repository operation fails
      See Also:
    • fireEvent

      protected final void fireEvent(int type, String pagename)
      Fires a WikiPageEvent of the provided type and page name to all registered listeners.
      Parameters:
      type - the event type to be fired
      pagename - the wiki page name as a String
      See Also:
      • WikiPageEvent
    • actionPerformed

      public void actionPerformed(org.apache.wiki.event.WikiEvent event)
      Listens for WikiSecurityEvent.PROFILE_NAME_CHANGED events. If a user profile's name changes, each page ACL is inspected. If an entry contains a name that has changed, it is replaced with the new one. No events are emitted as a consequence of this method, because the page contents are still the same; it is only the representations of the names within the ACL that are changing.
      Specified by:
      actionPerformed in interface org.apache.wiki.event.WikiEventListener
      Parameters:
      event - The event
    • changeAcl

      protected boolean changeAcl(org.apache.wiki.api.core.Page page, Principal[] oldPrincipals, Principal newPrincipal)
      For a single wiki page, replaces all Acl entries matching a supplied array of Principals with a new Principal.
      Parameters:
      page - the wiki page whose Acl is to be modified
      oldPrincipals - an array of Principals to replace; all AclEntry objects whose AclEntry.getPrincipal() method returns one of these Principals will be replaced
      newPrincipal - the Principal that should receive the old Principals' permissions
      Returns:
      true if the Acl was actually changed; false otherwise
    • getPageSorter

      Returns the configured PageSorter.
      Specified by:
      getPageSorter in interface PageManager
      Returns:
      the configured PageSorter.
      See Also: