org.apache.wiki
Class PageManager

java.lang.Object
  extended by org.apache.wiki.modules.ModuleManager
      extended by org.apache.wiki.PageManager
All Implemented Interfaces:
EventListener, WikiEventListener

public class PageManager
extends ModuleManager
implements WikiEventListener

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

Nested Class Summary
static class PageManager.PreSaveWikiPageTask
          Inner class that handles the page pre-save actions.
static class PageManager.SaveWikiPageTask
          Inner class that handles the actual page save and post-save actions.
 
Field Summary
static String FACT_CURRENT_TEXT
          Fact name for storing the current text.
static String FACT_DIFF_TEXT
          Fact name for storing a diff text.
static String FACT_IS_AUTHENTICATED
          Fact name for storing whether the user is authenticated or not.
static String FACT_PAGE_NAME
          Fact name for storing the page name.
static String FACT_PROPOSED_TEXT
          Fact name for storing the proposed (edited) text.
protected  HashMap<String,PageLock> m_pageLocks
           
static String PRESAVE_TASK_MESSAGE_KEY
          The message key for storing the text for the presave task.
static String PRESAVE_WIKI_CONTEXT
          The workflow attribute which stores the wikiContext.
static String PROP_LOCKEXPIRY
          The property value for setting the amount of time before the page locks expire.
static String PROP_PAGEPROVIDER
          The property value for setting the current page provider.
static String PROP_USECACHE
          The property value for setting the cache on/off.
static String SAVE_APPROVER
          The name of the key from jspwiki.properties which defines who shall approve the workflow of storing a wikipage.
static String SAVE_DECISION_MESSAGE_KEY
          The message key for storing the Decision text for saving a page.
static String SAVE_REJECT_MESSAGE_KEY
          The message key for rejecting the decision to save the page.
static String SAVE_TASK_MESSAGE_KEY
          The message key of the text to finally approve a page save.
 
Fields inherited from class org.apache.wiki.modules.ModuleManager
PLUGIN_RESOURCE_LOCATION
 
Constructor Summary
PageManager(WikiEngine engine, Properties props)
          Creates a new PageManager.
 
Method Summary
 void actionPerformed(WikiEvent event)
          Listens for WikiSecurityEvent.PROFILE_NAME_CHANGED events.
