You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2019/12/19 22:11:30 UTC

[jspwiki] branch master updated (daf5761 -> 453c2a4)

This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git.


    from daf5761  Add JIRA ids related to 2.11.0.M6
     new c961890  some code formatting
     new b3a3fa4  some more code cleanup and formatting prior to move renamePage method from WikiEngine to PageRenamer
     new 16b47e8  further cleanup + formatting on PageRenamer
     new dc06bef  JSPWIKI-120: Separate rendering engine from core
     new ccb852b  JSPWIKI-120: PageRenamer renamed as WikiPageRenamer, with new PageRenamer extracted as interface of WikiPageRenamer
     new 453c2a4  2.11.0-M7-git-01

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ChangeLog.md                                       |   9 +
 .../src/main/java/org/apache/wiki/Release.java     |   4 +-
 .../src/main/java/org/apache/wiki/WikiEngine.java  |  92 +----
 .../java/org/apache/wiki/content/PageRenamer.java  | 400 +--------------------
 .../src/main/resources/ini/classmappings.xml       |   4 +
 .../test/java/org/apache/wiki/WikiEngineTest.java  |  14 +-
 .../org/apache/wiki/content/PageRenamerTest.java   |  44 +--
 jspwiki-war/src/main/webapp/Rename.jsp             |   2 +-
 8 files changed, 71 insertions(+), 498 deletions(-)


[jspwiki] 01/06: some code formatting

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit c96189066a95d3d6c99487dbc315ea47774f7536
Author: juanpablo <ju...@apache.org>
AuthorDate: Thu Dec 19 22:04:35 2019 +0100

    some code formatting
---
 .../src/main/java/org/apache/wiki/WikiEngine.java  | 57 ++++++++--------------
 1 file changed, 21 insertions(+), 36 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
index c7fe788..6c2b5ee 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -26,7 +26,6 @@ import org.apache.wiki.api.engine.AdminBeanManager;
 import org.apache.wiki.api.engine.FilterManager;
 import org.apache.wiki.api.engine.PluginManager;
 import org.apache.wiki.api.exceptions.FilterException;
-import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
 import org.apache.wiki.api.exceptions.NoSuchVariableException;
 import org.apache.wiki.api.exceptions.ProviderException;
 import org.apache.wiki.api.exceptions.WikiException;
@@ -113,10 +112,9 @@ import java.util.concurrent.ConcurrentHashMap;
  *  There's basically only a single WikiEngine for each web application, and
  *  you should always get it using the WikiEngine.getInstance() method.
  */
