public class ReferenceManager extends BasicPageFilter implements InternalModule, WikiEventListener
This class contains two HashMaps, m_refersTo and m_referredBy. The first is indexed by WikiPage names and contains a Collection of all WikiPages the page refers to. (Multiple references are not counted, naturally.) The second is indexed by WikiPage names and contains a Set of all pages that refer to the indexing page. (Notice - the keys of both Maps should be kept in sync.)
When a page is added or edited, its references are parsed, a Collection is received, and we crudely replace anything previous with this new Collection. We then check each referenced page name and make sure they know they are referred to by the new page.
Based on this information, we can perform non-optimal searches for e.g. unreferenced pages, top ten lists, etc.
The owning class must take responsibility of filling in any pre-existing information, probably by loading each and every WikiPage and calling this class to update the references when created.
Constructor and Description |
---|
ReferenceManager(WikiEngine engine)
Builds a new ReferenceManager.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(WikiEvent event)
Fired when a WikiEvent is triggered by an event source.
|
void |
clearPageEntries(String pagename)
Clears the references to a certain page so it's no longer in the map.
|
int |
deepHashCode()
This 'deepHashCode' can be used to determine if there were any
modifications made to the underlying to and by maps of the
ReferenceManager.
|
Set |
findCreated()
Returns a list of all pages that the ReferenceManager knows about.
|
Set |
findReferredBy(String pageName)
Returns all pages that refer to this page.
|
Collection |
findReferrers(String pagename)
Find all pages that refer to this page.
|
Collection |
findRefersTo(String pageName)
Returns all pages that this page refers to.
|
Collection |
findUncreated()
Finds all references to non-existant pages.
|
Collection |
findUnreferenced()
Finds all unreferenced pages.
|
protected Map |
getReferredBy()
Returns the referred-by list.
|
protected Map |
getRefersTo()
Returns the refers-to list.
|
void |
initialize(Collection pages)
Initializes the entire reference manager with the initial set of pages
from the collection.
|
void |
pageRemoved(WikiPage page)
Updates the m_referedTo and m_referredBy hashmaps when a page has been
deleted.
|
void |
postSave(WikiContext context,
String content)
After the page has been saved, updates the reference lists.
|
void |
updateReferences(String page,
Collection<String> references)
Updates the referred pages of a new or edited WikiPage.
|
destroy, initialize, postTranslate, preSave, preTranslate
public ReferenceManager(WikiEngine engine)
engine
- The WikiEngine to which this is managing references to.public void initialize(Collection pages) throws ProviderException
pages
- A collection of all pages you want to be included in the reference
count.ProviderException
- If reading of pages fail.public void postSave(WikiContext context, String content)
postSave
in interface PageFilter
postSave
in class BasicPageFilter
context
- The WikiContextcontent
- The content which was just stored.public void pageRemoved(WikiPage page)
Within the m_refersTo map the pagename is a key. The whole key-value-set has to be removed to keep the map clean. Within the m_referredBy map the name is stored as a value. Since a key can have more than one value we have to delete just the key-value-pair referring page:deleted page.
page
- Name of the page to remove from the maps.public void updateReferences(String page, Collection<String> references)
This is the method to call when a new page has been created and we want to a) set up its references and b) notify the referred pages of the references. Use this method during run-time.
page
- Name of the page to update.references
- A Collection of Strings, each one pointing to a page this page references.protected Map getRefersTo()
protected Map getReferredBy()
public void clearPageEntries(String pagename)
pagename
- Name of the page to clear references for.public Collection findUnreferenced()
public Collection findUncreated()
Returns a Collection containing Strings of unreferenced page names. Each non-existant page name is shown only once - we don't return information on who referred to it.
public Collection findReferrers(String pagename)
pagename
- The page to find referrers for.public Set findReferredBy(String pageName)
The advantages of using this method over findReferrers() is that it is very fast, as it does not create a new object. The disadvantages are that it does not do any mapping between plural names, and you may end up getting a ConcurrentModificationException.
pageName
- Page name to query.public Collection findRefersTo(String pageName)
The Collection returned is unmutable, so you cannot change it. It does reflect the current status and thus is a live object. So, if you are using any kind of an iterator on it, be prepared for ConcurrentModificationExceptions.
The returned value is a Collection, because a page may refer to another page multiple times.
pageName
- Page name to querypublic int deepHashCode()
public Set findCreated()
public void actionPerformed(WikiEvent event)
actionPerformed
in interface WikiEventListener
event
- a WikiEvent objectCopyright © 2001-2018 The Apache Software Foundation. All rights reserved.