*/
public void initialize( Collection pages )
throws ProviderException
{
log.debug( "Initializing new ReferenceManager with "+pages.size()+" initial pages." );
StopWatch sw = new StopWatch();
sw.start();
log.info( "Starting cross reference scan of WikiPages" );
//
// First, try to serialize old data from disk. If that fails,
// we'll go and update the entire reference lists (which'll take
// time)
//
try
{
//
// Unserialize things. The loop below cannot be combined with
// the other loop below, simply because engine.getPage() has
// side effects such as loading initializing the user databases,
// which in turn want all of the pages to be read already...
//
// Yes, this is a kludge. We know. Will be fixed.
//
long saved = unserializeFromDisk();
for( Iterator it = pages.iterator(); it.hasNext(); )
{
WikiPage page = (WikiPage) it.next();
unserializeAttrsFromDisk( page );
}
//
// Now we must check if any of the pages have been changed
// while we were in the electronic la-la-land, and update
// the references for them.
//
Iterator it = pages.iterator();
while( it.hasNext() )
{
WikiPage page = (WikiPage) it.next();
if( page instanceof Attachment )
{
// Skip attachments
}
else
{
// Refresh with the latest copy
page = m_engine.getPage( page.getName() );
if( page.getLastModified() == null )
{
log.fatal( "Provider returns null lastModified. Please submit a bug report." );
}
else if( page.getLastModified().getTime() > saved )
{
updatePageReferences( page );
}
}
}
}
catch( Exception e )
{
log.info("Unable to unserialize old refmgr information, rebuilding database: "+e.getMessage());
buildKeyLists( pages );
// Scan the existing pages from disk and update references in the manager.
Iterator it = pages.iterator();
while( it.hasNext() )
{
WikiPage page = (WikiPage)it.next();
if( page instanceof Attachment )
{
// We cannot build a reference list from the contents
// of attachments, so we skip them.
}
else
{
updatePageReferences( page );
serializeAttrsToDisk( page );
}
}
serializeToDisk();
}
sw.stop();
log.info( "Cross reference scan done in "+sw );
WikiEventUtils.addWikiEventListener(m_engine.getPageManager(),
WikiPageEvent.PAGE_DELETED, this);
}