Package org.apache.wiki.pages
Class DefaultPageManager
- java.lang.Object
-
- org.apache.wiki.pages.DefaultPageManager
-
- All Implemented Interfaces:
java.util.EventListener,WikiEventListener,PageManager
public class DefaultPageManager extends java.lang.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 protected java.util.concurrent.ConcurrentHashMap<java.lang.String,PageLock>m_pageLocks-
Fields inherited from interface org.apache.wiki.pages.PageManager
PROP_LOCKEXPIRY, PROP_PAGEPROVIDER
-
-
Constructor Summary
Constructors Constructor Description DefaultPageManager(Engine engine, java.util.Properties props)Creates a new PageManager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(WikiEvent event)Listens forWikiSecurityEvent.PROFILE_NAME_CHANGEDevents.protected booleanchangeAcl(Page page, java.security.Principal[] oldPrincipals, java.security.Principal newPrincipal)For a single wiki page, replaces all Acl entries matching a supplied array of Principals with a new Principal.voiddeletePage(java.lang.String pageName)Deletes a page or an attachment completely, including all versions.voiddeletePage(Page page)Deletes an entire page, all versions, all traces.voiddeleteVersion(Page page)Deletes only a specific version of a WikiPage.protected voidfireEvent(int type, java.lang.String pagename)Fires a WikiPageEvent of the provided type and page name to all registered listeners.java.util.List<PageLock>getActiveLocks()Returns a list of currently applicable locks.java.util.Collection<Page>getAllPages()Returns all pages in some random order.PageLockgetCurrentLock(Page page)Returns the current lock owner of a page.java.lang.StringgetCurrentProvider()Returns the provider name.protected EnginegetEngine()Returns the Engine to which this PageManager belongs to.PagegetPage(java.lang.String pagereq)Finds the corresponding WikiPage object based on the page name.PagegetPage(java.lang.String pagereq, int version)Finds the corresponding WikiPage object base on the page name and version.PagegetPageInfo(java.lang.String pageName, int version)Finds a WikiPage object describing a particular page and version.PageSortergetPageSorter()Returns the configuredPageSorter.java.lang.StringgetPageText(java.lang.String pageName, int version)Fetches the page text from the repository.PageProvidergetProvider()Returns the page provider currently in use.java.lang.StringgetProviderDescription()Returns a human-readable description of the current provider.java.lang.StringgetPureText(java.lang.String page, int version)Returns the pure text of a page, no conversions.java.util.Set<Page>getRecentChanges()Returns a Collection of WikiPages, sorted in time order of last change (i.e. first object is the most recently changed).java.lang.StringgetText(java.lang.String page, int version)Returns the un-HTMLized text of the given version of a page.intgetTotalPageCount()Returns the total count of all pages in the repository.<T extends Page>
java.util.List<T>getVersionHistory(java.lang.String pageName)Gets a version history of page.PageLocklockPage(Page page, java.lang.String user)Locks page for editing.booleanpageExists(java.lang.String pageName)Returns true, if the page exists (any version) on the underlying WikiPageProvider.booleanpageExists(java.lang.String pageName, int version)Checks for existence of a specific page and version on the underlying WikiPageProvider.voidputPageText(Page page, java.lang.String content)Puts the page text into the repository.voidsaveText(Context context, java.lang.String text)Writes the WikiText of a page into the page repository.voidunlockPage(PageLock lock)Marks a page free to be written again.booleanwikiPageExists(java.lang.String page)Returns true, if the requested page (or an alias) exists.booleanwikiPageExists(java.lang.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 Detail
-
m_pageLocks
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,PageLock> m_pageLocks
-
-
Constructor Detail
-
DefaultPageManager
public DefaultPageManager(Engine engine, java.util.Properties props) throws java.util.NoSuchElementException, WikiException
Creates a new PageManager.- Parameters:
engine- Engine instanceprops- Properties to use for initialization- Throws:
java.util.NoSuchElementException- "jspwiki.pageProvider" property not found on Engine propertiesWikiException- If anything goes wrong, you get this.
-
-
Method Detail
-
getProvider
public PageProvider getProvider()
Returns the page provider currently in use.- Specified by:
getProviderin interfacePageManager- Returns:
- A WikiPageProvider instance.
- See Also:
PageManager.getProvider()
-
getAllPages
public java.util.Collection<Page> getAllPages() throws ProviderException
Returns all pages in some random order. If you need just the page names, please seeReferenceManager#findCreated(), which is probably a lot faster. This method may cause repository access.- Specified by:
getAllPagesin interfacePageManager- Returns:
- A Collection of WikiPage objects.
- Throws:
ProviderException- If the backend has problems.- See Also:
PageManager.getAllPages()
-
getPageText
public java.lang.String getPageText(java.lang.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.- Specified by:
getPageTextin interfacePageManager- 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.- See Also:
PageManager.getPageText(java.lang.String, int)
-
getPureText
public java.lang.String getPureText(java.lang.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 toPageManager.getPageText(String, int), except that it doesn't throwProviderException, it logs and swallows them.- Specified by:
getPureTextin interfacePageManager- 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:
PageManager.getPureText(String, int)
-
getText
public java.lang.String getText(java.lang.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, usePageManager.getPureText(String, int).- Specified by:
getTextin interfacePageManager- Parameters:
page- WikiName of the page to fetchversion- Version of the page to fetch- Returns:
- WikiText.
- See Also:
PageManager.getText(String, int)
-
saveText
public void saveText(Context context, java.lang.String text) throws WikiException
Description copied from interface:PageManagerWrites the WikiText of a page into the page repository. If thejspwiki.propertiesfile contains the propertyjspwiki.approver.workflow.saveWikiPageand its value resolves to a valid user,GrouporRole, this method will place aDecisionin the approver's workflow inbox and throw aDecisionRequiredException. 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:
saveTextin interfacePageManager- Parameters:
context- The current WikiContexttext- The Wiki markup for the page.- Throws:
WikiException- if the save operation encounters an error during the save operation. If the page-save operation requires approval, the exception will be of typeDecisionRequiredException. Individual PageFilters, such as theSpamFiltermay also throw aRedirectException.
-
getEngine
protected Engine getEngine()
Returns the Engine to which this PageManager belongs to.- Returns:
- The Engine object.
-
putPageText
public void putPageText(Page page, java.lang.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 saveText()- Specified by:
putPageTextin interfacePageManager- Parameters:
page- Page to savecontent- Wikimarkup to save- Throws:
ProviderException- If something goes wrong in the saving phase- See Also:
PageManager.putPageText(org.apache.wiki.api.core.Page, java.lang.String)
-
lockPage
public PageLock lockPage(Page page, java.lang.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:
lockPagein interfacePageManager- Parameters:
page- WikiPage to lockuser- Username to use for locking- Returns:
- null, if page could not be locked.
- See Also:
PageManager.lockPage(org.apache.wiki.api.core.Page, java.lang.String)
-
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:
unlockPagein interfacePageManager- Parameters:
lock- A lock acquired in lockPage(). Safe to be null.- See Also:
PageManager.unlockPage(org.apache.wiki.pages.PageLock)
-
getCurrentLock
public PageLock getCurrentLock(Page page)
Returns the current lock owner of a page. If the page is not locked, will return null.- Specified by:
getCurrentLockin interfacePageManager- Parameters:
page- The page to check the lock for- Returns:
- Current lock, or null, if there is no lock
- See Also:
PageManager.getCurrentLock(org.apache.wiki.api.core.Page)
-
getActiveLocks
public java.util.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.- Specified by:
getActiveLocksin interfacePageManager- Returns:
- List of PageLock objects, detailing the locks. If no locks exist, returns an empty list.
- See Also:
PageManager.getActiveLocks()
-
getPage
public Page getPage(java.lang.String pagereq)
Finds the corresponding WikiPage object based on the page name. It always finds the latest version of a page.- Specified by:
getPagein interfacePageManager- 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:
PageManager.getPage(java.lang.String)
-
getPage
public Page getPage(java.lang.String pagereq, int version)
Finds the corresponding WikiPage object base on the page name and version.- Specified by:
getPagein interfacePageManager- 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:
PageManager.getPage(java.lang.String, int)
-
getPageInfo
public Page getPageInfo(java.lang.String pageName, int version) throws ProviderException
Finds a WikiPage object describing a particular page and version.- Specified by:
getPageInfoin interfacePageManager- Parameters:
pageName- The name of the pageversion- 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- See Also:
PageManager.getPageInfo(java.lang.String, int)
-
getVersionHistory
public <T extends Page> java.util.List<T> getVersionHistory(java.lang.String pageName)
Gets a version history of page. Each element in the returned List is a WikiPage.- Specified by:
getVersionHistoryin interfacePageManager- 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:
PageManager.getVersionHistory(java.lang.String)
-
getCurrentProvider
public java.lang.String getCurrentProvider()
Returns the provider name.- Specified by:
getCurrentProviderin interfacePageManager- Returns:
- The full class name of the current page provider.
- See Also:
PageManager.getCurrentProvider()
-
getProviderDescription
public java.lang.String getProviderDescription()
Returns a human-readable description of the current provider.- Specified by:
getProviderDescriptionin interfacePageManager- Returns:
- A human-readable description.
- See Also:
PageManager.getProviderDescription()
-
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:
getTotalPageCountin interfacePageManager- Returns:
- The number of pages, or -1, if there is an error.
- See Also:
PageManager.getTotalPageCount()
-
getRecentChanges
public java.util.Set<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:
getRecentChangesin interfacePageManager- Returns:
- Set of WikiPage objects.
- See Also:
PageManager.getRecentChanges()
-
pageExists
public boolean pageExists(java.lang.String pageName) throws ProviderException
Returns true, if the page exists (any version) on the underlying WikiPageProvider.- Specified by:
pageExistsin interfacePageManager- 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.- See Also:
PageManager.pageExists(java.lang.String)
-
pageExists
public boolean pageExists(java.lang.String pageName, int version) throws ProviderException
Checks for existence of a specific page and version on the underlying WikiPageProvider.- Specified by:
pageExistsin interfacePageManager- Parameters:
pageName- Name of the pageversion- The version to check- Returns:
trueif the page exists,falseotherwise- Throws:
ProviderException- If backend fails or name is illegal- See Also:
PageManager.pageExists(java.lang.String, int)
-
wikiPageExists
public boolean wikiPageExists(java.lang.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:
wikiPageExistsin interfacePageManager- Parameters:
page- WikiName of the page.- Returns:
- true, if page (or attachment) exists.
- See Also:
PageManager.wikiPageExists(java.lang.String)
-
wikiPageExists
public boolean wikiPageExists(java.lang.String page, int version) throws 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:
wikiPageExistsin interfacePageManager- Parameters:
page- Page nameversion- Page version- Returns:
- True, if page (or alias, or attachment) exists
- Throws:
ProviderException- If the provider fails.- See Also:
PageManager.wikiPageExists(java.lang.String, int)
-
deleteVersion
public void deleteVersion(Page page) throws ProviderException
Deletes only a specific version of a WikiPage.- Specified by:
deleteVersionin interfacePageManager- Parameters:
page- The page to delete.- Throws:
ProviderException- if the page fails- See Also:
PageManager.deleteVersion(org.apache.wiki.api.core.Page)
-
deletePage
public void deletePage(java.lang.String pageName) throws ProviderException
Deletes a page or an attachment completely, including all versions. If the page does not exist, does nothing.- Specified by:
deletePagein interfacePageManager- Parameters:
pageName- The name of the page.- Throws:
ProviderException- If something goes wrong.- See Also:
PageManager.deletePage(java.lang.String)
-
deletePage
public void deletePage(Page page) throws ProviderException
Deletes an entire page, all versions, all traces.- Specified by:
deletePagein interfacePageManager- Parameters:
page- The WikiPage to delete- Throws:
ProviderException- If the repository operation fails- See Also:
PageManager.deletePage(org.apache.wiki.api.core.Page)
-
fireEvent
protected final void fireEvent(int type, java.lang.String pagename)
Fires a WikiPageEvent of the provided type and page name to all registered listeners.- Parameters:
type- the event type to be firedpagename- the wiki page name as a String- See Also:
WikiPageEvent
-
actionPerformed
public void actionPerformed(WikiEvent event)
Listens forWikiSecurityEvent.PROFILE_NAME_CHANGEDevents. 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:
actionPerformedin interfaceWikiEventListener- Parameters:
event- The event
-
changeAcl
protected boolean changeAcl(Page page, java.security.Principal[] oldPrincipals, java.security.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 modifiedoldPrincipals- an array of Principals to replace; all AclEntry objects whoseAclEntry.getPrincipal()method returns one of these Principals will be replacednewPrincipal- the Principal that should receive the old Principals' permissions- Returns:
trueif the Acl was actually changed;falseotherwise
-
getPageSorter
public PageSorter getPageSorter()
Returns the configuredPageSorter.- Specified by:
getPageSorterin interfacePageManager- Returns:
- the configured
PageSorter. - See Also:
PageManager.getPageSorter()
-
-