com.ecyrd.jspwiki
Class ReferenceManager

java.lang.Object
  |
  +--com.ecyrd.jspwiki.ReferenceManager

public class ReferenceManager
extends java.lang.Object

Keeps track of wikipage references:

This is a quick'n'dirty approach without any finesse in storage and searching algorithms; we trust java.util.*.

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 HashSet of all pages that refer to the indexing page. (Notice - the keys of both HashMaps 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.

Since:
1.6.1
Author:
ebu@memecry.net

Constructor Summary
ReferenceManager(WikiEngine engine, java.util.Collection pages)
          Builds a new ReferenceManager with default (null) entries for the WikiPages contained in the pages Collection.
 
Method Summary
 java.util.Collection findReferrers(java.lang.String pagename)
          Find all pages that refer to this page.
 java.util.Collection findUncreated()
          Finds all references to non-existant pages.
 java.util.Collection findUnreferenced()
          Finds all unreferenced pages.
 void updateReferences(java.lang.String page, java.util.Collection references)
          Updates the referred pages of a new or edited WikiPage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReferenceManager

public ReferenceManager(WikiEngine engine,
                        java.util.Collection pages)
Builds a new ReferenceManager with default (null) entries for the WikiPages contained in the pages Collection. (This collection must be given for subsequent updateReferences() calls to work.)

The collection should contain an entry for all currently existing WikiPages.

Parameters:
pages - a Collection of WikiPages
Method Detail

updateReferences

public void updateReferences(java.lang.String page,
                             java.util.Collection references)
Updates the referred pages of a new or edited WikiPage. If a refersTo entry for this page already exists, it is removed and a new one is built from scratch. Also calls updateReferredBy() for each referenced page.

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.

Parameters:
page - Name of the page to update.
references - A Collection of Strings, each one pointing to a page this page references.

findUnreferenced

public java.util.Collection findUnreferenced()
Finds all unreferenced pages. This requires a linear scan through m_referredBy to locate keys with null or empty values.


findUncreated

public java.util.Collection findUncreated()
Finds all references to non-existant pages. This requires a linear scan through m_refersTo values; each value must have a corresponding key entry in the reference HashMaps, otherwise such a page has never been created.

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.


findReferrers

public java.util.Collection findReferrers(java.lang.String pagename)
Find all pages that refer to this page. Returns null if the page does not exist or is not referenced at all, otherwise returns a collection containint page names (String) that refer to this one.