You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2009/03/29 16:52:21 UTC
svn commit: r759704 - in /incubator/jspwiki/trunk: ./
src/java/org/apache/wiki/ src/java/org/apache/wiki/api/
src/java/org/apache/wiki/attachment/ src/java/org/apache/wiki/content/
src/java/org/apache/wiki/parser/ src/java/org/apache/wiki/plugin/ src/j...
Author: jalkanen
Date: Sun Mar 29 14:52:20 2009
New Revision: 759704
URL: http://svn.apache.org/viewvc?rev=759704&view=rev
Log:
Refactored ReferenceManager to use JCR repository. It does not quite work yet, but it's a start.
Minor refactorings to remove dependencies on PageManager.
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageRenamer.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferredPagesPlugin.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/acl/DefaultAclManagerTest.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/PluginManagerTest.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sun Mar 29 14:52:20 2009
@@ -1,3 +1,12 @@
+2009-03-29 Janne Jalkanen <ja...@apache.org>
+
+ * 3.0.0-svn-90
+
+ * Refactored ReferenceManager to use JCR repository. It does
+ not quite work yet, but it's a start.
+
+ * Minor refactorings to remove dependencies on PageManager.
+
2009-03-29 Harry Metske <me...@apache.org>
* 3.0.0-svn-89
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java Sun Mar 29 14:52:20 2009
@@ -64,6 +64,9 @@
private static final String ACL = "wiki:acl";
+ public static final String REFERSTO = "wiki:refersTo";
+
+
private WikiName m_name;
private WikiEngine m_engine;
private String m_jcrPath = null;
@@ -134,6 +137,19 @@
return null;
}
+ /**
+ * Direct access to JCR Properties.
+ *
+ * @param key
+ * @return
+ * @throws PathNotFoundException
+ * @throws RepositoryException
+ */
+ public Property getProperty( String key ) throws PathNotFoundException, RepositoryException
+ {
+ return getJCRNode().getProperty(key);
+ }
+
private Object getValue( Property property ) throws RepositoryException, ValueFormatException
{
switch( property.getType() )
@@ -453,6 +469,28 @@
return null;
}
+ public Collection<WikiName> getRefersTo() throws ProviderException
+ {
+ Collection<WikiName> refs = new ArrayList<WikiName>();
+
+ try
+ {
+ Property p = getProperty( REFERSTO );
+
+ Value[] values = p.getValues();
+
+ for( Value v : values )
+ refs.add( WikiName.valueOf( v.getString() ) );
+ }
+ catch( PathNotFoundException e ) {}
+ catch( RepositoryException e )
+ {
+ throw new ProviderException("Unable to get the referrals",e);
+ }
+ return refs;
+ }
+
+
public void setContent( InputStream in ) throws ProviderException
{
try
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java Sun Mar 29 14:52:20 2009
@@ -345,15 +345,7 @@
public void deleteVersion( WikiPage page )
throws ProviderException
{
- try
- {
- m_engine.getContentManager().deleteVersion( page );
- }
- catch( PageNotFoundException e )
- {
- // This should not happen. If it does, rethrow
- throw new ProviderException( e.getMessage() );
- }
+ m_engine.getContentManager().deleteVersion( page );
}
/**
@@ -365,15 +357,7 @@
public void deletePage( WikiPage page )
throws ProviderException
{
- try
- {
- m_engine.getContentManager().deletePage( page );
- }
- catch( PageNotFoundException e )
- {
- // This should not happen. If it does, rethrow
- throw new ProviderException( e.getMessage() );
- }
+ m_engine.getContentManager().deletePage( page );
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ReferenceManager.java Sun Mar 29 14:52:20 2009
@@ -20,15 +20,18 @@
*/
package org.apache.wiki;
-import java.io.*;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.jcr.*;
import org.apache.commons.lang.time.StopWatch;
import org.apache.wiki.api.WikiPage;
-import org.apache.wiki.attachment.Attachment;
+import org.apache.wiki.content.ContentManager;
import org.apache.wiki.content.PageNotFoundException;
+import org.apache.wiki.content.WikiName;
import org.apache.wiki.event.WikiEvent;
import org.apache.wiki.event.WikiEventListener;
import org.apache.wiki.event.WikiEventUtils;
@@ -38,103 +41,21 @@
import org.apache.wiki.log.LoggerFactory;
import org.apache.wiki.modules.InternalModule;
import org.apache.wiki.providers.ProviderException;
-import org.apache.wiki.providers.WikiPageProvider;
import org.apache.wiki.util.TextUtil;
-
-/*
- BUGS
-
- - if a wikilink is added to a page, then removed, RefMan still thinks that
- the page refers to the wikilink page. Hm.
-
- - if a page is deleted, gets very confused.
-
- - Serialization causes page attributes to be missing, when InitializablePlugins
- are not executed properly. Thus, serialization should really also mark whether
- a page is serializable or not...
- */
-
-
-/*
- A word about synchronizing:
-
- I expect this object to be accessed in three situations:
- - when a WikiEngine is created and it scans its wikipages
- - when the WE saves a page
- - when a JSP page accesses one of the WE's ReferenceManagers
- to display a list of (un)referenced pages.
-
- So, access to this class is fairly rare, and usually triggered by
- user interaction. OTOH, the methods in this class use their storage
- objects intensively (and, sorry to say, in an unoptimized manner =).
- My deduction: using unsynchronized HashMaps etc and syncing methods
- or code blocks is preferrable to using slow, synced storage objects.
- We don't have iterative code here, so I'm going to use synced methods
- for now.
-
- Please contact me if you notice problems with ReferenceManager, and
- especially with synchronization, or if you have suggestions about
- syncing.
-
- ebu@memecry.net
-*/
-
/**
- * Keeps track of wikipage references:
+ * Calculates wikipage references:
* <UL>
* <LI>What pages a given page refers to
* <LI>What pages refer to a given page
* </UL>
*
- * This is a quick'n'dirty approach without any finesse in storage and
- * searching algorithms; we trust java.util.*.
- * <P>
- * 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.)
- * <P>
- * 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.
- * <P>
- * Based on this information, we can perform non-optimal searches for
- * e.g. unreferenced pages, top ten lists, etc.
- * <P>
- * 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.
- *
- * @author ebu@memecry.net
- * @since 1.6.1
*/
-
-// FIXME: The way that we save attributes is now a major booboo, and must be
-// replace forthwith. However, this is a workaround for the great deal
-// of problems that occur here...
-
public class ReferenceManager
extends BasicPageFilter
implements InternalModule, WikiEventListener
{
- /** Maps page wikiname to a Collection of pages it refers to. The Collection
- * must contain Strings. The Collection may contain names of non-existing
- * pages.
- */
- private Map<String,Collection<String>> m_refersTo;
- private Map<String,Collection<String>> m_unmutableRefersTo;
-
- /** Maps page wikiname to a Set of referring pages. The Set must
- * contain Strings. Non-existing pages (a reference exists, but not a file
- * for the page contents) may have an empty Set in m_referredBy.
- */
- private Map<String,Set<String>> m_referredBy;
- private Map<String,Set<String>> m_unmutableReferredBy;
/** The WikiEngine that owns this object. */
private WikiEngine m_engine;
@@ -149,6 +70,8 @@
/** We use this also a generic serialization id */
private static final long serialVersionUID = 4L;
+ private static final String REFERENCES_ROOT = "/wiki:references";
+
/**
* Builds a new ReferenceManager.
*
@@ -156,19 +79,12 @@
*/
public ReferenceManager( WikiEngine engine )
{
- m_refersTo = new HashMap<String,Collection<String>>();
- m_referredBy = new HashMap<String,Set<String>>();
m_engine = engine;
m_matchEnglishPlurals = TextUtil.getBooleanProperty( engine.getWikiProperties(),
WikiEngine.PROP_MATCHPLURALS,
m_matchEnglishPlurals );
- //
- // Create two maps that contain unmutable versions of the two basic maps.
- //
- m_unmutableReferredBy = Collections.unmodifiableMap( m_referredBy );
- m_unmutableRefersTo = Collections.unmodifiableMap( m_refersTo );
}
/**
@@ -179,29 +95,33 @@
throws ProviderException
{
String content;
- try
- {
- content = m_engine.getPageManager().getPageText( page.getName(),
- WikiPageProvider.LATEST_VERSION );
- }
- catch( PageNotFoundException e )
- {
- // This should not happen. If it does, rethrow
- throw new ProviderException( e.getMessage() );
- }
- TreeSet<String> res = new TreeSet<String>();
- Collection<String> links = m_engine.scanWikiLinks( page, content );
+ content = page.getContentAsString();
+ TreeSet<WikiName> res = new TreeSet<WikiName>();
+ Collection<WikiName> links = m_engine.scanWikiLinks( page, content );
+
+ // This makes sure all duplicates are removed.
+
res.addAll( links );
+
+ // FIXME: I am not sure whether it makes sense to add all attachments here as well.
+ /*
Collection attachments = m_engine.getAttachmentManager().listAttachments( page );
for( Iterator atti = attachments.iterator(); atti.hasNext(); )
{
res.add( ((WikiPage)(atti.next())).getName() );
}
-
- internalUpdateReferences( page.getName(), res );
+ */
+ try
+ {
+ internalUpdateReferences( (JCRWikiPage)page, res );
+ }
+ catch( RepositoryException e )
+ {
+ throw new ProviderException("Unable to store internal references",e);
+ }
}
/**
@@ -216,11 +136,28 @@
public void initialize( Collection pages )
throws ProviderException
{
+ try
+ {
+ Session session = m_engine.getContentManager().getCurrentSession();
+
+ if( !session.getRootNode().hasNode( REFERENCES_ROOT ) )
+ {
+ session.getRootNode().addNode( REFERENCES_ROOT );
+
+ session.save();
+ }
+ }
+ catch( RepositoryException e )
+ {
+ throw new ProviderException("Failed to initialize repository contents",e);
+ }
+
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
@@ -306,137 +243,12 @@
serializeToDisk();
}
-
+*/
sw.stop();
log.info( "Cross reference scan done in "+sw );
- WikiEventUtils.addWikiEventListener(m_engine.getPageManager(),
- WikiPageEvent.PAGE_DELETED, this);
- }
-
- /**
- * Reads the serialized data from the disk back to memory.
- * Returns the date when the data was last written on disk
- */
- @SuppressWarnings("unchecked")
- private synchronized long unserializeFromDisk()
- throws IOException,
- ClassNotFoundException
- {
- ObjectInputStream in = null;
- long saved = 0L;
-
- try
- {
- StopWatch sw = new StopWatch();
- sw.start();
-
- File f = new File( m_engine.getWorkDir(), SERIALIZATION_FILE );
-
- in = new ObjectInputStream( new BufferedInputStream(new FileInputStream(f)) );
-
- long ver = in.readLong();
-
- if( ver != serialVersionUID )
- {
- throw new IOException("File format has changed; I need to recalculate references.");
- }
-
- saved = in.readLong();
- m_refersTo = (Map) in.readObject();
- m_referredBy = (Map) in.readObject();
-
- in.close();
-
- m_unmutableReferredBy = Collections.unmodifiableMap( m_referredBy );
- m_unmutableRefersTo = Collections.unmodifiableMap( m_refersTo );
-
- sw.stop();
- log.debug("Read serialized data successfully in "+sw);
- }
- finally
- {
- if( in != null ) in.close();
- }
-
- return saved;
- }
-
- /**
- * Serializes hashmaps to disk. The format is private, don't touch it.
- */
- private synchronized void serializeToDisk()
- {
- ObjectOutputStream out = null;
-
- try
- {
- StopWatch sw = new StopWatch();
- sw.start();
-
- File f = new File( m_engine.getWorkDir(), SERIALIZATION_FILE );
-
- out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream(f)) );
-
- out.writeLong( serialVersionUID );
- out.writeLong( System.currentTimeMillis() ); // Timestamp
- out.writeObject( m_refersTo );
- out.writeObject( m_referredBy );
-
- out.close();
-
- sw.stop();
-
- log.debug("serialization done - took "+sw);
- }
- catch( IOException e )
- {
- log.error("Unable to serialize!");
-
- try
- {
- if( out != null ) out.close();
- }
- catch( IOException ex ) {}
- }
- }
-
- private String getHashFileName( String pageName )
- throws NoSuchAlgorithmException
- {
- MessageDigest digest = MessageDigest.getInstance("MD5");
-
- byte[] dig;
- try
- {
- dig = digest.digest( pageName.getBytes("UTF-8") );
- }
- catch (UnsupportedEncodingException e)
- {
- throw new InternalWikiException("AAAAGH! UTF-8 is gone! My eyes! It burns...!");
- }
-
- return TextUtil.toHexString(dig)+".cache";
- }
-
- /**
- * Reads the serialized data from the disk back to memory.
- * Returns the date when the data was last written on disk
- * @deprecated to be removed
- */
- private synchronized long unserializeAttrsFromDisk(WikiPage p)
- throws IOException,
- ClassNotFoundException
- {
- return 0L;
- }
-
- /**
- * Serializes hashmaps to disk. The format is private, don't touch it.
- * @deprecated To be removed
- */
- private synchronized void serializeAttrsToDisk( WikiPage p )
- {
+ WikiEventUtils.addWikiEventListener(m_engine.getContentManager(),
+ WikiPageEvent.PAGE_DELETE_REQUEST, this);
}
/**
@@ -449,10 +261,15 @@
{
WikiPage page = context.getPage();
- updateReferences( page.getName(),
- context.getEngine().scanWikiLinks( page, content ) );
-
- serializeAttrsToDisk( page );
+ try
+ {
+ updateReferences( page,
+ context.getEngine().scanWikiLinks( page, content ) );
+ }
+ catch( ProviderException e )
+ {
+ log.error("ReferenceManager updates failed, repo is now in inconsistent state!",e);
+ }
}
/**
@@ -466,70 +283,113 @@
* referring page:deleted page.
*
* @param page Name of the page to remove from the maps.
+ * @throws PageNotFoundException
+ * @throws ProviderException
*/
- public synchronized void pageRemoved( WikiPage page )
+ public synchronized void pageRemoved( WikiName pageName ) throws ProviderException, PageNotFoundException
{
- String pageName = page.getName();
+ WikiPage page = m_engine.getContentManager().getPage( pageName );
+
+ Collection<WikiName> refTo = page.getRefersTo();
+
+ for( WikiName referred : refTo )
+ {
+ log.debug( "Removing references to page %s from page %s", page.getQualifiedName(), referred );
+ Set<WikiName> referredBy = getReferredBy(referred);
+
+ referredBy.remove( page.getQualifiedName() );
+
+ try
+ {
+ setReferredBy( referred, referredBy );
+ }
+ catch( RepositoryException e )
+ {
+ throw new ProviderException("Failed to change the contents of pages",e);
+ }
+ }
- pageRemoved(pageName);
}
- private void pageRemoved(String pageName)
+ private String getReferredByJCRPath(WikiName name)
{
- Collection<String> refTo = m_refersTo.get( pageName );
-
- if( refTo != null )
+ return "/wiki:references/"+name.getSpace()+"/"+name.getPath();
+ }
+
+ private Set<WikiName> getReferredBy(WikiName name) throws ProviderException
+ {
+ String jcrPath = getReferredByJCRPath( name );
+
+ try
{
- Iterator itRefTo = refTo.iterator();
- while( itRefTo.hasNext() )
+ jcrPath += "/wiki:referredBy";
+
+ Property p = (Property)m_engine.getContentManager().getCurrentSession().getItem(jcrPath);
+
+ TreeSet<WikiName> result = new TreeSet<WikiName>();
+
+ for( Value v : p.getValues() )
{
- String referredPageName = (String)itRefTo.next();
- Set<String> refBy = m_referredBy.get( referredPageName );
-
- if( refBy == null )
- throw new InternalWikiException("Refmgr out of sync: page "+pageName+" refers to "+referredPageName+", which has null referrers.");
-
- refBy.remove(pageName);
-
- m_referredBy.remove( referredPageName );
-
- // We won't put it back again if it becomes empty and does not exist. It will be added
- // later on anyway, if it becomes referenced again.
- if( !(refBy.isEmpty() && !m_engine.pageExists(referredPageName)) )
- {
- m_referredBy.put( referredPageName, refBy );
- }
+ result.add( WikiName.valueOf( v.getString() ) );
}
-
- log.debug("Removing from m_refersTo HashMap key:value "+pageName+":"+m_refersTo.get( pageName ));
- m_refersTo.remove( pageName );
+
+ return result;
}
-
- Set<String> refBy = m_referredBy.get( pageName );
- if( refBy == null || refBy.isEmpty() )
+ catch( PathNotFoundException e )
{
- m_referredBy.remove( pageName );
+ // Fine, we can return an empty set
+ return new TreeSet<WikiName>();
}
+ catch( RepositoryException e )
+ {
+ throw new ProviderException("Unable to get the referred-by list",e);
+ }
+ }
+
+ /**
+ * Set the referredBy attribute set.
+ *
+ * @param name
+ * @param references
+ * @throws RepositoryException
+ */
+ private void setReferredBy(WikiName name,Set<WikiName> references) throws RepositoryException
+ {
+ String jcrPath = getReferredByJCRPath( name );
+ Property p = null;
- //
- // Remove any traces from the disk, too
- //
- serializeToDisk();
-
+ String[] value = new String[references.size()];
+ WikiName[] refs = references.toArray(new WikiName[references.size()]);
+
+ for( int i = 0; i < references.size(); i++ )
+ {
+ value[i] = refs[i].toString();
+ }
+
+ ContentManager mgr = m_engine.getContentManager();
+
try
{
- File f = new File( m_engine.getWorkDir(), SERIALIZATION_DIR );
+ p = (Property)mgr.getCurrentSession().getItem(jcrPath+"/wiki:referredBy");
- f = new File( f, getHashFileName(pageName) );
-
- if( f.exists() ) f.delete();
+ p.setValue( value );
}
- catch( NoSuchAlgorithmException e )
+ catch( PathNotFoundException e )
{
- log.error("What do you mean - no such algorithm?", e);
+ Session s = mgr.getCurrentSession();
+ if( !s.itemExists( jcrPath ) )
+ {
+ mgr.createJCRNode(jcrPath);
+ }
+
+ Node nd = (Node) s.getItem(jcrPath);
+
+ nd.setProperty( "wiki:referredBy", value );
}
+
+ mgr.getCurrentSession().getItem( "/wiki:references" ).save();
}
-
+
/**
* 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
@@ -542,11 +402,17 @@
* @param page Name of the page to update.
* @param references A Collection of Strings, each one pointing to a page this page references.
*/
- public synchronized void updateReferences( String page, Collection references )
+ public synchronized void updateReferences( WikiPage page, Collection<WikiName> references )
+ throws ProviderException
{
- internalUpdateReferences(page, references);
-
- serializeToDisk();
+ try
+ {
+ internalUpdateReferences( (JCRWikiPage)page, references);
+ }
+ catch( RepositoryException e )
+ {
+ throw new ProviderException("Failed to update references",e);
+ }
}
/**
@@ -557,233 +423,66 @@
* This method does not synchronize the database to disk.
*
* @param page Name of the page to update.
- * @param references A Collection of Strings, each one pointing to a page this page references.
+ * @param newRefersTo A Collection of Strings, each one pointing to a page this page references.
+ * @throws ProviderException
+ * @throws RepositoryException
*/
- private void internalUpdateReferences(String page, Collection references)
+ private void internalUpdateReferences(JCRWikiPage page, Collection<WikiName> newRefersTo) throws ProviderException, RepositoryException
{
- page = getFinalPageName( page );
-
//
- // Create a new entry in m_refersTo.
+ // Get the old refererences so that we can go and ping every page on that
+ // list and make sure that their referredBy lists are fine.
//
- Collection oldRefTo = m_refersTo.get( page );
- m_refersTo.remove( page );
-
- TreeSet<String> cleanedRefs = new TreeSet<String>();
- for( Iterator i = references.iterator(); i.hasNext(); )
- {
- String ref = (String)i.next();
-
- ref = getFinalPageName( ref );
-
- cleanedRefs.add( ref );
- }
-
- m_refersTo.put( page, cleanedRefs );
+ Collection<WikiName> oldRefersTo = page.getRefersTo();
//
- // We know the page exists, since it's making references somewhere.
- // If an entry for it didn't exist previously in m_referredBy, make
- // sure one is added now.
+ // Set up the new references list
//
- if( !m_referredBy.containsKey( page ) )
+
+ WikiName[] wn = newRefersTo.toArray(new WikiName[newRefersTo.size()]);
+ String[] nr = new String[newRefersTo.size()];
+
+ for( int i = 0; i < nr.length; i++ )
{
- m_referredBy.put( page, new TreeSet<String>() );
+ nr[i] = wn[i].toString();
}
-
+
+ Node nd = page.getJCRNode();
+
+ nd.setProperty( JCRWikiPage.REFERSTO, nr );
+
//
- // Get all pages that used to be referred to by 'page' and
- // remove that reference. (We don't want to try to figure out
- // which particular references were removed...)
+ // Go ping the old pages that the reference list has changed.
//
- cleanReferredBy( page, oldRefTo, cleanedRefs );
-
- //
- // Notify all referred pages of their referinesshoodicity.
- //
- Iterator<String> it = cleanedRefs.iterator();
- while( it.hasNext() )
+
+ for( WikiName name : oldRefersTo )
{
- String referredPageName = it.next();
- updateReferredBy( getFinalPageName(referredPageName), page );
- }
- }
-
- /**
- * Returns the refers-to list. For debugging.
- *
- * @return The refers-to list.
- */
- protected Map getRefersTo()
- {
- return m_refersTo;
- }
-
- /**
- * Returns the referred-by list. For debugging.
- *
- * @return Referred-by lists.
- */
- protected Map getReferredBy()
- {
- return m_referredBy;
- }
-
- /**
- * Cleans the 'referred by' list, removing references by 'referrer' to
- * any other page. Called after 'referrer' is removed.
- */
- private void cleanReferredBy( String referrer,
- Collection oldReferred,
- Collection<String> newReferred )
- {
- // Two ways to go about this. One is to look up all pages previously
- // referred by referrer and remove referrer from their lists, and let
- // the update put them back in (except possibly removed ones).
- // The other is to get the old referred to list, compare to the new,
- // and tell the ones missing in the latter to remove referrer from
- // their list. Hm. We'll just try the first for now. Need to come
- // back and optimize this a bit.
-
- if( oldReferred == null )
- return;
-
- Iterator it = oldReferred.iterator();
- while( it.hasNext() )
- {
- String referredPage = (String)it.next();
- Set oldRefBy = m_referredBy.get( referredPage );
- if( oldRefBy != null )
- {
- oldRefBy.remove( referrer );
- }
-
- // If the page is referred to by no one AND it doesn't even
- // exist, we might just as well forget about this entry.
- // It will be added again elsewhere if new references appear.
- if( ( ( oldRefBy == null ) || ( oldRefBy.isEmpty() ) ) &&
- ( m_engine.pageExists( referredPage ) == false ) )
+ if( !newRefersTo.contains( name ) )
{
- m_referredBy.remove( referredPage );
+ // A page is no longer referenced, so this page is removed from its
+ // referencedBy list.
+ Set<WikiName> refs = getReferredBy( name );
+ refs.remove( page.getQualifiedName() );
+ setReferredBy( name, refs );
}
}
-
- }
-
-
- /**
- * When initially building a ReferenceManager from scratch, call this method
- * BEFORE calling updateReferences() with a full list of existing page names.
- * It builds the refersTo and referredBy key lists, thus enabling
- * updateReferences() to function correctly.
- * <P>
- * This method should NEVER be called after initialization. It clears all mappings
- * from the reference tables.
- *
- * @param pages a Collection containing WikiPage objects.
- */
- private synchronized void buildKeyLists( Collection pages )
- {
- m_refersTo.clear();
- m_referredBy.clear();
-
- if( pages == null )
- return;
-
- Iterator it = pages.iterator();
- try
+
+ for( WikiName name : newRefersTo )
{
- while( it.hasNext() )
+ if( !oldRefersTo.contains(name) )
{
- WikiPage page = (WikiPage)it.next();
- // We add a non-null entry to referredBy to indicate the referred page exists
- m_referredBy.put( page.getName(), new TreeSet<String>() );
- // Just add a key to refersTo; the keys need to be in sync with referredBy.
- m_refersTo.put( page.getName(), null );
+ // There is a new reference which is not in the old references list,
+ // so we will need to add it to the new page's referencedBy list.
+ Set<WikiName> refs = getReferredBy( name );
+ refs.add( page.getQualifiedName() );
+ setReferredBy( name, refs );
}
}
- catch( ClassCastException e )
- {
- log.error( "Invalid collection entry in ReferenceManager.buildKeyLists().", e );
- }
+
}
- /**
- * Marks the page as referred to by the referrer. If the page does not
- * exist previously, nothing is done. (This means that some page, somewhere,
- * has a link to a page that does not exist.)
- * <P>
- * This method is NOT synchronized. It should only be referred to from
- * within a synchronized method, or it should be made synced if necessary.
- */
- private void updateReferredBy( String page, String referrer )
- {
- // We're not really interested in first level self-references.
- /*
- if( page.equals( referrer ) )
- {
- return;
- }
- */
- // Neither are we interested if plural forms refer to each other.
- if( m_matchEnglishPlurals )
- {
- String p2 = page.endsWith("s") ? page.substring(0,page.length()-1) : page+"s";
-
- if( referrer.equals(p2) )
- {
- return;
- }
- }
-
- Set<String> referrers = m_referredBy.get( page );
-
- // Even if 'page' has not been created yet, it can still be referenced.
- // This requires we don't use m_referredBy keys when looking up missing
- // pages, of course.
- if(referrers == null)
- {
- referrers = new TreeSet<String>();
- m_referredBy.put( page, referrers );
- }
- referrers.add( referrer );
- }
-
-
- /**
- * Clears the references to a certain page so it's no longer in the map.
- *
- * @param pagename Name of the page to clear references for.
- */
- public synchronized void clearPageEntries( String pagename )
- {
- pagename = getFinalPageName(pagename);
-
- //
- // Remove this item from the referredBy list of any page
- // which this item refers to.
- //
- Collection<String> c = m_refersTo.get( pagename );
-
- if( c != null )
- {
- for( String key : c )
- {
- Collection<?> dref = m_referredBy.get( key );
-
- dref.remove( pagename );
- }
- }
-
- //
- // Finally, remove direct references.
- //
- m_referredBy.remove( pagename );
- m_refersTo.remove( pagename );
- }
-
/**
* Finds all unreferenced pages. This requires a linear scan through
@@ -795,6 +494,8 @@
{
ArrayList<String> unref = new ArrayList<String>();
+ // FIXME: Not implemented yet
+ /*
for( String key : m_referredBy.keySet() )
{
Set<?> refs = getReferenceList( m_referredBy, key );
@@ -804,7 +505,7 @@
unref.add( key );
}
}
-
+*/
return unref;
}
@@ -828,6 +529,8 @@
// Go through m_refersTo values and check that m_refersTo has the corresponding keys.
// We want to reread the code to make sure our HashMaps are in sync...
+ // FIXME: Not yet done
+ /*
Collection<Collection<String>> allReferences = m_refersTo.values();
for( Collection<String> refs : allReferences )
@@ -843,49 +546,10 @@
}
}
}
-
+ */
return uncreated;
}
- /**
- * Searches for the given page in the given Map, and returns
- * the set of references. This method also takes care of English plural
- * matching.
- *
- * @param coll The Map to search in
- * @param pagename The name to find.
- * @return The references list.
- */
- private <T> Set<T> getReferenceList( Map<String,Set<T>> coll, String pagename )
- {
- Set<T> refs = coll.get( pagename );
-
- if( m_matchEnglishPlurals )
- {
- //
- // We'll add also matches from the "other" page.
- //
- Set<T> refs2;
-
- if( pagename.endsWith("s") )
- {
- refs2 = coll.get( pagename.substring(0,pagename.length()-1) );
- }
- else
- {
- refs2 = coll.get( pagename+"s" );
- }
-
- if( refs2 != null )
- {
- if( refs != null )
- refs.addAll( refs2 );
- else
- refs = refs2;
- }
- }
- return refs;
- }
/**
* Find all pages that refer to this page. Returns null if the page
@@ -896,40 +560,20 @@
* @return A Collection of Strings. (This is, in fact, a Set, and is likely
* to change at some point to a Set). May return null, if the page
* does not exist, or if it has no references.
+ * @throws ProviderException
+ * @deprecated
*/
// FIXME: Return a Set instead of a Collection.
- public synchronized Collection<String> findReferrers( String pagename )
+ public synchronized Collection<String> findReferrers( String pagename ) throws ProviderException
{
- Set<String> refs = getReferenceList( m_referredBy, pagename );
+ Set<String> refs = new TreeSet<String>();
- if( refs == null || refs.isEmpty() )
- {
- return null;
- }
+ Set<WikiName> r = getReferredBy( WikiName.valueOf( pagename ) );
+ for( WikiName wn : r )
+ refs.add( wn.toString() );
+
return refs;
-
- }
-
- /**
- * Returns all pages that refer to this page. Note that this method
- * returns an unmodifiable Map, which may be abruptly changed. So any
- * access to any iterator may result in a ConcurrentModificationException.
- * <p>
- * 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.
- *
- * @param pageName Page name to query.
- * @return A Set of Strings containing the names of all the pages that refer
- * to this page. May return null, if the page does not exist or
- * has not been indexed yet.
- * @since 2.2.33
- */
- public Set findReferredBy( String pageName )
- {
- return m_unmutableReferredBy.get( getFinalPageName(pageName) );
}
/**
@@ -948,52 +592,23 @@
* @return A Collection of Strings containing the names of the pages that this page
* refers to. May return null, if the page does not exist or has not
* been indexed yet.
+ * @throws PageNotFoundException
+ * @throws ProviderException
* @since 2.2.33
+ * @deprecated Use WikiPage.getRefersTo() instead
*/
- public Collection findRefersTo( String pageName )
+ public Collection findRefersTo( String pageName ) throws ProviderException, PageNotFoundException
{
- return m_unmutableRefersTo.get( getFinalPageName(pageName) );
+ ArrayList<String> result = new ArrayList<String>();
+
+ Collection<WikiName> refs = m_engine.getPage( pageName ).getRefersTo();
+
+ for( WikiName wn : refs )
+ result.add( wn.toString() );
+
+ return result;
}
- /**
- * This 'deepHashCode' can be used to determine if there were any
- * modifications made to the underlying to and by maps of the
- * ReferenceManager. The maps of the ReferenceManager are not
- * synchronized, so someone could add/remove entries in them while the
- * hashCode is being computed.
- *
- * @return Sum of the hashCodes for the to and by maps of the
- * ReferenceManager
- * @since 2.3.24
- */
- //
- // This method traps and retries if a concurrent
- // modifcaition occurs.
- // TODO: It is unnecessary to calculate the hashcode; it should be calculated only
- // when the hashmaps are changed. This is slow.
- //
- public int deepHashCode()
- {
- boolean failed = true;
- int signature = 0;
-
- while (failed)
- {
- signature = 0;
- try
- {
- signature ^= m_referredBy.hashCode();
- signature ^= m_refersTo.hashCode();
- failed = false;
- }
- catch (ConcurrentModificationException e)
- {
- Thread.yield();
- }
- }
-
- return signature;
- }
/**
* Returns a list of all pages that the ReferenceManager knows about.
@@ -1003,11 +618,19 @@
* very fast.
*
* @return A Set of all defined page names that ReferenceManager knows about.
+ * @throws ProviderException
* @since 2.3.24
+ * @deprecated
*/
- public Set<String> findCreated()
+ public Set<String> findCreated() throws ProviderException
{
- return new HashSet<String>( m_refersTo.keySet() );
+ Set<String> result = new TreeSet<String>();
+ Collection<WikiPage> c = m_engine.getContentManager().getAllPages( null );
+
+ for( WikiPage p : c )
+ result.add( p.getQualifiedName().toString() );
+
+ return result;
}
private String getFinalPageName( String orig )
@@ -1028,13 +651,26 @@
*/
public void actionPerformed(WikiEvent event)
{
- if( (event instanceof WikiPageEvent) && (event.getType() == WikiPageEvent.PAGE_DELETED) )
+ if( (event instanceof WikiPageEvent) && (event.getType() == WikiPageEvent.PAGE_DELETE_REQUEST) )
{
String pageName = ((WikiPageEvent) event).getPageName();
if( pageName != null )
{
- pageRemoved( pageName );
+ try
+ {
+ pageRemoved( WikiName.valueOf(pageName) );
+ }
+ catch( ProviderException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch( PageNotFoundException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Sun Mar 29 14:52:20 2009
@@ -77,7 +77,7 @@
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "89";
+ public static final String BUILD = "90";
/**
* This is the generic version string you should use
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java Sun Mar 29 14:52:20 2009
@@ -1579,7 +1579,7 @@
* @param pagedata The page contents
* @return a Collection of Strings
*/
- public Collection<String> scanWikiLinks( WikiPage page, String pagedata )
+ public List<WikiName> scanWikiLinks( WikiPage page, String pagedata )
{
LinkCollector localCollector = new LinkCollector();
@@ -1591,7 +1591,14 @@
false,
true );
- return localCollector.getLinks();
+ ArrayList<WikiName> response = new ArrayList<WikiName>();
+
+ for( String s : localCollector.getLinks() )
+ {
+ response.add( WikiName.valueOf( s ) );
+ }
+
+ return response;
}
/**
@@ -1713,12 +1720,13 @@
* Updates all references for the given page.
*
* @param page wiki page for which references should be updated
+ * @throws ProviderException
*/
- public void updateReferences( WikiPage page )
+ public void updateReferences( WikiPage page ) throws ProviderException
{
String pageData = getPureText( page.getName(), WikiProvider.LATEST_VERSION );
- m_referenceManager.updateReferences( page.getName(),
+ m_referenceManager.updateReferences( page,
scanWikiLinks( page, pageData ) );
}
@@ -2238,30 +2246,14 @@
throws ProviderException
{
WikiPage p;
+
try
{
p = getPage( pageName );
- if( p instanceof Attachment )
- {
- m_attachmentManager.deleteAttachment( (Attachment) p );
- }
- else
- {
- if (m_attachmentManager.hasAttachments( p ))
- {
- Collection attachments = m_attachmentManager.listAttachments( p );
- for( Iterator atti = attachments.iterator(); atti.hasNext(); )
- {
- m_attachmentManager.deleteAttachment( (Attachment)(atti.next()) );
- }
- }
- m_pageManager.deletePage( p );
- }
- }
- catch( PageNotFoundException e )
- {
- // If page doesn't exist, do nothing
+
+ m_contentManager.deletePage( p );
}
+ catch(PageNotFoundException e) {}
}
/**
@@ -2273,14 +2265,7 @@
public void deleteVersion( WikiPage page )
throws ProviderException
{
- if( page instanceof Attachment )
- {
- m_attachmentManager.deleteVersion( (WikiPage) page );
- }
- else
- {
- m_pageManager.deleteVersion( page );
- }
+ m_contentManager.deleteVersion( page );
}
/**
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java Sun Mar 29 14:52:20 2009
@@ -21,6 +21,7 @@
package org.apache.wiki.api;
import java.io.InputStream;
+import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -206,6 +207,8 @@
public void setContent( InputStream in ) throws ProviderException;
+ public Collection<WikiName> getRefersTo() throws ProviderException;
+
/**
* Returns the parent of the page.
*
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java Sun Mar 29 14:52:20 2009
@@ -411,14 +411,7 @@
*/
public void deleteVersion( WikiPage att ) throws ProviderException
{
- try
- {
- m_engine.getContentManager().deleteVersion( att );
- }
- catch( PageNotFoundException e )
- {
- // No worries
- }
+ m_engine.getContentManager().deleteVersion( att );
}
/**
@@ -428,17 +421,9 @@
* @param att The Attachment to delete.
* @throws ProviderException if something goes wrong with the backend
*/
- // FIXME: Should also use events!
public void deleteAttachment( Attachment att ) throws ProviderException
{
- try
- {
- m_engine.getContentManager().deletePage( att );
- }
- catch( PageNotFoundException e )
- {
- // No worries
- }
+ m_engine.getContentManager().deletePage( att );
}
/**
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java Sun Mar 29 14:52:20 2009
@@ -55,6 +55,7 @@
import org.apache.wiki.workflow.Outcome;
import org.apache.wiki.workflow.Task;
import org.apache.wiki.workflow.Workflow;
+import org.hsqldb.lib.StringUtil;
import org.priha.RepositoryManager;
import org.priha.util.ConfigurationException;
@@ -84,6 +85,13 @@
* it does not really take advantage of all of the JCR API. Therefore, this
* class should be treated as extremely volatile.
*
+ * Events which are fired by this Manager:
+ * <ul>
+ * <li>WikiPageEvent.PAGE_DELETE_REQUEST - Before deletion actually starts. Page still exists in
+ * the repository.</li>
+ * <li>WikiPageEvent.PAGE_DELETED - After deletion is complete, which means that the page no longer
+ * exists in the repository.</li>
+ * <ul>
* @since 3.0
*/
@@ -299,6 +307,19 @@
m_sessionManager.releaseSession();
}
+ /**
+ * Returns the current JCR Session. If there is no Session, a new
+ * one is created.
+ *
+ * @return A valid JCR Session
+ * @throws LoginException If login credentials are wrong
+ * @throws RepositoryException If something else fails with the repository
+ */
+ public Session getCurrentSession() throws LoginException, RepositoryException
+ {
+ return m_sessionManager.getSession();
+ }
+
/*
public Object acquire() throws ProviderException
{
@@ -684,9 +705,11 @@
* @param page The page to delete.
* @throws ProviderException if the page fails
* @throws PageNotFoundException If the page in question does not exist.
+ * @return True, if the page was actually deleted, and false otherwise.
*/
- public void deleteVersion( WikiPage page )
- throws ProviderException, PageNotFoundException
+ // TODO: The event which gets fired suggests that this actually a whole page delete event
+ public boolean deleteVersion( WikiPage page )
+ throws ProviderException
{
fireEvent( WikiPageEvent.PAGE_DELETE_REQUEST, page.getName() );
@@ -697,10 +720,12 @@
jcrPage.save();
fireEvent( WikiPageEvent.PAGE_DELETED, jcrPage.getName() );
+
+ return true;
}
catch( PathNotFoundException e )
{
- throw new PageNotFoundException(page.getQualifiedName());
+ return false;
}
catch( RepositoryException e )
{
@@ -709,15 +734,16 @@
}
/**
- * Deletes an entire page, all versions, all traces.
+ * Deletes an entire page, all versions, all traces. If the page did not
+ * exist, will just exit quietly and return false.
*
* @param page The WikiPage to delete
+ * @return True, if the page was found and deleted; false, if the page did not exist in the first place
* @throws ProviderException If the backend fails or the page is illegal.
- * @throws PageNotFoundException If the page has already disappeared.
*/
- public void deletePage( WikiPage page )
- throws ProviderException, PageNotFoundException
+ public boolean deletePage( WikiPage page )
+ throws ProviderException
{
fireEvent( WikiPageEvent.PAGE_DELETE_REQUEST, page.getName() );
@@ -747,10 +773,12 @@
nd.getParent().save();
fireEvent( WikiPageEvent.PAGE_DELETED, page.getName() );
+
+ return true;
}
catch( PathNotFoundException e )
{
- throw new PageNotFoundException(page.getQualifiedName());
+ return false;
}
catch( RepositoryException e )
{
@@ -1009,6 +1037,9 @@
Node nd = session.getRootNode().addNode( getJCRPath(path) );
+ nd.addMixin( "mix:versionable" );
+ nd.addMixin( "mix:referenceable" );
+
JCRWikiPage page = new JCRWikiPage(m_engine, nd);
return page;
@@ -1080,6 +1111,8 @@
if( version == WikiProvider.LATEST_VERSION || version == 1)
page = new JCRWikiPage( m_engine, nd );
+ else
+ throw new PageNotFoundException("Version "+version+" of page "+path+" does not exist!");
}
return page;
@@ -1312,8 +1345,35 @@
boolean m_identity = false;
}
- public Node getJCRNode( String path ) throws RepositoryException
+ public Node getJCRNode( String jcrPath ) throws RepositoryException
{
- return (Node)m_sessionManager.getSession().getItem( path );
+ return (Node)m_sessionManager.getSession().getItem( jcrPath );
+ }
+
+ /**
+ * Creates a JCR Node including all of its parents from a given JCR Path.
+ * If the Node already exists, returns it.
+ *
+ * @param jcrPath An absolute or relative path. If relative, it's interpreted
+ * as relative to the workspace root node.
+ * @return A valid JCR Node
+ * @throws RepositoryException If the creation fails for some reason
+ */
+ public Node createJCRNode( String jcrPath ) throws RepositoryException
+ {
+ String[] components = StringUtil.split( jcrPath, "/" );
+
+ Node current = getCurrentSession().getRootNode();
+
+ for( int i = 0; i < components.length; i++ )
+ {
+ if( !current.hasNode( components[i] ) )
+ {
+ current.addNode( components[i] );
+ }
+ current = current.getNode( components[i] );
+ }
+
+ return current;
}
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageRenamer.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageRenamer.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageRenamer.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageRenamer.java Sun Mar 29 14:52:20 2009
@@ -165,7 +165,14 @@
// Update the references
//
- engine.getReferenceManager().pageRemoved( fromPage );
+ try
+ {
+ engine.getReferenceManager().pageRemoved( fromPage.getQualifiedName() );
+ }
+ catch( PageNotFoundException e )
+ {
+ // This is fine.
+ }
engine.updateReferences( toPage );
//
@@ -251,11 +258,11 @@
{
Set<String> referrers = new TreeSet<String>();
- Collection<String> r = engine.getReferenceManager().findReferrers( fromPage.getName() );
- if( r != null ) referrers.addAll( r );
-
try
{
+ Collection<String> r = engine.getReferenceManager().findReferrers( fromPage.getName() );
+ if( r != null ) referrers.addAll( r );
+
Collection<Attachment> attachments = engine.getAttachmentManager().listAttachments( fromPage );
for( WikiPage att : attachments )
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java Sun Mar 29 14:52:20 2009
@@ -41,6 +41,7 @@
import org.apache.wiki.attachment.AttachmentManager;
import org.apache.wiki.auth.WikiSecurityException;
import org.apache.wiki.auth.acl.Acl;
+import org.apache.wiki.content.PageNotFoundException;
import org.apache.wiki.i18n.InternationalizationManager;
import org.apache.wiki.log.Logger;
import org.apache.wiki.log.LoggerFactory;
@@ -1671,18 +1672,18 @@
try
{
att = mgr.getAttachmentInfo( m_context, linktext );
+
+ return att.getName();
}
+ catch( PageNotFoundException e )
+ {}
catch( Exception e )
{
log.warn("Finding attachments failed: ",e);
return null;
}
-
- if( att != null )
- {
- return att.getName();
- }
- else if( linktext.indexOf('/') != -1 )
+
+ if( linktext.indexOf('/') != -1 )
{
return linktext;
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferredPagesPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferredPagesPlugin.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferredPagesPlugin.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferredPagesPlugin.java Sun Mar 29 14:52:20 2009
@@ -25,8 +25,10 @@
import org.apache.wiki.*;
import org.apache.wiki.api.PluginException;
import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.content.PageNotFoundException;
import org.apache.wiki.log.Logger;
import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.providers.ProviderException;
import org.apache.wiki.util.TextUtil;
@@ -126,7 +128,14 @@
//PatternCompiler g_compiler = new GlobCompiler();
// go get all referred links
- getReferredPages(context,rootname, 0);
+ try
+ {
+ getReferredPages(context,rootname, 0);
+ }
+ catch(Exception e)
+ {
+ throw new PluginException("Failed to get referred pages "+e.getMessage());
+ }
// close and finish
m_result.append ("</div>\n" ) ;
@@ -138,9 +147,11 @@
/**
* Retrieves a list of all referred pages. Is called recursively
* depending on the depth parameter
+ * @throws PageNotFoundException
+ * @throws ProviderException
*/
@SuppressWarnings("unchecked")
- private void getReferredPages( WikiContext context, String pagename, int depth )
+ private void getReferredPages( WikiContext context, String pagename, int depth ) throws ProviderException, PageNotFoundException
{
if( depth >= m_depth ) return; // end of recursion
if( pagename == null ) return;
@@ -157,7 +168,7 @@
handleLinks( context, pages, ++depth, pagename );
}
- private void handleLinks(WikiContext context,Collection<String> links, int depth, String pagename)
+ private void handleLinks(WikiContext context,Collection<String> links, int depth, String pagename) throws ProviderException, PageNotFoundException
{
boolean isUL = false;
HashSet<String> localLinkSet = new HashSet<String>(); // needed to skip multiple
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java Sun Mar 29 14:52:20 2009
@@ -41,6 +41,7 @@
import org.apache.wiki.parser.MarkupParser;
import org.apache.wiki.parser.WikiDocument;
import org.apache.wiki.providers.CachingProvider;
+import org.apache.wiki.providers.ProviderException;
import org.apache.wiki.util.TextUtil;
@@ -341,22 +342,30 @@
{
String pageName = ((WikiPageEvent) event).getPageName();
m_documentCache.flushPattern( pageName );
- Collection referringPages = m_engine.getReferenceManager().findReferrers( pageName );
-
- //
- // Flush also those pages that refer to this page (if an nonexistant page
- // appears; we need to flush the HTML that refers to the now-existant page
- //
- if( referringPages != null )
+ try
{
- Iterator i = referringPages.iterator();
- while (i.hasNext())
+ Collection referringPages = m_engine.getReferenceManager().findReferrers( pageName );
+
+ //
+ // Flush also those pages that refer to this page (if an nonexistant page
+ // appears; we need to flush the HTML that refers to the now-existant page
+ //
+ if( referringPages != null )
{
- String page = (String) i.next();
- if( log.isDebugEnabled() ) log.debug( "Flushing " + page );
- m_documentCache.flushPattern( page );
+ Iterator i = referringPages.iterator();
+ while (i.hasNext())
+ {
+ String page = (String) i.next();
+ if( log.isDebugEnabled() ) log.debug( "Flushing " + page );
+ m_documentCache.flushPattern( page );
+ }
}
}
+ catch( ProviderException e )
+ {
+ // Just skip this
+ // FIXME: Is this the right way to work?
+ }
}
}
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java Sun Mar 29 14:52:20 2009
@@ -129,7 +129,16 @@
String oldStyleName = MarkupParser.wikifyLink(wikiName).toLowerCase() + filename;
- Set allPages = m_engine.getReferenceManager().findCreated();
+ Set allPages;
+ try
+ {
+ allPages = m_engine.getReferenceManager().findCreated();
+ }
+ catch( ProviderException e )
+ {
+ // FIXME: THis is probably not very smart.
+ allPages = new TreeSet();
+ }
int counter = 0;
for( Iterator i = allPages.iterator(); i.hasNext() && counter < maxLength; )
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java Sun Mar 29 14:52:20 2009
@@ -33,6 +33,7 @@
import org.apache.wiki.api.WikiException;
import org.apache.wiki.providers.AbstractFileProvider;
+import org.apache.wiki.providers.ProviderException;
/**
@@ -110,7 +111,7 @@
assertTrue( c.size() == 1 && c.contains("Foobar") );
}
- public void testNonExistant2()
+ public void testNonExistant2() throws ProviderException
{
Collection c = mgr.findReferrers("TestBug");
@@ -382,6 +383,7 @@
* This method is NOT synchronized, and should be used in testing
* with one user, one WikiEngine only.
*/
+ /*
public static String dumpReferenceManager( ReferenceManager rm )
{
StringBuffer buf = new StringBuffer();
@@ -437,6 +439,7 @@
return( buf.toString() );
}
+ */
}
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java Sun Mar 29 14:52:20 2009
@@ -121,20 +121,6 @@
m_engine.pageExists( NAME1 ) );
}
- /**
- * Check that calling pageExists( WikiPage ) works.
- */
- public void testNonExistantPage2()
- throws Exception
- {
- m_engine.deletePage( NAME1 );
- WikiPage page = m_engine.createPage( WikiName.valueOf( NAME1 ) );
-
- assertEquals( "Page already exists",
- false,
- m_engine.pageExists( page ) );
- }
-
public void testFinalPageName()
throws Exception
{
@@ -602,16 +588,13 @@
{
m_engine.saveText( NAME1, "Test" );
- String files = props.getProperty( AbstractFileProvider.PROP_PAGEDIR );
- File saved = new File( files, NAME1+".txt" );
-
- assertTrue( "Didn't create it!", saved.exists() );
-
WikiPage page = m_engine.getPage( NAME1, WikiProvider.LATEST_VERSION );
+ assertNotNull( "Page exists", page );
+
m_engine.deletePage( page.getName() );
- assertFalse( "Page has not been removed!", saved.exists() );
+ assertFalse( "Page has not been removed!", m_engine.pageExists( NAME1 ) );
}
/*
@@ -956,6 +939,18 @@
m_engine.pageExists( name ) );
}
+ public void testCreatePage2()
+ throws Exception
+ {
+ m_engine.deletePage( NAME1 );
+ WikiPage page = m_engine.createPage( WikiName.valueOf( NAME1 ) );
+
+ assertEquals( "Page does not exist",
+ true,
+ m_engine.pageExists( page ) );
+ }
+
+
public void testCreateEmptyPage() throws Exception
{
String text = "";
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/acl/DefaultAclManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/acl/DefaultAclManagerTest.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/acl/DefaultAclManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/auth/acl/DefaultAclManagerTest.java Sun Mar 29 14:52:20 2009
@@ -60,16 +60,10 @@
m_engine.saveText( "TestAclPage", text );
}
- public void tearDown()
+ public void tearDown() throws Exception
{
- try
- {
- m_engine.deletePage( "TestDefaultPage" );
- m_engine.deletePage( "TestAclPage" );
- }
- catch ( ProviderException e )
- {
- }
+ m_engine.deletePage( "TestDefaultPage" );
+ m_engine.deletePage( "TestAclPage" );
m_engine.shutdown();
}
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/PluginManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/PluginManagerTest.java?rev=759704&r1=759703&r2=759704&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/PluginManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/PluginManagerTest.java Sun Mar 29 14:52:20 2009
@@ -24,16 +24,14 @@
import java.util.Collection;
import java.util.Properties;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
import org.apache.wiki.TestEngine;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiEngine;
-import org.apache.wiki.plugin.PluginManager;
import org.apache.wiki.plugin.PluginManager.WikiPluginInfo;
-import org.apache.wiki.providers.ProviderException;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
public class PluginManagerTest extends TestCase
@@ -64,15 +62,9 @@
manager = new PluginManager( engine, props );
}
- public void tearDown()
+ public void tearDown() throws Exception
{
- try
- {
- engine.deletePage("Testpage");
- }
- catch ( ProviderException e )
- {
- }
+ engine.deletePage("Testpage");
engine.shutdown();
}