protected  boolean changeAcl(WikiPage 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(WikiPage page)
          Deletes an entire page, all versions, all traces.
 void deleteVersion(WikiPage page)
          Deletes only a specific version of a WikiPage.
protected  void fireEvent(int type, String pagename)
          Fires a WikiPageEvent of the provided type and page name to all registered listeners.
 List<PageLock> getActiveLocks()
          Returns a list of currently applicable locks.
 Collection getAllPages()
          Returns all pages in some random order.
 PageLock getCurrentLock(WikiPage page)
          Returns the current lock owner of a page.
 WikiEngine getEngine()
          Returns the WikiEngine to which this PageManager belongs to.
 WikiPage getPageInfo(String pageName, int version)
          Finds a WikiPage object describing a particular page and version.
 String getPageText(String pageName, int version)
          Fetches the page text from the repository.
 WikiPageProvider getProvider()
          Returns the page provider currently in use.
 String getProviderDescription()
          Returns a human-readable description of the current provider.
 int getTotalPageCount()
          Returns the total count of all pages in the repository.
 List getVersionHistory(String pageName)
          Gets a version history of page.
 PageLock lockPage(WikiPage page, String user)
          Locks page for editing.
 Collection modules()
          Returns a collection of modules currently managed by this ModuleManager.
 boolean pageExists(String pageName)
          Returns true, if the page exists (any version).
 boolean pageExists(String pageName, int version)
          Checks for existence of a specific page and version.
 void putPageText(WikiPage page, String content)
          Puts the page text into the repository.
 void unlockPage(PageLock lock)
          Marks a page free to be written again.
 
Methods inherited from class org.apache.wiki.modules.ModuleManager
checkCompatibility
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_PAGEPROVIDER

public static final String PROP_PAGEPROVIDER
The property value for setting the current page provider. Value is "jspwiki.pageProvider".

See Also:
Constant Field Values

PROP_USECACHE

public static final String PROP_USECACHE
The property value for setting the cache on/off. Value is "jspwiki.usePageCache".

See Also:
Constant Field Values

PROP_LOCKEXPIRY

public static final String PROP_LOCKEXPIRY
The property value for setting the amount of time before the page locks expire. Value is "jspwiki.lockExpiryTime".

See Also:
Constant Field Values

PRESAVE_TASK_MESSAGE_KEY

public static final String PRESAVE_TASK_MESSAGE_KEY
The message key for storing the text for the presave task. Value is "task.preSaveWikiPage"

See Also:
Constant Field Values

PRESAVE_WIKI_CONTEXT

public static final String PRESAVE_WIKI_CONTEXT
The workflow attribute which stores the wikiContext.

See Also:
Constant Field Values

SAVE_APPROVER

public static final String SAVE_APPROVER
The name of the key from jspwiki.properties which defines who shall approve the workflow of storing a wikipage. Value is "workflow.saveWikiPage"

See Also:
Constant Field Values

SAVE_DECISION_MESSAGE_KEY

public static final String SAVE_DECISION_MESSAGE_KEY
The message key for storing the Decision text for saving a page. Value is "decision.saveWikiPage".

See Also:
Constant Field Values

SAVE_REJECT_MESSAGE_KEY

public static final String SAVE_REJECT_MESSAGE_KEY
The message key for rejecting the decision to save the page. Value is "notification.saveWikiPage.reject".

See Also:
Constant Field Values

SAVE_TASK_MESSAGE_KEY

public static final String SAVE_TASK_MESSAGE_KEY
The message key of the text to finally approve a page save. Value is "task.saveWikiPage".

See Also:
Constant Field Values

FACT_PAGE_NAME

public static final String FACT_PAGE_NAME
Fact name for storing the page name. Value is "fact.pageName".

See Also:
Constant Field Values

FACT_DIFF_TEXT

public static final String FACT_DIFF_TEXT
Fact name for storing a diff text. Value is "fact.diffText".

See Also:
Constant Field Values

FACT_CURRENT_TEXT

public static final String FACT_CURRENT_TEXT
Fact name for storing the current text. Value is "fact.currentText".

See Also:
Constant Field Values

FACT_PROPOSED_TEXT

public static final String FACT_PROPOSED_TEXT
Fact name for storing the proposed (edited) text. Value is "fact.proposedText".

See Also:
Constant Field Values

FACT_IS_AUTHENTICATED

public static final String FACT_IS_AUTHENTICATED
Fact name for storing whether the user is authenticated or not. Value is "fact.isAuthenticated".

See Also:
Constant Field Values

m_pageLocks

protected HashMap<String,PageLock> m_pageLocks
Constructor Detail

PageManager

public PageManager(WikiEngine engine,
                   Properties props)
            throws WikiException
Creates a new PageManager.

Parameters:
engine - WikiEngine instance
props - Properties to use for initialization
Throws:
WikiException - If anything goes wrong, you get this.
Method Detail

getProvider

public WikiPageProvider getProvider()
Returns the page provider currently in use.

Returns:
A WikiPageProvider instance.

getAllPages

public Collection getAllPages()
                       throws 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.

Returns:
A Collection of WikiPage objects.
Throws:
ProviderException - If the backend has problems.

getPageText

public String getPageText(String pageName,
                          int version)
                   throws 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.

Parameters:
pageName - The name of the page to fetch.
version - The version to find
Returns:
The page content as a raw string
Throws:
ProviderException - If the backend has issues.

getEngine

public WikiEngine getEngine()
Returns the WikiEngine to which this PageManager belongs to.

Returns:
The WikiEngine object.

putPageText

public void putPageText(WikiPage page,
                        String content)
                 throws 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 WikiEngine.saveText()

Parameters:
page - Page to save
content - Wikimarkup to save
Throws:
ProviderException - If something goes wrong in the saving phase

lockPage

public PageLock lockPage(WikiPage 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.

Parameters:
page - WikiPage to lock
user - Username to use for locking
Returns:
null, if page could not be locked.

unlockPage

public void unlockPage(PageLock lock)
Marks a page free to be written again. If there has not been a lock, will fail quietly.

Parameters:
lock - A lock acquired in lockPage(). Safe to be null.

getCurrentLock

public PageLock getCurrentLock(WikiPage page)
Returns the current lock owner of a page. If the page is not locked, will return null.

Parameters:
page - The page to check the lock for
Returns:
Current lock, or null, if there is no lock

getActiveLocks

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

Returns:
List of PageLock objects, detailing the locks. If no locks exist, returns an empty list.
Since:
2.0.22.

getPageInfo

public WikiPage getPageInfo(String pageName,
                            int version)
                     throws ProviderException
Finds a WikiPage object describing a particular page and version.

Parameters:
pageName - The name of the page
version - A version number
Returns:
A WikiPage object, or null, if the page does not exist
Throws:
ProviderException - If there is something wrong with the page name or the repository

getVersionHistory

public List getVersionHistory(String pageName)
                       throws ProviderException
Gets a version history of page. Each element in the returned List is a WikiPage.

Parameters:
pageName - The name of the page to fetch history for
Returns:
If the page does not exist, returns null, otherwise a List of WikiPages.
Throws:
ProviderException - If the repository fails.

getProviderDescription

public String getProviderDescription()
Returns a human-readable description of the current provider.

Returns:
A human-readable description.

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.

Returns:
The number of pages, or -1, if there is an error.

pageExists

public boolean pageExists(String pageName)
                   throws ProviderException
Returns true, if the page exists (any version).

Parameters:
pageName - Name of the page.
Returns:
A boolean value describing the existence of a page
Throws:
ProviderException - If the backend fails or the name is illegal.

pageExists

public boolean pageExists(String pageName,
                          int version)
                   throws ProviderException
Checks for existence of a specific page and version.

Parameters:
pageName - Name of the page
version - The version to check
Returns:
true if the page exists, false otherwise
Throws:
ProviderException - If backend fails or name is illegal
Since:
2.3.29

deleteVersion

public void deleteVersion(WikiPage page)
                   throws ProviderException
Deletes only a specific version of a WikiPage.

Parameters:
page - The page to delete.
Throws:
ProviderException - if the page fails

deletePage

public void deletePage(WikiPage page)
                throws ProviderException
Deletes an entire page, all versions, all traces.

Parameters:
page - The WikiPage to delete
Throws:
ProviderException - If the repository operation fails

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

modules

public Collection modules()
Returns a collection of modules currently managed by this ModuleManager. Each entry is an instance of the WikiModuleInfo class. This method should return something which is safe to iterate over, even if the underlying collection changes.

Specified by:
modules in class ModuleManager
Returns:
A Collection of WikiModuleInfo instances.

actionPerformed

public void actionPerformed(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 WikiEventListener
Parameters:
event - The event

changeAcl

protected boolean changeAcl(WikiPage 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


Copyright © {inceptionYear}-2014 The Apache Software Foundation. All rights reserved.