public class DefaultReferenceManager extends BasePageFilter implements ReferenceManager
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.
m_engine| Constructor and Description |
|---|
DefaultReferenceManager(Engine engine)
Builds a new ReferenceManager.
|
| Modifier and Type | Method and Description |
|---|---|
void |
actionPerformed(WikiEvent event) |
void |
clearPageEntries(java.lang.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.
|
java.util.Set<java.lang.String> |
findCreated()
Returns a list of all pages that the ReferenceManager knows about.
|
java.util.Set<java.lang.String> |
findReferredBy(java.lang.String pageName)
Returns all pages that refer to this page.
|
java.util.Set<java.lang.String> |
findReferrers(java.lang.String pagename)
Find all pages that refer to this page.
|
java.util.Collection<java.lang.String> |
findRefersTo(java.lang.String pageName)
Returns all pages that this page refers to.
|
java.util.Collection<java.lang.String> |
findUncreated()
Finds all references to non-existant pages.
|
java.util.Collection<java.lang.String> |
findUnreferenced()
Finds all unreferenced pages.
|
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
getReferredBy()
Returns the referred-by list.
|
protected java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> |
getRefersTo()
Returns the refers-to list.
|
void |
initialize(java.util.Collection<Page> pages)
Initializes the entire reference manager with the initial set of pages from the collection.
|
void |
pageRemoved(Page page)
Updates the m_referedTo and m_referredBy hashmaps when a page has been deleted.
|
void |
postSave(Context context,
java.lang.String content)
After the page has been saved, updates the reference lists.
|
java.util.Collection<java.lang.String> |
scanWikiLinks(Page page,
java.lang.String pagedata)
Reads a WikiPageful of data from a String and returns all links internal to this Wiki in a Collection.
|
void |
updateReferences(Page page)
Updates all references for the given page.
|
void |
updateReferences(java.lang.String page,
java.util.Collection<java.lang.String> references)
Updates the referred pages of a new or edited WikiPage.
|
initializeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdestroy, initialize, postTranslate, preSave, preTranslatepublic DefaultReferenceManager(Engine engine)
engine - The Engine to which this is managing references to.public void initialize(java.util.Collection<Page> pages) throws ProviderException
initialize in interface ReferenceManagerpages - A collection of all pages you want to be included in the reference count.ProviderException - If reading of pages fails.public void postSave(Context context, java.lang.String content)
postSave in interface PageFiltercontext - content - public java.util.Collection<java.lang.String> scanWikiLinks(Page page, java.lang.String pagedata)
scanWikiLinks in interface ReferenceManagerpage - The WikiPage to scanpagedata - The page contentspublic void pageRemoved(Page 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.
pageRemoved in interface ReferenceManagerpage - Name of the page to remove from the maps.public void updateReferences(Page page)
updateReferences in interface ReferenceManagerpage - wiki page for which references should be updatedpublic void updateReferences(java.lang.String page, java.util.Collection<java.lang.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.
updateReferences in interface ReferenceManagerpage - Name of the page to update.references - A Collection of Strings, each one pointing to a page this page references.protected java.util.Map<java.lang.String,java.util.Collection<java.lang.String>> getRefersTo()
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getReferredBy()
public void clearPageEntries(java.lang.String pagename)
clearPageEntries in interface ReferenceManagerpagename - Name of the page to clear references for.public java.util.Collection<java.lang.String> findUnreferenced()
findUnreferenced in interface ReferenceManagerpublic java.util.Collection<java.lang.String> 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.
findUncreated in interface ReferenceManagerpublic java.util.Set<java.lang.String> findReferrers(java.lang.String pagename)
findReferrers in interface ReferenceManagerpagename - The page to find referrers for.public java.util.Set<java.lang.String> findReferredBy(java.lang.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.
findReferredBy in interface ReferenceManagerpageName - Page name to query.public java.util.Collection<java.lang.String> findRefersTo(java.lang.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.
findRefersTo in interface ReferenceManagerpageName - Page name to querypublic int deepHashCode()
public java.util.Set<java.lang.String> findCreated()
findCreated in interface ReferenceManagerpublic void actionPerformed(WikiEvent event)
actionPerformed in interface WikiEventListenerCopyright (c) 2001-2022 The Apache Software Foundation. All rights reserved.