-public class WikiEngine
-{
-    private static final String ATTR_WIKIENGINE = "org.apache.wiki.WikiEngine";
+public class WikiEngine  {
 
+    private static final String ATTR_WIKIENGINE = "org.apache.wiki.WikiEngine";
     private static final Logger log = Logger.getLogger(WikiEngine.class);
 
     /** True, if log4j has been configured. */
@@ -636,21 +634,14 @@ public class WikiEngine
         //
         //  Initialize the good-to-have-but-not-fatal modules.
         //
-        try
-        {
-            if( TextUtil.getBooleanProperty( props,
-                                             RSSGenerator.PROP_GENERATE_RSS,
-                                             false ) )
-            {
+        try {
+            if( TextUtil.getBooleanProperty( props, RSSGenerator.PROP_GENERATE_RSS,false ) ) {
                 m_rssGenerator = (RSSGenerator)ClassUtil.getMappedObject(RSSGenerator.class.getName(), this, props );
             }
 
             m_pageRenamer = (PageRenamer)ClassUtil.getMappedObject(PageRenamer.class.getName(), this, props );
-        }
-        catch( Exception e )
-        {
-            log.error( "Unable to start RSS generator - JSPWiki will still work, "+
-                       "but there will be no RSS feed.", e );
+        } catch( final Exception e ) {
+            log.error( "Unable to start RSS generator - JSPWiki will still work, but there will be no RSS feed.", e );
         }
 
         // Start the RSS generator & generator thread
@@ -2076,7 +2067,7 @@ public class WikiEngine
     public String renamePage( WikiContext context,
                               String renameFrom,
                               String renameTo,
-                              boolean changeReferrers)
+                              boolean changeReferrers )
         throws WikiException
     {
         String newPageName = m_pageRenamer.renamePage(context, renameFrom, renameTo, changeReferrers);
@@ -2196,7 +2187,7 @@ public class WikiEngine
      * Registers a WikiEventListener with this instance.
      * @param listener the event listener
      */
-    public final synchronized void addWikiEventListener( WikiEventListener listener )
+    public final synchronized void addWikiEventListener( final WikiEventListener listener )
     {
         WikiEventManager.addWikiEventListener( this, listener );
     }
@@ -2205,7 +2196,7 @@ public class WikiEngine
      * Un-registers a WikiEventListener with this instance.
      * @param listener the event listener
      */
-    public final synchronized void removeWikiEventListener( WikiEventListener listener )
+    public final synchronized void removeWikiEventListener( final WikiEventListener listener )
     {
         WikiEventManager.removeWikiEventListener( this, listener );
     }
@@ -2214,11 +2205,9 @@ public class WikiEngine
      * Fires a WikiEngineEvent to all registered listeners.
      * @param type  the event type
      */
-    protected final void fireEvent( int type )
-    {
-        if ( WikiEventManager.isListening(this) )
-        {
-            WikiEventManager.fireEvent(this,new WikiEngineEvent(this,type));
+    protected final void fireEvent( final int type ) {
+        if( WikiEventManager.isListening(this ) ) {
+            WikiEventManager.fireEvent( this, new WikiEngineEvent(this, type ) );
         }
     }
 
@@ -2226,11 +2215,9 @@ public class WikiEngine
      * Fires a WikiPageEvent to all registered listeners.
      * @param type  the event type
      */
-    protected final void firePageEvent( int type, String pageName )
-    {
-        if ( WikiEventManager.isListening(this) )
-        {
-            WikiEventManager.fireEvent(this,new WikiPageEvent(this,type,pageName));
+    protected final void firePageEvent( final int type, final String pageName ) {
+        if( WikiEventManager.isListening(this ) ) {
+            WikiEventManager.fireEvent(this,new WikiPageEvent(this, type, pageName ) );
         }
     }
 
@@ -2239,11 +2226,9 @@ public class WikiEngine
      * @param oldName the former page name
      * @param newName the new page name
      */
-    protected final void firePageRenameEvent(String oldName, String newName )
-    {
-        if ( WikiEventManager.isListening(this) )
-        {
-            WikiEventManager.fireEvent(this,new WikiPageRenameEvent(this,oldName,newName));
+    protected final void firePageRenameEvent( final String oldName, final String newName ) {
+        if( WikiEventManager.isListening(this) ) {
+            WikiEventManager.fireEvent(this, new WikiPageRenameEvent(this, oldName, newName ) );
         }
     }
 
@@ -2255,7 +2240,7 @@ public class WikiEngine
      * @param key the attribute name
      * @param value the value
      */
-    public void setAttribute( String key, Object value )
+    public void setAttribute( final String key, final Object value )
     {
         m_attributes.put( key, value );
     }
@@ -2266,7 +2251,7 @@ public class WikiEngine
      *  @param key the attribute name
      *  @return the value
      */
-    public Object getAttribute( String key )
+    public Object getAttribute( final String key )
     {
         return m_attributes.get( key );
     }
@@ -2277,7 +2262,7 @@ public class WikiEngine
      *  @param key The key of the attribute to remove.
      *  @return The previous attribute, if it existed.
      */
-    public Object removeAttribute( String key )
+    public Object removeAttribute( final String key )
     {
         return m_attributes.remove( key );
     }


[jspwiki] 06/06: 2.11.0-M7-git-01

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 453c2a4f33df13da79df18668fa996dafe3d207b
Author: juanpablo <ju...@apache.org>
AuthorDate: Thu Dec 19 23:10:27 2019 +0100

    2.11.0-M7-git-01
---
 ChangeLog.md                                            | 9 +++++++++
 jspwiki-main/src/main/java/org/apache/wiki/Release.java | 4 ++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index 953de74..b70ff72 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -17,6 +17,15 @@ specific language governing permissions and limitations
 under the License.
 -->
 
+**2019-12-19  Juan Pablo Santos (juanpablo AT apache DOT org)**
+
+* _2.11.0-M7-git-01_
+
+* [JSPWIKI-120](https://issues.apache.org/jira/browse/JSPWIKI-120): Separate rendering engine from core
+    * `PageRenamer` renamed as `WikiPageRenamer`, with new `PageRenamer` extracted as interface of `WikiPageRenamer`
+    * `pageRename(..)` method deleted from `WikiEngine`, use the one located on `PageRenamer`
+    * custom `PageRenamer`s should also fire the appropiate `WikiPageRenameEvent` on `pageRename(..)` method
+
 **2019-12-06  Juan Pablo Santos (juanpablo AT apache DOT org)**
 
 * _2.11.0-M6-git-05_
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/Release.java b/jspwiki-main/src/main/java/org/apache/wiki/Release.java
index 70f12ba..3fea463 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/Release.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/Release.java
@@ -52,7 +52,7 @@ public final class Release {
      *  <p>
      *  If the POSTFIX is empty, it is not added to the version string.
      */
-    private static final String    POSTFIX       = "M6";
+    private static final String    POSTFIX       = "M7";
 
     /** The JSPWiki major version. */
     public static final int        VERSION       = 2;
@@ -72,7 +72,7 @@ public final class Release {
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "";
+    public static final String     BUILD         = "git-01";
 
     /**
      *  This is the generic version string you should use when printing out the version.  It is of


[jspwiki] 02/06: some more code cleanup and formatting prior to move renamePage method from WikiEngine to PageRenamer

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit b3a3fa4462c937bba6e242eadb1021dfa5e90624
Author: juanpablo <ju...@apache.org>
AuthorDate: Thu Dec 19 22:05:47 2019 +0100

    some more code cleanup and formatting prior to move renamePage method from WikiEngine to PageRenamer
---
 .../java/org/apache/wiki/content/PageRenamer.java  | 117 +++++++++------------
 1 file changed, 49 insertions(+), 68 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java b/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
index 04539c1..5643783 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
@@ -18,13 +18,6 @@
  */
 package org.apache.wiki.content;
 
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 import org.apache.log4j.Logger;
 import org.apache.wiki.InternalWikiException;
 import org.apache.wiki.WikiContext;
@@ -39,6 +32,13 @@ import org.apache.wiki.parser.JSPWikiMarkupParser;
 import org.apache.wiki.parser.MarkupParser;
 import org.apache.wiki.util.TextUtil;
 
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  *  Provides page renaming functionality.  Note that there used to be
  *  a similarly named class in 2.6, but due to unclear copyright, the
@@ -63,32 +63,23 @@ public class PageRenamer
      *  @return The final new name (in case it had to be modified)
      *  @throws WikiException If the page cannot be renamed.
      */
-    public String renamePage(final WikiContext context, 
-                              final String renameFrom, 
-                              final String renameTo, 
-                              final boolean changeReferrers )
-        throws WikiException
-    {
+    public String renamePage( final WikiContext context, final String renameFrom, final String renameTo, final boolean changeReferrers ) throws WikiException {
         //
         //  Sanity checks first
         //
-        if( renameFrom == null || renameFrom.length() == 0 )
-        {
+        if( renameFrom == null || renameFrom.length() == 0 ) {
             throw new WikiException( "From name may not be null or empty" );
         }
-        if( renameTo == null || renameTo.length() == 0 )
-        {
+        if( renameTo == null || renameTo.length() == 0 ) {
             throw new WikiException( "To name may not be null or empty" );
         }
        
         //
         //  Clean up the "to" -name so that it does not contain anything illegal
         //
-        
         String renameToClean = MarkupParser.cleanLink( renameTo.trim() );
         
-        if( renameToClean.equals(renameFrom) )
-        {
+        if( renameToClean.equals(renameFrom) ) {
             throw new WikiException( "You cannot rename the page to itself" );
         }
         
@@ -98,56 +89,48 @@ public class PageRenamer
         WikiEngine engine = context.getEngine();
         WikiPage fromPage = engine.getPage( renameFrom );
         
-        if( fromPage == null )
-        {
+        if( fromPage == null ) {
             throw new WikiException("No such page "+renameFrom);
         }
         
         WikiPage toPage = engine.getPage( renameToClean );
         
-        if( toPage != null )
-        {
+        if( toPage != null ) {
             throw new WikiException( "Page already exists " + renameToClean );
         }
         
         //
         //  Options
         //
-        
-        m_camelCase = TextUtil.getBooleanProperty( engine.getWikiProperties(), 
-                                                   JSPWikiMarkupParser.PROP_CAMELCASELINKS, 
-                                                   m_camelCase );
+        m_camelCase = TextUtil.getBooleanProperty( engine.getWikiProperties(), JSPWikiMarkupParser.PROP_CAMELCASELINKS, m_camelCase );
 
-        Set<String> referrers = getReferencesToChange( fromPage, engine );
+        Set< String > referrers = getReferencesToChange( fromPage, engine );
 
         //
-        //  Do the actual rename by changing from the frompage to the topage, including
-        //  all of the attachments
+        //  Do the actual rename by changing from the frompage to the topage, including all of the attachments
         //
         
         //  Remove references to attachments under old name
-        List<Attachment> attachmentsOldName = engine.getAttachmentManager().listAttachments( fromPage );
-        for (Attachment att:attachmentsOldName)
-        {
+        List< Attachment > attachmentsOldName = engine.getAttachmentManager().listAttachments( fromPage );
+        for( Attachment att:attachmentsOldName ) {
             WikiPage fromAttPage = engine.getPage( att.getName() );
             engine.getReferenceManager().pageRemoved( fromAttPage );
         }
 
         engine.getPageManager().getProvider().movePage( renameFrom, renameToClean );
 
-        if( engine.getAttachmentManager().attachmentsEnabled() )
-        {
+        if( engine.getAttachmentManager().attachmentsEnabled() ) {
             engine.getAttachmentManager().getCurrentProvider().moveAttachmentsForPage( renameFrom, renameToClean );
         }
         
         //
-        //  Add a comment to the page notifying what changed.  This adds a new revision
-        //  to the repo with no actual change.
+        //  Add a comment to the page notifying what changed.  This adds a new revision to the repo with no actual change.
         //
-        
         toPage = engine.getPage( renameToClean );
         
-        if( toPage == null ) throw new InternalWikiException("Rename seems to have failed for some strange reason - please check logs!");
+        if( toPage == null ) {
+            throw new InternalWikiException("Rename seems to have failed for some strange reason - please check logs!");
+        }
 
         toPage.setAttribute( WikiPage.CHANGENOTE, fromPage.getName() + " ==> " + toPage.getName() );
         toPage.setAuthor( context.getCurrentUser().getName() );
@@ -157,27 +140,24 @@ public class PageRenamer
         //
         //  Update the references
         //
-        
         engine.getReferenceManager().pageRemoved( fromPage );
         engine.updateReferences( toPage );
 
         //
         //  Update referrers
         //
-        if( changeReferrers )
-        {
+        if( changeReferrers ) {
             updateReferrers( context, fromPage, toPage, referrers );
         }
 
         //
         //  re-index the page including its attachments
         //
-        engine.getSearchManager().reindexPage(toPage);
+        engine.getSearchManager().reindexPage( toPage );
         
-        Collection<Attachment> attachmentsNewName = engine.getAttachmentManager().listAttachments( toPage );
-        for (Attachment att:attachmentsNewName)
-        {
-            WikiPage toAttPage = engine.getPage( att.getName() );
+        Collection< Attachment > attachmentsNewName = engine.getAttachmentManager().listAttachments( toPage );
+        for( final Attachment att:attachmentsNewName ) {
+            final WikiPage toAttPage = engine.getPage( att.getName() );
             // add reference to attachment under new page name
             engine.updateReferences( toAttPage );
             engine.getSearchManager().reindexPage(att);
@@ -387,21 +367,22 @@ public class PageRenamer
     }
 
     /**
-     *  This method does a correct replacement of a single link, taking into
-     *  account anchors and attachments.
+     *  This method does a correct replacement of a single link, taking into account anchors and attachments.
      */
-    private String replaceSingleLink( WikiContext context, String original, String from, String newlink )
-    {
-        int hash = original.indexOf( '#' );
-        int slash = original.indexOf( '/' );
-        String reallink = original;
-        String oldStyleRealLink;
-        
-        if( hash != -1 ) reallink = original.substring( 0, hash );
-        if( slash != -1 ) reallink = original.substring( 0,slash );
-        
-        reallink = MarkupParser.cleanLink( reallink );
-        oldStyleRealLink = MarkupParser.wikifyLink( reallink );
+    private String replaceSingleLink( final WikiContext context, final String original, final String from, final String newlink ) {
+        final int hash = original.indexOf( '#' );
+        final int slash = original.indexOf( '/' );
+        String realLink = original;
+
+        if( hash != -1 ) {
+            realLink = original.substring( 0, hash );
+        }
+        if( slash != -1 ) {
+            realLink = original.substring( 0,slash );
+        }
+
+        realLink = MarkupParser.cleanLink( realLink );
+        final String oldStyleRealLink = MarkupParser.wikifyLink( realLink );
         
         //WikiPage realPage  = context.getEngine().getPage( reallink );
         // WikiPage p2 = context.getEngine().getPage( from );
@@ -412,18 +393,18 @@ public class PageRenamer
         //
         //  Yes, these point to the same page.
         //
-        if( reallink.equals(from) || original.equals(from) || oldStyleRealLink.equals(from) )
-        {
+        if( realLink.equals( from ) || original.equals( from ) || oldStyleRealLink.equals( from ) ) {
             //
             //  if the original contains blanks, then we should introduce a link, for example:  [My Page]  =>  [My Page|My Renamed Page]
-            int blank = reallink.indexOf( " ");
+            final int blank = realLink.indexOf( " ");
             
-            if( blank != -1 )
-            {
+            if( blank != -1 ) {
                 return original + "|" + newlink;
             }
             
-            return newlink + ((hash > 0) ? original.substring( hash ) : "") + ((slash > 0) ? original.substring( slash ) : "") ;
+            return newlink +
+                   ( ( hash > 0 ) ? original.substring( hash ) : "" ) +
+                   ( ( slash > 0 ) ? original.substring( slash ) : "" ) ;
         }
         
         return original;


[jspwiki] 04/06: JSPWIKI-120: Separate rendering engine from core

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit dc06bef45ce4bdc4d3b04b9fa9cd63d5685df627
Author: juanpablo <ju...@apache.org>
AuthorDate: Thu Dec 19 22:55:43 2019 +0100

    JSPWIKI-120: Separate rendering engine from core
    
    * pageRename(..) method deleted from WikiEngine, use the one located on PageRenamer
    * custom PageRenamers should also fire the appropiate WikiPageRenameEvent on their pageRename(..) method
---
 .../src/main/java/org/apache/wiki/WikiEngine.java  | 39 -------------------
 .../java/org/apache/wiki/content/PageRenamer.java  | 16 +++++++-
 .../org/apache/wiki/content/PageRenamerTest.java   | 44 ++++++++++------------
 jspwiki-war/src/main/webapp/Rename.jsp             |  2 +-
 4 files changed, 34 insertions(+), 67 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
index 6c2b5ee..a37e3da 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -42,7 +42,6 @@ import org.apache.wiki.event.WikiEngineEvent;
 import org.apache.wiki.event.WikiEventListener;
 import org.apache.wiki.event.WikiEventManager;
 import org.apache.wiki.event.WikiPageEvent;
-import org.apache.wiki.event.WikiPageRenameEvent;
 import org.apache.wiki.i18n.InternationalizationManager;
 import org.apache.wiki.pages.PageManager;
 import org.apache.wiki.pages.PageTimeComparator;
@@ -2049,33 +2048,6 @@ public class WikiEngine  {
     }
 
     /**
-     * Renames, or moves, a wiki page. Can also alter referring wiki
-     * links to point to the renamed page.
-     *
-     * @param context           The context during which this rename takes
-     *                          place.
-     * @param renameFrom        Name of the source page.
-     * @param renameTo          Name of the destination page.
-     * @param changeReferrers   If true, then changes any referring links
-     *                          to point to the renamed page.
-     *
-     * @return The name of the page that the source was renamed to.
-     *
-     * @throws WikiException    In the case of an error, such as the destination
-     *                          page already existing.
-     */
-    public String renamePage( WikiContext context,
-                              String renameFrom,
-                              String renameTo,
-                              boolean changeReferrers )
-        throws WikiException
-    {
-        String newPageName = m_pageRenamer.renamePage(context, renameFrom, renameTo, changeReferrers);
-        firePageRenameEvent(renameFrom, newPageName);
-        return newPageName;
-    }
-
-    /**
      *  Returns the PageRenamer employed by this WikiEngine.
      *  @since 2.5.141
      *  @return The current PageRenamer instance.
@@ -2222,17 +2194,6 @@ public class WikiEngine  {
     }
 
     /**
-     * Fires a WikiPageRenameEvent to all registered listeners.
-     * @param oldName the former page name
-     * @param newName the new page name
-     */
-    protected final void firePageRenameEvent( final String oldName, final String newName ) {
-        if( WikiEventManager.isListening(this) ) {
-            WikiEventManager.fireEvent(this, new WikiPageRenameEvent(this, oldName, newName ) );
-        }
-    }
-
-    /**
      * Adds an attribute to the engine for the duration of this engine.  The
      * value is not persisted.
      *
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java b/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
index 5063c1d..0bf86c9 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
@@ -131,14 +131,26 @@ public class PageRenamer {
             engine.getSearchManager().reindexPage( att );
         }
 
-        // Currently not used internally by JSPWiki itself, but you can use it for something else.
-        WikiEventManager.fireEvent( this, new WikiPageRenameEvent( this, renameFrom, renameToClean ) );
+        firePageRenameEvent( renameFrom, renameToClean );
 
         //  Done, return the new name.
         return renameToClean;
     }
 
     /**
+     * Fires a WikiPageRenameEvent to all registered listeners. Currently not used internally by JSPWiki itself, but you can use it for
+     * something else.
+     *
+     * @param oldName the former page name
+     * @param newName the new page name
+     */
+    public void firePageRenameEvent( final String oldName, final String newName ) {
+        if( WikiEventManager.isListening(this) ) {
+            WikiEventManager.fireEvent(this, new WikiPageRenameEvent(this, oldName, newName ) );
+        }
+    }
+
+    /**
      *  This method finds all the pages which have anything to do with the fromPage and
      *  change any referrers it can figure out in that page.
      *  
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/content/PageRenamerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/content/PageRenamerTest.java
index 799d09f..c4dc60e 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/content/PageRenamerTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/content/PageRenamerTest.java
@@ -17,16 +17,7 @@
     under the License.
  */
 package org.apache.wiki.content;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.AfterEach;
-
-import java.util.Collection;
-import java.util.Properties;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.Assertions;
 import net.sf.ehcache.CacheManager;
-
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
@@ -34,14 +25,20 @@ import org.apache.wiki.WikiPage;
 import org.apache.wiki.WikiProvider;
 import org.apache.wiki.api.exceptions.WikiException;
 import org.apache.wiki.attachment.Attachment;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Properties;
 
 public class PageRenamerTest
 {
     TestEngine m_engine;
 
     @BeforeEach
-    public void setUp() throws Exception
-    {
+    public void setUp() throws Exception {
         Properties props = TestEngine.getTestProperties();
         props.setProperty( WikiEngine.PROP_MATCHPLURALS, "true" );
         CacheManager.getInstance().removeAllCaches();
@@ -50,8 +47,7 @@ public class PageRenamerTest
     }
 
     @AfterEach
-    public void tearDown() throws Exception
-    {
+    public void tearDown() {
         m_engine.deleteTestPage("TestPage");
         m_engine.deleteTestPage("TestPage2");
         m_engine.deleteTestPage("FooTest");
@@ -73,10 +69,8 @@ public class PageRenamerTest
     }
 
     @Test
-    public void testSimpleRename()
-        throws Exception
-    {
-        // Count the numberof existing references
+    public void testSimpleRename() throws Exception {
+        // Count the number of existing references
         int refCount = m_engine.getReferenceManager().findCreated().size();
 
         m_engine.saveText("TestPage", "the big lazy dog thing" );
@@ -85,7 +79,7 @@ public class PageRenamerTest
 
         WikiContext context = new WikiContext(m_engine, p);
 
-        m_engine.renamePage(context, "TestPage", "FooTest", false);
+        m_engine.getPageRenamer().renamePage(context, "TestPage", "FooTest", false);
 
         WikiPage newpage = m_engine.getPage("FooTest");
 
@@ -111,7 +105,7 @@ public class PageRenamerTest
 
         WikiContext context = new WikiContext(m_engine, p);
 
-        m_engine.renamePage(context, "TestPage", "FooTest", true);
+        m_engine.getPageRenamer().renamePage(context, "TestPage", "FooTest", true);
 
         String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
 
@@ -137,7 +131,7 @@ public class PageRenamerTest
 
         WikiContext context = new WikiContext(m_engine, p);
 
-        m_engine.renamePage(context, "TestPage", "FooTest", true);
+        m_engine.getPageRenamer().renamePage(context, "TestPage", "FooTest", true);
 
         String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
 
@@ -162,7 +156,7 @@ public class PageRenamerTest
 
         WikiContext context = new WikiContext(m_engine, p);
 
-        m_engine.renamePage(context, "TestPage", "FooTest", true);
+        m_engine.getPageRenamer().renamePage(context, "TestPage", "FooTest", true);
 
         String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
 
@@ -187,7 +181,7 @@ public class PageRenamerTest
 
         WikiContext context = new WikiContext(m_engine, p);
 
-        m_engine.renamePage(context, "TestPage", "FooTest", true);
+        m_engine.getPageRenamer().renamePage(context, "TestPage", "FooTest", true);
 
         String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
 
@@ -215,7 +209,7 @@ public class PageRenamerTest
 
         WikiContext context = new WikiContext(m_engine, p);
 
-        m_engine.renamePage(context, "Test", "TestPage", true);
+        m_engine.getPageRenamer().renamePage(context, "Test", "TestPage", true);
 
         String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION );
 
@@ -235,7 +229,7 @@ public class PageRenamerTest
 
         WikiContext context = new WikiContext(m_engine, p);
 
-        m_engine.renamePage(context, "TestPage", "FooTest", true);
+        m_engine.getPageRenamer().renamePage(context, "TestPage", "FooTest", true);
 
         String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
 
@@ -314,7 +308,7 @@ public class PageRenamerTest
 
         WikiContext context = new WikiContext(m_engine, p);
 
-        m_engine.renamePage(context, src, dst, true);
+        m_engine.getPageRenamer().renamePage(context, src, dst, true);
     }
 
     @Test
diff --git a/jspwiki-war/src/main/webapp/Rename.jsp b/jspwiki-war/src/main/webapp/Rename.jsp
index 703787d..2df7fa5 100644
--- a/jspwiki-war/src/main/webapp/Rename.jsp
+++ b/jspwiki-war/src/main/webapp/Rename.jsp
@@ -64,7 +64,7 @@
     {
         if (renameTo.length() > 0)
         {
-            String renamedTo = wiki.renamePage(wikiContext, renameFrom, renameTo, changeReferences);
+            String renamedTo = wiki.getPageRenamer().renamePage(wikiContext, renameFrom, renameTo, changeReferences);
 
             FixedQueue trail = (FixedQueue) session.getAttribute( BreadcrumbsTag.BREADCRUMBTRAIL_KEY );
             if( trail != null )


[jspwiki] 03/06: further cleanup + formatting on PageRenamer

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 16b47e8d679b77413370a44d292be6a7fb983c26
Author: juanpablo <ju...@apache.org>
AuthorDate: Thu Dec 19 22:38:48 2019 +0100

    further cleanup + formatting on PageRenamer
---
 .../java/org/apache/wiki/content/PageRenamer.java  | 235 +++++++--------------
 1 file changed, 80 insertions(+), 155 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java b/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
index 5643783..5063c1d 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
@@ -40,14 +40,12 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 /**
- *  Provides page renaming functionality.  Note that there used to be
- *  a similarly named class in 2.6, but due to unclear copyright, the
- *  class was completely rewritten from scratch for 2.8.
+ * Provides page renaming functionality. Note that there used to be a similarly named class in 2.6, but due to unclear copyright, the
+ * class was completely rewritten from scratch for 2.8.
  *
- *  @since 2.8
+ * @since 2.8
  */
-public class PageRenamer
-{
+public class PageRenamer {
 
     private static final Logger log = Logger.getLogger( PageRenamer.class );
     
@@ -64,9 +62,7 @@ public class PageRenamer
      *  @throws WikiException If the page cannot be renamed.
      */
     public String renamePage( final WikiContext context, final String renameFrom, final String renameTo, final boolean changeReferrers ) throws WikiException {
-        //
         //  Sanity checks first
-        //
         if( renameFrom == null || renameFrom.length() == 0 ) {
             throw new WikiException( "From name may not be null or empty" );
         }
@@ -74,101 +70,71 @@ public class PageRenamer
             throw new WikiException( "To name may not be null or empty" );
         }
        
-        //
         //  Clean up the "to" -name so that it does not contain anything illegal
-        //
-        String renameToClean = MarkupParser.cleanLink( renameTo.trim() );
-        
-        if( renameToClean.equals(renameFrom) ) {
+        final String renameToClean = MarkupParser.cleanLink( renameTo.trim() );
+        if( renameToClean.equals( renameFrom ) ) {
             throw new WikiException( "You cannot rename the page to itself" );
         }
         
-        //
         //  Preconditions: "from" page must exist, and "to" page must not yet exist.
-        //
-        WikiEngine engine = context.getEngine();
-        WikiPage fromPage = engine.getPage( renameFrom );
-        
+        final WikiEngine engine = context.getEngine();
+        final WikiPage fromPage = engine.getPage( renameFrom );
         if( fromPage == null ) {
             throw new WikiException("No such page "+renameFrom);
         }
-        
         WikiPage toPage = engine.getPage( renameToClean );
-        
         if( toPage != null ) {
             throw new WikiException( "Page already exists " + renameToClean );
         }
         
-        //
-        //  Options
-        //
-        m_camelCase = TextUtil.getBooleanProperty( engine.getWikiProperties(), JSPWikiMarkupParser.PROP_CAMELCASELINKS, m_camelCase );
+        final Set< String > referrers = getReferencesToChange( fromPage, engine );
 
-        Set< String > referrers = getReferencesToChange( fromPage, engine );
-
-        //
         //  Do the actual rename by changing from the frompage to the topage, including all of the attachments
-        //
-        
         //  Remove references to attachments under old name
-        List< Attachment > attachmentsOldName = engine.getAttachmentManager().listAttachments( fromPage );
-        for( Attachment att:attachmentsOldName ) {
-            WikiPage fromAttPage = engine.getPage( att.getName() );
+        final List< Attachment > attachmentsOldName = engine.getAttachmentManager().listAttachments( fromPage );
+        for( final Attachment att: attachmentsOldName ) {
+            final WikiPage fromAttPage = engine.getPage( att.getName() );
             engine.getReferenceManager().pageRemoved( fromAttPage );
         }
 
         engine.getPageManager().getProvider().movePage( renameFrom, renameToClean );
-
         if( engine.getAttachmentManager().attachmentsEnabled() ) {
             engine.getAttachmentManager().getCurrentProvider().moveAttachmentsForPage( renameFrom, renameToClean );
         }
         
-        //
         //  Add a comment to the page notifying what changed.  This adds a new revision to the repo with no actual change.
-        //
         toPage = engine.getPage( renameToClean );
-        
         if( toPage == null ) {
-            throw new InternalWikiException("Rename seems to have failed for some strange reason - please check logs!");
+            throw new InternalWikiException( "Rename seems to have failed for some strange reason - please check logs!" );
         }
-
         toPage.setAttribute( WikiPage.CHANGENOTE, fromPage.getName() + " ==> " + toPage.getName() );
         toPage.setAuthor( context.getCurrentUser().getName() );
-        
         engine.getPageManager().putPageText( toPage, engine.getPureText( toPage ) );
 
-        //
         //  Update the references
-        //
         engine.getReferenceManager().pageRemoved( fromPage );
         engine.updateReferences( toPage );
 
-        //
         //  Update referrers
-        //
         if( changeReferrers ) {
             updateReferrers( context, fromPage, toPage, referrers );
         }
 
-        //
         //  re-index the page including its attachments
-        //
         engine.getSearchManager().reindexPage( toPage );
         
-        Collection< Attachment > attachmentsNewName = engine.getAttachmentManager().listAttachments( toPage );
+        final Collection< Attachment > attachmentsNewName = engine.getAttachmentManager().listAttachments( toPage );
         for( final Attachment att:attachmentsNewName ) {
             final WikiPage toAttPage = engine.getPage( att.getName() );
             // add reference to attachment under new page name
             engine.updateReferences( toAttPage );
-            engine.getSearchManager().reindexPage(att);
+            engine.getSearchManager().reindexPage( att );
         }
 
         // Currently not used internally by JSPWiki itself, but you can use it for something else.
         WikiEventManager.fireEvent( this, new WikiPageRenameEvent( this, renameFrom, renameToClean ) );
 
-        //
         //  Done, return the new name.
-        //
         return renameToClean;
     }
 
@@ -180,72 +146,59 @@ public class PageRenamer
      *  @param fromPage The old page
      *  @param toPage The new page
      */
-    private void updateReferrers( WikiContext context, WikiPage fromPage, WikiPage toPage, Set<String>referrers )
-    {
-        WikiEngine engine = context.getEngine();
-        
-        if( referrers.isEmpty() ) return; // No referrers
-        
-        for( String pageName : referrers )
-        {
-            //  In case the page was just changed from under us, let's do this
-            //  small kludge.
-            if( pageName.equals( fromPage.getName() ) )
-            {
+    private void updateReferrers( final WikiContext context, final WikiPage fromPage, final WikiPage toPage, final Set< String > referrers ) {
+        if( referrers.isEmpty() ) { // No referrers
+            return;
+        }
+
+        final WikiEngine engine = context.getEngine();
+        for( String pageName : referrers ) {
+            //  In case the page was just changed from under us, let's do this small kludge.
+            if( pageName.equals( fromPage.getName() ) ) {
                 pageName = toPage.getName();
             }
             
-            WikiPage p = engine.getPage( pageName );
-            
-            String sourceText = engine.getPureText( p );
-            
+            final WikiPage p = engine.getPage( pageName );
+
+            final String sourceText = engine.getPureText( p );
             String newText = replaceReferrerString( context, sourceText, fromPage.getName(), toPage.getName() );
-            
-            if( m_camelCase )
+
+            m_camelCase = TextUtil.getBooleanProperty( engine.getWikiProperties(), JSPWikiMarkupParser.PROP_CAMELCASELINKS, m_camelCase );
+            if( m_camelCase ) {
                 newText = replaceCCReferrerString( context, newText, fromPage.getName(), toPage.getName() );
+            }
             
-            if( !sourceText.equals( newText ) )
-            {
+            if( !sourceText.equals( newText ) ) {
                 p.setAttribute( WikiPage.CHANGENOTE, fromPage.getName()+" ==> "+toPage.getName() );
                 p.setAuthor( context.getCurrentUser().getName() );
          
-                try
-                {
+                try {
                     engine.getPageManager().putPageText( p, newText );
                     engine.updateReferences( p );
-                }
-                catch( ProviderException e )
-                {
-                    //
-                    //  We fail with an error, but we will try to continue to rename
-                    //  other referrers as well.
-                    //
+                } catch( final ProviderException e ) {
+                    //  We fail with an error, but we will try to continue to rename other referrers as well.
                     log.error("Unable to perform rename.",e);
                 }
             }
         }
     }
 
-    private Set<String> getReferencesToChange( WikiPage fromPage, WikiEngine engine )
-    {
-        Set<String> referrers = new TreeSet<String>();
-        
-        Collection<String> r = engine.getReferenceManager().findReferrers( fromPage.getName() );
-        if( r != null ) referrers.addAll( r );
+    private Set<String> getReferencesToChange( final WikiPage fromPage, final WikiEngine engine ) {
+        final Set< String > referrers = new TreeSet<>();
+        final Collection< String > r = engine.getReferenceManager().findReferrers( fromPage.getName() );
+        if( r != null ) {
+            referrers.addAll( r );
+        }
         
-        try
-        {
-            List<Attachment> attachments = engine.getAttachmentManager().listAttachments( fromPage );
-
-            for( Attachment att : attachments  )
-            {
-                Collection<String> c = engine.getReferenceManager().findReferrers(att.getName());
-
-                if( c != null ) referrers.addAll(c);
+        try {
+            final List< Attachment > attachments = engine.getAttachmentManager().listAttachments( fromPage );
+            for( final Attachment att : attachments  ) {
+                final Collection< String > c = engine.getReferenceManager().findReferrers( att.getName() );
+                if( c != null ) {
+                    referrers.addAll( c );
+                }
             }
-        }
-        catch( ProviderException e )
-        {
+        } catch( final ProviderException e ) {
             // We will continue despite this error
             log.error( "Provider error while fetching attachments for rename", e );
         }
@@ -255,31 +208,21 @@ public class PageRenamer
     /**
      *  Replaces camelcase links.
      */
-    private String replaceCCReferrerString( WikiContext context, String sourceText, String from, String to )
-    {
-        StringBuilder sb = new StringBuilder( sourceText.length()+32 );
-        
-        Pattern linkPattern = Pattern.compile( "\\p{Lu}+\\p{Ll}+\\p{Lu}+[\\p{L}\\p{Digit}]*" );
-        
-        Matcher matcher = linkPattern.matcher( sourceText );
-        
+    private String replaceCCReferrerString( final WikiContext context, final String sourceText, final String from, final String to ) {
+        final StringBuilder sb = new StringBuilder( sourceText.length()+32 );
+        final Pattern linkPattern = Pattern.compile( "\\p{Lu}+\\p{Ll}+\\p{Lu}+[\\p{L}\\p{Digit}]*" );
+        final Matcher matcher = linkPattern.matcher( sourceText );
         int start = 0;
         
-        while( matcher.find(start) )
-        {
-            String match = matcher.group();
-
+        while( matcher.find( start ) ) {
+            final String match = matcher.group();
             sb.append( sourceText.substring( start, matcher.start() ) );
-
-            int lastOpenBrace = sourceText.lastIndexOf( '[', matcher.start() );
-            int lastCloseBrace = sourceText.lastIndexOf( ']', matcher.start() );
+            final int lastOpenBrace = sourceText.lastIndexOf( '[', matcher.start() );
+            final int lastCloseBrace = sourceText.lastIndexOf( ']', matcher.start() );
             
-            if( match.equals( from ) && lastCloseBrace >= lastOpenBrace )
-            {
+            if( match.equals( from ) && lastCloseBrace >= lastOpenBrace ) {
                 sb.append( to );
-            }
-            else
-            {
+            } else {
                 sb.append( match );
             }
             
@@ -291,35 +234,24 @@ public class PageRenamer
         return sb.toString();
     }
 
-    private String replaceReferrerString( WikiContext context, String sourceText, String from, String to )
-    {
-        StringBuilder sb = new StringBuilder( sourceText.length()+32 );
-        
-        //
-        //  This monstrosity just looks for a JSPWiki link pattern.  But it is pretty
-        //  cool for a regexp, isn't it?  If you can understand this in a single reading,
-        //  you have way too much time in your hands.
-        //
-        Pattern linkPattern = Pattern.compile( "([\\[\\~]?)\\[([^\\|\\]]*)(\\|)?([^\\|\\]]*)(\\|)?([^\\|\\]]*)\\]" );
-        
-        Matcher matcher = linkPattern.matcher( sourceText );
+    private String replaceReferrerString( final WikiContext context, final String sourceText, final String from, final String to ) {
+        final StringBuilder sb = new StringBuilder( sourceText.length()+32 );
         
+        // This monstrosity just looks for a JSPWiki link pattern.  But it is pretty cool for a regexp, isn't it?  If you can
+        // understand this in a single reading, you have way too much time in your hands.
+        final Pattern linkPattern = Pattern.compile( "([\\[\\~]?)\\[([^\\|\\]]*)(\\|)?([^\\|\\]]*)(\\|)?([^\\|\\]]*)\\]" );
+        final Matcher matcher = linkPattern.matcher( sourceText );
         int start = 0;
         
-        // System.out.println("====");
-        // System.out.println("SRC="+sourceText.trim());
-        while( matcher.find(start) )
-        {
+        while( matcher.find( start ) ) {
             char charBefore = (char)-1;
             
-            if( matcher.start() > 0 ) 
-                charBefore = sourceText.charAt( matcher.start()-1 );
+            if( matcher.start() > 0 ) {
+                charBefore = sourceText.charAt( matcher.start() - 1 );
+            }
             
-            if( matcher.group(1).length() > 0 || charBefore == '~' || charBefore == '[' ) 
-            {
-                //
+            if( matcher.group(1).length() > 0 || charBefore == '~' || charBefore == '[' ) {
                 //  Found an escape character, so I am escaping.
-                //
                 sb.append( sourceText.substring( start, matcher.end() ) );
                 start = matcher.end();
                 continue;
@@ -327,25 +259,14 @@ public class PageRenamer
 
             String text = matcher.group(2);
             String link = matcher.group(4);
-            String attr = matcher.group(6);
+            final String attr = matcher.group(6);
              
-            /*
-            System.out.println("MATCH="+matcher.group(0));
-            System.out.println("   text="+text);
-            System.out.println("   link="+link);
-            System.out.println("   attr="+attr);
-            */
-            if( link.length() == 0 )
-            {
+            if( link.length() == 0 ) {
                 text = replaceSingleLink( context, text, from, to );
-            }
-            else
-            {
+            } else {
                 link = replaceSingleLink( context, link, from, to );
                 
-                //
                 //  A very simple substitution, but should work for quite a few cases.
-                //
                 text = TextUtil.replaceString( text, from, to );
             }
         
@@ -353,9 +274,13 @@ public class PageRenamer
             //  Construct the new string
             //
             sb.append( sourceText.substring( start, matcher.start() ) );
-            sb.append( "["+text );
-            if( link.length() > 0 ) sb.append( "|" + link );
-            if( attr.length() > 0 ) sb.append( "|" + attr );
+            sb.append( "[" ).append( text );
+            if( link.length() > 0 ) {
+                sb.append( "|" ).append( link );
+            }
+            if( attr.length() > 0 ) {
+                sb.append( "|" ).append( attr );
+            }
             sb.append( "]" );
             
             start = matcher.end();


[jspwiki] 05/06: JSPWIKI-120: PageRenamer renamed as WikiPageRenamer, with new PageRenamer extracted as interface of WikiPageRenamer

Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit ccb852bbefe68a9619b0c49daed8a2871ec2f493
Author: juanpablo <ju...@apache.org>
AuthorDate: Thu Dec 19 23:09:42 2019 +0100

    JSPWIKI-120: PageRenamer renamed as WikiPageRenamer, with new PageRenamer extracted as interface of WikiPageRenamer
---
 .../src/main/java/org/apache/wiki/WikiEngine.java  |   4 +-
 .../java/org/apache/wiki/content/PageRenamer.java  | 302 +--------------------
 .../src/main/resources/ini/classmappings.xml       |   4 +
 .../test/java/org/apache/wiki/WikiEngineTest.java  |  14 +-
 4 files changed, 15 insertions(+), 309 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
index a37e3da..3258915 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -635,10 +635,10 @@ public class WikiEngine  {
         //
         try {
             if( TextUtil.getBooleanProperty( props, RSSGenerator.PROP_GENERATE_RSS,false ) ) {
-                m_rssGenerator = (RSSGenerator)ClassUtil.getMappedObject(RSSGenerator.class.getName(), this, props );
+                m_rssGenerator = ClassUtil.getMappedObject( RSSGenerator.class.getName(), this, props );
             }
 
-            m_pageRenamer = (PageRenamer)ClassUtil.getMappedObject(PageRenamer.class.getName(), this, props );
+            m_pageRenamer = ClassUtil.getMappedObject( PageRenamer.class.getName(), this, props );
         } catch( final Exception e ) {
             log.error( "Unable to start RSS generator - JSPWiki will still work, but there will be no RSS feed.", e );
         }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java b/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
index 0bf86c9..c62b478 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/content/PageRenamer.java
@@ -18,26 +18,8 @@
  */
 package org.apache.wiki.content;
 
-import org.apache.log4j.Logger;
-import org.apache.wiki.InternalWikiException;
 import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
-import org.apache.wiki.WikiPage;
-import org.apache.wiki.api.exceptions.ProviderException;
 import org.apache.wiki.api.exceptions.WikiException;
-import org.apache.wiki.attachment.Attachment;
-import org.apache.wiki.event.WikiEventManager;
-import org.apache.wiki.event.WikiPageRenameEvent;
-import org.apache.wiki.parser.JSPWikiMarkupParser;
-import org.apache.wiki.parser.MarkupParser;
-import org.apache.wiki.util.TextUtil;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 /**
  * Provides page renaming functionality. Note that there used to be a similarly named class in 2.6, but due to unclear copyright, the
@@ -45,12 +27,8 @@ import java.util.regex.Pattern;
  *
  * @since 2.8
  */
-public class PageRenamer {
+public interface PageRenamer {
 
-    private static final Logger log = Logger.getLogger( PageRenamer.class );
-    
-    private boolean m_camelCase = false;
-    
     /**
      *  Renames a page.
      *  
@@ -61,81 +39,7 @@ public class PageRenamer {
      *  @return The final new name (in case it had to be modified)
      *  @throws WikiException If the page cannot be renamed.
      */
-    public String renamePage( final WikiContext context, final String renameFrom, final String renameTo, final boolean changeReferrers ) throws WikiException {
-        //  Sanity checks first
-        if( renameFrom == null || renameFrom.length() == 0 ) {
-            throw new WikiException( "From name may not be null or empty" );
-        }
-        if( renameTo == null || renameTo.length() == 0 ) {
-            throw new WikiException( "To name may not be null or empty" );
-        }
-       
-        //  Clean up the "to" -name so that it does not contain anything illegal
-        final String renameToClean = MarkupParser.cleanLink( renameTo.trim() );
-        if( renameToClean.equals( renameFrom ) ) {
-            throw new WikiException( "You cannot rename the page to itself" );
-        }
-        
-        //  Preconditions: "from" page must exist, and "to" page must not yet exist.
-        final WikiEngine engine = context.getEngine();
-        final WikiPage fromPage = engine.getPage( renameFrom );
-        if( fromPage == null ) {
-            throw new WikiException("No such page "+renameFrom);
-        }
-        WikiPage toPage = engine.getPage( renameToClean );
-        if( toPage != null ) {
-            throw new WikiException( "Page already exists " + renameToClean );
-        }
-        
-        final Set< String > referrers = getReferencesToChange( fromPage, engine );
-
-        //  Do the actual rename by changing from the frompage to the topage, including all of the attachments
-        //  Remove references to attachments under old name
-        final List< Attachment > attachmentsOldName = engine.getAttachmentManager().listAttachments( fromPage );
-        for( final Attachment att: attachmentsOldName ) {
-            final WikiPage fromAttPage = engine.getPage( att.getName() );
-            engine.getReferenceManager().pageRemoved( fromAttPage );
-        }
-
-        engine.getPageManager().getProvider().movePage( renameFrom, renameToClean );
-        if( engine.getAttachmentManager().attachmentsEnabled() ) {
-            engine.getAttachmentManager().getCurrentProvider().moveAttachmentsForPage( renameFrom, renameToClean );
-        }
-        
-        //  Add a comment to the page notifying what changed.  This adds a new revision to the repo with no actual change.
-        toPage = engine.getPage( renameToClean );
-        if( toPage == null ) {
-            throw new InternalWikiException( "Rename seems to have failed for some strange reason - please check logs!" );
-        }
-        toPage.setAttribute( WikiPage.CHANGENOTE, fromPage.getName() + " ==> " + toPage.getName() );
-        toPage.setAuthor( context.getCurrentUser().getName() );
-        engine.getPageManager().putPageText( toPage, engine.getPureText( toPage ) );
-
-        //  Update the references
-        engine.getReferenceManager().pageRemoved( fromPage );
-        engine.updateReferences( toPage );
-
-        //  Update referrers
-        if( changeReferrers ) {
-            updateReferrers( context, fromPage, toPage, referrers );
-        }
-
-        //  re-index the page including its attachments
-        engine.getSearchManager().reindexPage( toPage );
-        
-        final Collection< Attachment > attachmentsNewName = engine.getAttachmentManager().listAttachments( toPage );
-        for( final Attachment att:attachmentsNewName ) {
-            final WikiPage toAttPage = engine.getPage( att.getName() );
-            // add reference to attachment under new page name
-            engine.updateReferences( toAttPage );
-            engine.getSearchManager().reindexPage( att );
-        }
-
-        firePageRenameEvent( renameFrom, renameToClean );
-
-        //  Done, return the new name.
-        return renameToClean;
-    }
+    String renamePage( WikiContext context, String renameFrom, String renameTo, boolean changeReferrers ) throws WikiException;
 
     /**
      * Fires a WikiPageRenameEvent to all registered listeners. Currently not used internally by JSPWiki itself, but you can use it for
@@ -144,206 +48,6 @@ public class PageRenamer {
      * @param oldName the former page name
      * @param newName the new page name
      */
-    public void firePageRenameEvent( final String oldName, final String newName ) {
-        if( WikiEventManager.isListening(this) ) {
-            WikiEventManager.fireEvent(this, new WikiPageRenameEvent(this, oldName, newName ) );
-        }
-    }
-
-    /**
-     *  This method finds all the pages which have anything to do with the fromPage and
-     *  change any referrers it can figure out in that page.
-     *  
-     *  @param context WikiContext in which we operate
-     *  @param fromPage The old page
-     *  @param toPage The new page
-     */
-    private void updateReferrers( final WikiContext context, final WikiPage fromPage, final WikiPage toPage, final Set< String > referrers ) {
-        if( referrers.isEmpty() ) { // No referrers
-            return;
-        }
-
-        final WikiEngine engine = context.getEngine();
-        for( String pageName : referrers ) {
-            //  In case the page was just changed from under us, let's do this small kludge.
-            if( pageName.equals( fromPage.getName() ) ) {
-                pageName = toPage.getName();
-            }
-            
-            final WikiPage p = engine.getPage( pageName );
-
-            final String sourceText = engine.getPureText( p );
-            String newText = replaceReferrerString( context, sourceText, fromPage.getName(), toPage.getName() );
-
-            m_camelCase = TextUtil.getBooleanProperty( engine.getWikiProperties(), JSPWikiMarkupParser.PROP_CAMELCASELINKS, m_camelCase );
-            if( m_camelCase ) {
-                newText = replaceCCReferrerString( context, newText, fromPage.getName(), toPage.getName() );
-            }
-            
-            if( !sourceText.equals( newText ) ) {
-                p.setAttribute( WikiPage.CHANGENOTE, fromPage.getName()+" ==> "+toPage.getName() );
-                p.setAuthor( context.getCurrentUser().getName() );
-         
-                try {
-                    engine.getPageManager().putPageText( p, newText );
-                    engine.updateReferences( p );
-                } catch( final ProviderException e ) {
-                    //  We fail with an error, but we will try to continue to rename other referrers as well.
-                    log.error("Unable to perform rename.",e);
-                }
-            }
-        }
-    }
-
-    private Set<String> getReferencesToChange( final WikiPage fromPage, final WikiEngine engine ) {
-        final Set< String > referrers = new TreeSet<>();
-        final Collection< String > r = engine.getReferenceManager().findReferrers( fromPage.getName() );
-        if( r != null ) {
-            referrers.addAll( r );
-        }
-        
-        try {
-            final List< Attachment > attachments = engine.getAttachmentManager().listAttachments( fromPage );
-            for( final Attachment att : attachments  ) {
-                final Collection< String > c = engine.getReferenceManager().findReferrers( att.getName() );
-                if( c != null ) {
-                    referrers.addAll( c );
-                }
-            }
-        } catch( final ProviderException e ) {
-            // We will continue despite this error
-            log.error( "Provider error while fetching attachments for rename", e );
-        }
-        return referrers;
-    }
-
-    /**
-     *  Replaces camelcase links.
-     */
-    private String replaceCCReferrerString( final WikiContext context, final String sourceText, final String from, final String to ) {
-        final StringBuilder sb = new StringBuilder( sourceText.length()+32 );
-        final Pattern linkPattern = Pattern.compile( "\\p{Lu}+\\p{Ll}+\\p{Lu}+[\\p{L}\\p{Digit}]*" );
-        final Matcher matcher = linkPattern.matcher( sourceText );
-        int start = 0;
-        
-        while( matcher.find( start ) ) {
-            final String match = matcher.group();
-            sb.append( sourceText.substring( start, matcher.start() ) );
-            final int lastOpenBrace = sourceText.lastIndexOf( '[', matcher.start() );
-            final int lastCloseBrace = sourceText.lastIndexOf( ']', matcher.start() );
-            
-            if( match.equals( from ) && lastCloseBrace >= lastOpenBrace ) {
-                sb.append( to );
-            } else {
-                sb.append( match );
-            }
-            
-            start = matcher.end();
-        }
-        
-        sb.append( sourceText.substring( start ) );
-        
-        return sb.toString();
-    }
-
-    private String replaceReferrerString( final WikiContext context, final String sourceText, final String from, final String to ) {
-        final StringBuilder sb = new StringBuilder( sourceText.length()+32 );
-        
-        // This monstrosity just looks for a JSPWiki link pattern.  But it is pretty cool for a regexp, isn't it?  If you can
-        // understand this in a single reading, you have way too much time in your hands.
-        final Pattern linkPattern = Pattern.compile( "([\\[\\~]?)\\[([^\\|\\]]*)(\\|)?([^\\|\\]]*)(\\|)?([^\\|\\]]*)\\]" );
-        final Matcher matcher = linkPattern.matcher( sourceText );
-        int start = 0;
-        
-        while( matcher.find( start ) ) {
-            char charBefore = (char)-1;
-            
-            if( matcher.start() > 0 ) {
-                charBefore = sourceText.charAt( matcher.start() - 1 );
-            }
-            
-            if( matcher.group(1).length() > 0 || charBefore == '~' || charBefore == '[' ) {
-                //  Found an escape character, so I am escaping.
-                sb.append( sourceText.substring( start, matcher.end() ) );
-                start = matcher.end();
-                continue;
-            }
-
-            String text = matcher.group(2);
-            String link = matcher.group(4);
-            final String attr = matcher.group(6);
-             
-            if( link.length() == 0 ) {
-                text = replaceSingleLink( context, text, from, to );
-            } else {
-                link = replaceSingleLink( context, link, from, to );
-                
-                //  A very simple substitution, but should work for quite a few cases.
-                text = TextUtil.replaceString( text, from, to );
-            }
-        
-            //
-            //  Construct the new string
-            //
-            sb.append( sourceText.substring( start, matcher.start() ) );
-            sb.append( "[" ).append( text );
-            if( link.length() > 0 ) {
-                sb.append( "|" ).append( link );
-            }
-            if( attr.length() > 0 ) {
-                sb.append( "|" ).append( attr );
-            }
-            sb.append( "]" );
-            
-            start = matcher.end();
-        }
-        
-        sb.append( sourceText.substring( start ) );
-        
-        return sb.toString();
-    }
-
-    /**
-     *  This method does a correct replacement of a single link, taking into account anchors and attachments.
-     */
-    private String replaceSingleLink( final WikiContext context, final String original, final String from, final String newlink ) {
-        final int hash = original.indexOf( '#' );
-        final int slash = original.indexOf( '/' );
-        String realLink = original;
-
-        if( hash != -1 ) {
-            realLink = original.substring( 0, hash );
-        }
-        if( slash != -1 ) {
-            realLink = original.substring( 0,slash );
-        }
+    void firePageRenameEvent( String oldName, String newName );
 
-        realLink = MarkupParser.cleanLink( realLink );
-        final String oldStyleRealLink = MarkupParser.wikifyLink( realLink );
-        
-        //WikiPage realPage  = context.getEngine().getPage( reallink );
-        // WikiPage p2 = context.getEngine().getPage( from );
-        
-        // System.out.println("   "+reallink+" :: "+ from);
-        // System.out.println("   "+p+" :: "+p2);
-        
-        //
-        //  Yes, these point to the same page.
-        //
-        if( realLink.equals( from ) || original.equals( from ) || oldStyleRealLink.equals( from ) ) {
-            //
-            //  if the original contains blanks, then we should introduce a link, for example:  [My Page]  =>  [My Page|My Renamed Page]
-            final int blank = realLink.indexOf( " ");
-            
-            if( blank != -1 ) {
-                return original + "|" + newlink;
-            }
-            
-            return newlink +
-                   ( ( hash > 0 ) ? original.substring( hash ) : "" ) +
-                   ( ( slash > 0 ) ? original.substring( slash ) : "" ) ;
-        }
-        
-        return original;
-    }
 }
diff --git a/jspwiki-main/src/main/resources/ini/classmappings.xml b/jspwiki-main/src/main/resources/ini/classmappings.xml
index a0f1cc9..649f034 100644
--- a/jspwiki-main/src/main/resources/ini/classmappings.xml
+++ b/jspwiki-main/src/main/resources/ini/classmappings.xml
@@ -96,6 +96,10 @@
     <mappedClass>org.apache.wiki.auth.authorize.GroupManager</mappedClass>
   </mapping>
   <mapping>
+    <requestedClass>org.apache.wiki.content.PageRenamer</requestedClass>
+    <mappedClass>org.apache.wiki.content.WikiPageRenamer</mappedClass>
+  </mapping>
+  <mapping>
     <requestedClass>org.apache.wiki.diff.DifferenceManager</requestedClass>
     <mappedClass>org.apache.wiki.diff.DifferenceManager</mappedClass>
   </mapping>
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java b/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
index 6faa84f..aa6ab6b 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
@@ -19,12 +19,7 @@
 
 package org.apache.wiki;
 
-import java.io.File;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-
-import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
+import net.sf.ehcache.CacheManager;
 import org.apache.wiki.attachment.Attachment;
 import org.apache.wiki.attachment.AttachmentManager;
 import org.apache.wiki.pages.PageManager;
@@ -38,7 +33,10 @@ import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import net.sf.ehcache.CacheManager;
+import java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
 
 public class WikiEngineTest
 {
@@ -766,7 +764,7 @@ public class WikiEngineTest
 
         WikiContext ctx = new WikiContext( m_engine, m_engine.getPage("OldNameTestPage") );
 
-        m_engine.renamePage( ctx, "OldNameTestPage", "NewNameTestPage", true );
+        m_engine.getPageRenamer().renamePage( ctx, "OldNameTestPage", "NewNameTestPage", true );
 
         Assertions.assertFalse( m_engine.pageExists( "OldNameTestPage"), "did not vanish" );
         Assertions.assertTrue( m_engine.pageExists( "NewNameTestPage"), "did not appear" );