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/20 18:20:22 UTC

[jspwiki] branch master updated (9b61776 -> 528d825)

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 9b61776  forgot to add WikiPageRenamer on last commit.. this should fix the build
     new f620efd  remove unnecessary FIXME: + intellij fixes
     new 56087e3  JSPWIKI-120: move getVariable(..) method from WikiEngine to VariableManager
     new 4237992  more formatting + intellij fixes on VariableManager
     new 203213b  JSPWIKI-120: rename VariableManager as WikiVariableManager and extract interface from it (again, VariableManager)
     new e0f1975  intellij format + fixes
     new 00bec87  JSPWIKI-120: move getDiff from WikiEngine to DifferenceManager
     new 15196d6  get rid of final on method parameters, is not needed there
     new b1b73c0  JSPWIKI-120: move getDiff from WikiEngine to DifferenceManager
     new 94306ff  JSPWIKI-120: rename DifferenceManager as WikiDifferenceManager and extract interface from it (again, DifferenceManager)
     new 528d825  2.11.0-M7-git-02

The 10 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                                       |  10 +
 .../src/main/java/org/apache/wiki/Release.java     |   2 +-
 .../main/java/org/apache/wiki/VariableManager.java | 435 ++-------------------
 .../src/main/java/org/apache/wiki/WikiContext.java |   2 +-
 .../src/main/java/org/apache/wiki/WikiEngine.java  |  60 +--
 ...riableManager.java => WikiVariableManager.java} | 313 +++++++--------
 .../apache/wiki/diff/ContextualDiffProvider.java   | 311 ++++++---------
 .../java/org/apache/wiki/diff/DiffProvider.java    |  22 +-
 .../org/apache/wiki/diff/DifferenceManager.java    |  92 +----
 .../org/apache/wiki/diff/ExternalDiffProvider.java |  80 ++--
 .../apache/wiki/diff/TraditionalDiffProvider.java  | 135 +++----
 .../apache/wiki/diff/WikiDifferenceManager.java    | 128 ++++++
 .../org/apache/wiki/pages/PageTimeComparator.java  |  17 +-
 .../main/java/org/apache/wiki/plugin/IfPlugin.java |  38 +-
 .../main/java/org/apache/wiki/rss/RSS20Feed.java   |  35 +-
 .../java/org/apache/wiki/rss/RSSGenerator.java     | 148 +++----
 .../java/org/apache/wiki/tags/InsertDiffTag.java   |  51 +--
 .../src/main/resources/ini/classmappings.xml       |   4 +-
 .../java/org/apache/wiki/VariableManagerTest.java  | 194 ---------
 .../org/apache/wiki/WikiVariableManagerTest.java   | 109 ++++++
 .../wiki/diff/ContextualDiffProviderTest.java      |  30 +-
 .../src/main/webapp/templates/210/DiffTab.jsp      |   2 +-
 .../src/main/webapp/templates/default/DiffTab.jsp  |   2 +-
 23 files changed, 793 insertions(+), 1427 deletions(-)
 copy jspwiki-main/src/main/java/org/apache/wiki/{VariableManager.java => WikiVariableManager.java} (59%)
 create mode 100644 jspwiki-main/src/main/java/org/apache/wiki/diff/WikiDifferenceManager.java
 delete mode 100644 jspwiki-main/src/test/java/org/apache/wiki/VariableManagerTest.java
 create mode 100644 jspwiki-main/src/test/java/org/apache/wiki/WikiVariableManagerTest.java


[jspwiki] 01/10: remove unnecessary FIXME: + intellij fixes

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 f620efd2b4194afd9a95b79aca57f040538e92f9
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 16:40:43 2019 +0100

    remove unnecessary FIXME: + intellij fixes
---
 .../java/org/apache/wiki/pages/PageTimeComparator.java  | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/pages/PageTimeComparator.java b/jspwiki-main/src/main/java/org/apache/wiki/pages/PageTimeComparator.java
index 588ff26..b410bb0 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/pages/PageTimeComparator.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/pages/PageTimeComparator.java
@@ -18,13 +18,13 @@
  */
 package org.apache.wiki.pages;
 
+import org.apache.log4j.Logger;
+import org.apache.wiki.WikiPage;
+
 import java.io.Serializable;
 import java.util.Comparator;
 import java.util.Date;
 
-import org.apache.log4j.Logger;
-import org.apache.wiki.WikiPage;
-
 /**
  *  Compares the lastModified date of its arguments.  Both o1 and o2 MUST
  *  be WikiPage objects, or else you will receive a ClassCastException.
@@ -32,8 +32,7 @@ import org.apache.wiki.WikiPage;
  *  If the lastModified date is the same, then the next key is the page name.
  *  If the page name is also equal, then returns 0 for equality.
  */
-// FIXME: Does not implement equals().
-public class PageTimeComparator implements Comparator<WikiPage>, Serializable {
+public class PageTimeComparator implements Comparator< WikiPage >, Serializable {
 	
     private static final long serialVersionUID = 0L;
 
@@ -42,14 +41,14 @@ public class PageTimeComparator implements Comparator<WikiPage>, Serializable {
     /**
      *  {@inheritDoc}
      */
-    public int compare( WikiPage w1, WikiPage w2 ) {
+    public int compare( final WikiPage w1, final WikiPage w2 ) {
         if( w1 == null || w2 == null ) {
             log.error( "W1 or W2 is NULL in PageTimeComparator!");
             return 0; // FIXME: Is this correct?
         }
 
-        Date w1LastMod = w1.getLastModified();
-        Date w2LastMod = w2.getLastModified();
+        final Date w1LastMod = w1.getLastModified();
+        final Date w2LastMod = w2.getLastModified();
 
         if( w1LastMod == null ) {
             log.error( "NULL MODIFY DATE WITH " + w1.getName() );
@@ -60,7 +59,7 @@ public class PageTimeComparator implements Comparator<WikiPage>, Serializable {
         }
 
         // This gets most recent on top
-        int timecomparison = w2LastMod.compareTo( w1LastMod );
+        final int timecomparison = w2LastMod.compareTo( w1LastMod );
 
         if( timecomparison == 0 ) {
             return w1.compareTo( w2 );


[jspwiki] 09/10: JSPWIKI-120: rename DifferenceManager as WikiDifferenceManager and extract interface from it (again, DifferenceManager)

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 94306fff73d16bb7e1b7f527beef25d17890b1cf
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 19:19:06 2019 +0100

    JSPWIKI-120: rename DifferenceManager as WikiDifferenceManager and extract interface from it (again, DifferenceManager)
---
 .../org/apache/wiki/diff/DifferenceManager.java    | 82 ++--------------------
 ...enceManager.java => WikiDifferenceManager.java} |  9 +--
 .../src/main/resources/ini/classmappings.xml       |  2 +-
 3 files changed, 8 insertions(+), 85 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
index bf46bde..a068632 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
@@ -19,66 +19,16 @@
 
 package org.apache.wiki.diff;
 
-import org.apache.log4j.Logger;
 import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiEngine;
-import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
-import org.apache.wiki.providers.WikiPageProvider;
-import org.apache.wiki.util.ClassUtil;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Properties;
 
 
 /**
  * Load, initialize and delegate to the DiffProvider that will actually do the work.
  */
-public class DifferenceManager {
-
-    private static final Logger log = Logger.getLogger( DifferenceManager.class );
+public interface DifferenceManager {
 
     /** Property value for storing a diff provider.  Value is {@value}. */
-    public static final String PROP_DIFF_PROVIDER = "jspwiki.diffProvider";
-
-    private DiffProvider m_provider;
-
-    /**
-     * Creates a new DifferenceManager for the given engine.
-     *
-     * @param engine The WikiEngine.
-     * @param props  A set of properties.
-     */
-    public DifferenceManager( final WikiEngine engine, final Properties props ) {
-        loadProvider( props );
-        initializeProvider( engine, props );
-
-        log.info( "Using difference provider: " + m_provider.getProviderInfo() );
-    }
-
-    private void loadProvider( final Properties props ) {
-        final String providerClassName = props.getProperty( PROP_DIFF_PROVIDER, TraditionalDiffProvider.class.getName() );
-        try {
-            final Class< ? > providerClass = ClassUtil.findClass("org.apache.wiki.diff", providerClassName );
-            m_provider = (DiffProvider) providerClass.getDeclaredConstructor().newInstance();
-        } catch( final ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e ) {
-            log.warn("Failed loading DiffProvider, will use NullDiffProvider.", e);
-        }
-
-        if( m_provider == null ) {
-            m_provider = new DiffProvider.NullDiffProvider();
-        }
-    }
-
-
-    private void initializeProvider( final WikiEngine engine, final Properties props ) {
-        try {
-            m_provider.initialize(engine, props);
-        } catch( final NoRequiredPropertyException | IOException e1 ) {
-            log.warn("Failed initializing DiffProvider, will use NullDiffProvider.", e1);
-            m_provider = new DiffProvider.NullDiffProvider(); //doesn't need init'd
-        }
-    }
+    String PROP_DIFF_PROVIDER = "jspwiki.diffProvider";
 
     /**
      * Returns valid XHTML string to be used in any way you please.
@@ -88,20 +38,7 @@ public class DifferenceManager {
      * @param secondWikiText the new text
      * @return XHTML, or empty string, if no difference detected.
      */
-    public String makeDiff( final WikiContext context, final String firstWikiText, final String secondWikiText ) {
-        String diff;
-        try {
-            diff = m_provider.makeDiffHtml( context, firstWikiText, secondWikiText );
-
-            if( diff == null ) {
-                diff = "";
-            }
-        } catch( final Exception e ) {
-            diff = "Failed to create a diff, check the logs.";
-            log.warn( diff, e );
-        }
-        return diff;
-    }
+    String makeDiff( WikiContext context, String firstWikiText, String secondWikiText );
 
     /**
      *  Returns a diff of two versions of a page.
@@ -114,18 +51,7 @@ public class DifferenceManager {
      *
      *  @return A HTML-ized difference between two pages.  If there is no difference, returns an empty string.
      */
-    public String getDiff( final WikiContext context, final int version1, final int version2 ) {
-        final String page = context.getPage().getName();
-        String page1 = context.getEngine().getPureText( page, version1 );
-        final String page2 = context.getEngine().getPureText( page, version2 );
-
-        // Kludge to make diffs for new pages to work this way.
-        if( version1 == WikiPageProvider.LATEST_VERSION ) {
-            page1 = "";
-        }
-
-        return makeDiff( context, page1, page2 );
-    }
+    String getDiff( WikiContext context, int version1, int version2 );
 
 }
 
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/WikiDifferenceManager.java
similarity index 93%
copy from jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
copy to jspwiki-main/src/main/java/org/apache/wiki/diff/WikiDifferenceManager.java
index bf46bde..e7100ad 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/WikiDifferenceManager.java
@@ -34,12 +34,9 @@ import java.util.Properties;
 /**
  * Load, initialize and delegate to the DiffProvider that will actually do the work.
  */
-public class DifferenceManager {
+public class WikiDifferenceManager implements DifferenceManager {
 
-    private static final Logger log = Logger.getLogger( DifferenceManager.class );
-
-    /** Property value for storing a diff provider.  Value is {@value}. */
-    public static final String PROP_DIFF_PROVIDER = "jspwiki.diffProvider";
+    private static final Logger log = Logger.getLogger( WikiDifferenceManager.class );
 
     private DiffProvider m_provider;
 
@@ -49,7 +46,7 @@ public class DifferenceManager {
      * @param engine The WikiEngine.
      * @param props  A set of properties.
      */
-    public DifferenceManager( final WikiEngine engine, final Properties props ) {
+    public WikiDifferenceManager( final WikiEngine engine, final Properties props ) {
         loadProvider( props );
         initializeProvider( engine, props );
 
diff --git a/jspwiki-main/src/main/resources/ini/classmappings.xml b/jspwiki-main/src/main/resources/ini/classmappings.xml
index 90d13d3..7a2ca54 100644
--- a/jspwiki-main/src/main/resources/ini/classmappings.xml
+++ b/jspwiki-main/src/main/resources/ini/classmappings.xml
@@ -101,7 +101,7 @@
   </mapping>
   <mapping>
     <requestedClass>org.apache.wiki.diff.DifferenceManager</requestedClass>
-    <mappedClass>org.apache.wiki.diff.DifferenceManager</mappedClass>
+    <mappedClass>org.apache.wiki.diff.WikiDifferenceManager</mappedClass>
   </mapping>
   <mapping>
     <requestedClass>org.apache.wiki.i18n.InternationalizationManager</requestedClass>


[jspwiki] 06/10: JSPWIKI-120: move getDiff from WikiEngine to DifferenceManager

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 00bec876ee7ae7b2d76ece26554cca7b257d6975
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 19:09:17 2019 +0100

    JSPWIKI-120: move getDiff from WikiEngine to DifferenceManager
---
 .../apache/wiki/diff/ContextualDiffProvider.java   | 24 ++++----
 .../org/apache/wiki/diff/DifferenceManager.java    | 31 +++++++++-
 .../java/org/apache/wiki/rss/RSSGenerator.java     | 66 +++++++---------------
 .../java/org/apache/wiki/tags/InsertDiffTag.java   | 51 +++++++----------
 .../wiki/diff/ContextualDiffProviderTest.java      | 30 +++++-----
 5 files changed, 95 insertions(+), 107 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
index 4b4ee3b..27077c0 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
@@ -63,27 +63,27 @@ public class ContextualDiffProvider implements DiffProvider {
     public boolean m_emitChangeNextPreviousHyperlinks = true;
 
     //Don't use spans here the deletion and insertions are nested in this...
-    public static final String CHANGE_START_HTML = ""; //This could be a image '>' for a start marker
-    public static final String CHANGE_END_HTML = ""; //and an image for an end '<' marker
-    public static final String DIFF_START = "<div class=\"diff-wikitext\">";
-    public static final String DIFF_END = "</div>";
+    public static String CHANGE_START_HTML = ""; //This could be a image '>' for a start marker
+    public static String CHANGE_END_HTML = ""; //and an image for an end '<' marker
+    public static String DIFF_START = "<div class=\"diff-wikitext\">";
+    public static String DIFF_END = "</div>";
 
     // Unfortunately we need to do dumb HTML here for RSS feeds.
 
-    public static final String INSERTION_START_HTML = "<font color=\"#8000FF\"><span class=\"diff-insertion\">";
-    public static final String INSERTION_END_HTML = "</span></font>";
-    public static final String DELETION_START_HTML = "<strike><font color=\"red\"><span class=\"diff-deletion\">";
-    public static final String DELETION_END_HTML = "</span></font></strike>";
+    public static String INSERTION_START_HTML = "<font color=\"#8000FF\"><span class=\"diff-insertion\">";
+    public static String INSERTION_END_HTML = "</span></font>";
+    public static String DELETION_START_HTML = "<strike><font color=\"red\"><span class=\"diff-deletion\">";
+    public static String DELETION_END_HTML = "</span></font></strike>";
     private static final String ANCHOR_PRE_INDEX = "<a name=\"change-";
     private static final String ANCHOR_POST_INDEX = "\" />";
     private static final String BACK_PRE_INDEX = "<a class=\"diff-nextprev\" title=\"Go to previous change\" href=\"#change-";
     private static final String BACK_POST_INDEX = "\">&lt;&lt;</a>";
     private static final String FORWARD_PRE_INDEX = "<a class=\"diff-nextprev\" title=\"Go to next change\" href=\"#change-";
     private static final String FORWARD_POST_INDEX = "\">&gt;&gt;</a>";
-    public static final String ELIDED_HEAD_INDICATOR_HTML = "<br/><br/><b>...</b>";
-    public static final String ELIDED_TAIL_INDICATOR_HTML = "<b>...</b><br/><br/>";
-    public static final String LINE_BREAK_HTML = "<br />";
-    public static final String ALTERNATING_SPACE_HTML = "&nbsp;";
+    public static String ELIDED_HEAD_INDICATOR_HTML = "<br/><br/><b>...</b>";
+    public static String ELIDED_TAIL_INDICATOR_HTML = "<b>...</b><br/><br/>";
+    public static String LINE_BREAK_HTML = "<br />";
+    public static String ALTERNATING_SPACE_HTML = "&nbsp;";
 
     // This one, I will make property file based...
     private static final int LIMIT_MAX_VALUE = (Integer.MAX_VALUE /2) - 1;
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
index 6643847..bf46bde 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
@@ -23,6 +23,7 @@ import org.apache.log4j.Logger;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
+import org.apache.wiki.providers.WikiPageProvider;
 import org.apache.wiki.util.ClassUtil;
 
 import java.io.IOException;
@@ -34,11 +35,10 @@ import java.util.Properties;
  * Load, initialize and delegate to the DiffProvider that will actually do the work.
  */
 public class DifferenceManager {
+
     private static final Logger log = Logger.getLogger( DifferenceManager.class );
 
-    /**
-     * Property value for storing a diff provider.  Value is {@value}.
-     */
+    /** Property value for storing a diff provider.  Value is {@value}. */
     public static final String PROP_DIFF_PROVIDER = "jspwiki.diffProvider";
 
     private DiffProvider m_provider;
@@ -102,5 +102,30 @@ public class DifferenceManager {
         }
         return diff;
     }
+
+    /**
+     *  Returns a diff of two versions of a page.
+     *  <p>
+     *  Note that the API was changed in 2.6 to provide a WikiContext object!
+     *
+     *  @param context The WikiContext of the page you wish to get a diff from
+     *  @param version1 Version number of the old page.  If WikiPageProvider.LATEST_VERSION (-1), then uses current page.
+     *  @param version2 Version number of the new page.  If WikiPageProvider.LATEST_VERSION (-1), then uses current page.
+     *
+     *  @return A HTML-ized difference between two pages.  If there is no difference, returns an empty string.
+     */
+    public String getDiff( final WikiContext context, final int version1, final int version2 ) {
+        final String page = context.getPage().getName();
+        String page1 = context.getEngine().getPureText( page, version1 );
+        final String page2 = context.getEngine().getPureText( page, version2 );
+
+        // Kludge to make diffs for new pages to work this way.
+        if( version1 == WikiPageProvider.LATEST_VERSION ) {
+            page1 = "";
+        }
+
+        return makeDiff( context, page1, page2 );
+    }
+
 }
 
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java b/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
index 058d9e6..1c21260 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
@@ -194,9 +194,9 @@ public class RSSGenerator {
         WikiContext ctx = new WikiContext( m_engine, page );
         if( page.getVersion() > 1 )
         {
-            String diff = m_engine.getDiff( ctx,
-                                            page.getVersion()-1, // FIXME: Will fail when non-contiguous versions
-                                            page.getVersion() );
+            String diff = m_engine.getDifferenceManager().getDiff( ctx,
+                                                          page.getVersion() - 1, // FIXME: Will fail when non-contiguous versions
+                                                                   page.getVersion() );
 
             buf.append(author+" changed this page on "+page.getLastModified()+":<br /><hr /><br />" );
             buf.append(diff);
@@ -238,17 +238,11 @@ public class RSSGenerator {
      *  
      *  @return A RSS 1.0 feed in the "full" mode.
      */
-    public String generate()
-    {
-        WikiContext context = new WikiContext( m_engine,new WikiPage( m_engine, "__DUMMY" ) );
+    public String generate() {
+        final WikiContext context = new WikiContext( m_engine,new WikiPage( m_engine, "__DUMMY" ) );
         context.setRequestContext( WikiContext.RSS );
-        Feed feed = new RSS10Feed( context );
-
-        String result = generateFullWikiRSS( context, feed );
-
-        result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + result;
-
-        return result;
+        final Feed feed = new RSS10Feed( context );
+        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + generateFullWikiRSS( context, feed );
     }
 
     /**
@@ -257,14 +251,10 @@ public class RSSGenerator {
      * @param mode the RSS mode: {@link #RSS10}, {@link #RSS20} or {@link #ATOM}.
      * @return the content type
      */
-    public static String getContentType( String mode )
-    {
-        if( mode.equals( RSS10 )||mode.equals(RSS20) )
-        {
+    public static String getContentType( final String mode ) {
+        if( mode.equals( RSS10 ) || mode.equals( RSS20 ) ) {
             return "application/rss+xml";
-        }
-        else if( mode.equals(ATOM) )
-        {
+        } else if( mode.equals( ATOM ) ) {
             return "application/atom+xml";
         }
 
@@ -282,41 +272,27 @@ public class RSSGenerator {
      * @throws ProviderException If the underlying provider failed.
      * @throws IllegalArgumentException If an illegal mode is given.
      */
-    public String generateFeed( WikiContext wikiContext, List< WikiPage > changed, String mode, String type )
-        throws ProviderException, IllegalArgumentException
-    {
-        Feed feed = null;
-        String res = null;
+    public String generateFeed( final WikiContext wikiContext, final List< WikiPage > changed, final String mode, final String type ) throws IllegalArgumentException {
+        final Feed feed;
+        final String res;
 
-        if( ATOM.equals(type) )
-        {
+        if( ATOM.equals(type) ) {
             feed = new AtomFeed( wikiContext );
-        }
-        else if( RSS20.equals( type ) )
-        {
+        } else if( RSS20.equals( type ) ) {
             feed = new RSS20Feed( wikiContext );
-        }
-        else
-        {
+        } else {
             feed = new RSS10Feed( wikiContext );
         }
 
         feed.setMode( mode );
 
-        if( MODE_BLOG.equals( mode ) )
-        {
+        if( MODE_BLOG.equals( mode ) ) {
             res = generateBlogRSS( wikiContext, changed, feed );
-        }
-        else if( MODE_FULL.equals(mode) )
-        {
+        } else if( MODE_FULL.equals(mode) ) {
             res = generateFullWikiRSS( wikiContext, feed );
-        }
-        else if( MODE_WIKI.equals(mode) )
-        {
+        } else if( MODE_WIKI.equals(mode) ) {
             res = generateWikiPageRSS( wikiContext, changed, feed );
-        }
-        else
-        {
+        } else {
             throw new IllegalArgumentException( "Invalid value for feed mode: "+mode );
         }
 
@@ -340,7 +316,7 @@ public class RSSGenerator {
      * methods output anything.
      * @param enabled whether RSS generation is considered enabled.
      */
-    public synchronized void setEnabled( boolean enabled )
+    public synchronized void setEnabled( final boolean enabled )
     {
         m_enabled = enabled;
     }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/InsertDiffTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/InsertDiffTag.java
index 211bc79..761eff0 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/InsertDiffTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/InsertDiffTag.java
@@ -18,15 +18,14 @@
  */
 package org.apache.wiki.tags;
 
-import java.io.IOException;
-
-import javax.servlet.jsp.JspWriter;
-import javax.servlet.jsp.PageContext;
-
 import org.apache.log4j.Logger;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
 
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
+import java.io.IOException;
+
 /**
  *  Writes difference between two pages using a HTML table.  If there is
  *  no difference, includes the body.
@@ -52,8 +51,7 @@ public class InsertDiffTag extends WikiTagBase {
     protected String m_pageName;
 
     /** {@inheritDoc} */
-    public void initTag()
-    {
+    public void initTag() {
         super.initTag();
         m_pageName = null;
     }
@@ -62,7 +60,7 @@ public class InsertDiffTag extends WikiTagBase {
      *  Sets the page name.
      *  @param page Page to get diff from.
      */
-    public void setPage( String page )
+    public void setPage( final String page )
     {
         m_pageName = page;
     }
@@ -77,39 +75,27 @@ public class InsertDiffTag extends WikiTagBase {
     }
 
     /** {@inheritDoc} */
-    public final int doWikiStartTag()
-        throws IOException
-    {
-        WikiEngine engine = m_wikiContext.getEngine();
-        WikiContext ctx;
+    public final int doWikiStartTag() throws IOException {
+        final WikiEngine engine = m_wikiContext.getEngine();
+        final WikiContext ctx;
         
-        if( m_pageName == null )
-        {
+        if( m_pageName == null ) {
             ctx = m_wikiContext;
-        }
-        else
-        {
-            ctx = (WikiContext)m_wikiContext.clone();
+        } else {
+            ctx = ( WikiContext )m_wikiContext.clone();
             ctx.setPage( engine.getPage(m_pageName) );
         }
 
-        Integer vernew = (Integer) pageContext.getAttribute( ATTR_NEWVERSION,
-                                                             PageContext.REQUEST_SCOPE );
-        Integer verold = (Integer) pageContext.getAttribute( ATTR_OLDVERSION,
-                                                             PageContext.REQUEST_SCOPE );
+        final Integer vernew = ( Integer )pageContext.getAttribute( ATTR_NEWVERSION, PageContext.REQUEST_SCOPE );
+        final Integer verold = ( Integer )pageContext.getAttribute( ATTR_OLDVERSION, PageContext.REQUEST_SCOPE );
 
         log.debug("Request diff between version "+verold+" and "+vernew);
 
-        if( ctx.getPage() != null )
-        {
-            JspWriter out = pageContext.getOut();
-
-            String diff = engine.getDiff( ctx, 
-                                          vernew.intValue(), 
-                                          verold.intValue() );
+        if( ctx.getPage() != null ) {
+            final JspWriter out = pageContext.getOut();
+            final String diff = engine.getDifferenceManager().getDiff( ctx, vernew.intValue(), verold.intValue() );
 
-            if( diff.length() == 0 )
-            {
+            if( diff.length() == 0 ) {
                 return EVAL_BODY_INCLUDE;
             }
 
@@ -118,5 +104,6 @@ public class InsertDiffTag extends WikiTagBase {
 
         return SKIP_BODY;
     }
+
 }
 
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/diff/ContextualDiffProviderTest.java b/jspwiki-main/src/test/java/org/apache/wiki/diff/ContextualDiffProviderTest.java
index f2181d1..d2432bb 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/diff/ContextualDiffProviderTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/diff/ContextualDiffProviderTest.java
@@ -18,9 +18,6 @@
  */
 package org.apache.wiki.diff;
 
-import java.io.IOException;
-import java.util.Properties;
-
 import org.apache.log4j.PropertyConfigurator;
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiContext;
@@ -29,6 +26,9 @@ import org.apache.wiki.api.exceptions.WikiException;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
+import java.io.IOException;
+import java.util.Properties;
+
 public class ContextualDiffProviderTest
 {
     /**
@@ -40,25 +40,25 @@ public class ContextualDiffProviderTest
      */
     private void specializedNotation(ContextualDiffProvider diff)
     {
-        diff.m_changeEndHtml = "|";
-        diff.m_changeStartHtml = "|";
+        diff.CHANGE_END_HTML = "|";
+        diff.CHANGE_START_HTML = "|";
 
-        diff.m_deletionEndHtml = "-";
-        diff.m_deletionStartHtml = "-";
+        diff.DELETION_END_HTML = "-";
+        diff.DELETION_START_HTML = "-";
 
-        diff.m_diffEnd = "";
-        diff.m_diffStart = "";
+        diff.DIFF_END = "";
+        diff.DIFF_START = "";
 
-        diff.m_elidedHeadIndicatorHtml = "...";
-        diff.m_elidedTailIndicatorHtml = "...";
+        diff.ELIDED_HEAD_INDICATOR_HTML = "...";
+        diff.ELIDED_TAIL_INDICATOR_HTML = "...";
 
         diff.m_emitChangeNextPreviousHyperlinks = false;
 
-        diff.m_insertionEndHtml = "^";
-        diff.m_insertionStartHtml = "^";
+        diff.INSERTION_END_HTML = "^";
+        diff.INSERTION_START_HTML = "^";
 
-        diff.m_lineBreakHtml = "";
-        diff.m_alternatingSpaceHtml = "_";
+        diff.LINE_BREAK_HTML = "";
+        diff.ALTERNATING_SPACE_HTML = "_";
     }
 
 


[jspwiki] 02/10: JSPWIKI-120: move getVariable(..) method from WikiEngine to VariableManager

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 56087e3d287c475fc36eb8ccd3e5c232ded5d8f0
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 16:43:03 2019 +0100

    JSPWIKI-120: move getVariable(..) method from WikiEngine to VariableManager
---
 .../main/java/org/apache/wiki/VariableManager.java | 79 +++++++++------------
 .../src/main/java/org/apache/wiki/WikiContext.java |  2 +-
 .../src/main/java/org/apache/wiki/WikiEngine.java  | 31 ++------
 .../main/java/org/apache/wiki/plugin/IfPlugin.java | 38 +++++-----
 .../main/java/org/apache/wiki/rss/RSS20Feed.java   | 35 +++++----
 .../java/org/apache/wiki/rss/RSSGenerator.java     | 82 ++++++++++------------
 .../src/main/webapp/templates/210/DiffTab.jsp      |  2 +-
 .../src/main/webapp/templates/default/DiffTab.jsp  |  2 +-
 8 files changed, 111 insertions(+), 160 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java b/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
index 86e166d..71a6ba5 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
@@ -93,59 +93,40 @@ public class VariableManager
     }
 
     /**
-     *  This method does in-place expansion of any variables.  However,
-     *  the expansion is not done twice, that is, a variable containing text $variable
-     *  will not be expanded.
+     *  This method does in-place expansion of any variables.  However, the expansion is not done twice, that is,
+     *  a variable containing text $variable will not be expanded.
      *  <P>
-     *  The variables should be in the same format ({$variablename} as in the web
-     *  pages.
+     *  The variables should be in the same format ({$variablename} as in the web pages.
      *
      *  @param context The WikiContext of the current page.
      *  @param source  The source string.
      *  @return The source string with variables expanded.
      */
     // FIXME: somewhat slow.
-    public String expandVariables( WikiContext context, String source ) {
-    	StringBuilder result = new StringBuilder();
-
-        for( int i = 0; i < source.length(); i++ )
-        {
-            if( source.charAt(i) == '{' )
-            {
-                if( i < source.length()-2 && source.charAt(i+1) == '$' )
-                {
-                    int end = source.indexOf( '}', i );
-
-                    if( end != -1 )
-                    {
-                        String varname = source.substring( i+2, end );
+    public String expandVariables( final WikiContext context, final String source ) {
+        final StringBuilder result = new StringBuilder();
+        for( int i = 0; i < source.length(); i++ ) {
+            if( source.charAt(i) == '{' ) {
+                if( i < source.length()-2 && source.charAt(i+1) == '$' ) {
+                    final int end = source.indexOf( '}', i );
+
+                    if( end != -1 ) {
+                        final String varname = source.substring( i+2, end );
                         String value;
 
-                        try
-                        {
+                        try {
                             value = getValue( context, varname );
-                        }
-                        catch( NoSuchVariableException e )
-                        {
-                            value = e.getMessage();
-                        }
-                        catch( IllegalArgumentException e )
-                        {
+                        } catch( final NoSuchVariableException | IllegalArgumentException e ) {
                             value = e.getMessage();
                         }
 
                         result.append( value );
                         i = end;
-                        continue;
                     }
-                }
-                else
-                {
+                } else {
                     result.append( '{' );
                 }
-            }
-            else
-            {
+            } else {
                 result.append( source.charAt(i) );
             }
         }
@@ -154,28 +135,36 @@ public class VariableManager
     }
 
     /**
-     *  Returns the value of a named variable.  See {@link #getValue(WikiContext, String)}.
-     *  The only difference is that this method does not throw an exception, but it
-     *  returns the given default value instead.
+     *  Returns the value of a named variable.  See {@link #getValue(WikiContext, String)}. The only difference is that
+     *  this method does not throw an exception, but it returns the given default value instead.
      *
      *  @param context WikiContext
      *  @param varName The name of the variable
      *  @param defValue A default value.
      *  @return The variable value, or if not found, the default value.
      */
-    public String getValue( WikiContext context, String varName, String defValue )
-    {
-        try
-        {
+    public String getValue( final WikiContext context, final String varName, final String defValue ) {
+        try {
             return getValue( context, varName );
-        }
-        catch( NoSuchVariableException e )
-        {
+        } catch( final NoSuchVariableException e ) {
             return defValue;
         }
     }
 
     /**
+     *  Shortcut to getValue(). However, this method does not throw a NoSuchVariableException, but returns null
+     *  in case the variable does not exist.
+     *
+     *  @param context WikiContext to look the variable in
+     *  @param name Name of the variable to look for
+     *  @return Variable value, or null, if there is no such variable.
+     *  @since 2.2 on WikiEngine, moved to VariableManager on 2.11.0
+     */
+    public String getVariable( final WikiContext context, final String name ) {
+        return getValue( context, name, null );
+    }
+
+    /**
      *  Returns a value of the named variable.  The resolving order is
      *  <ol>
      *    <li>Known "constant" name, such as "pagename", etc.  This is so
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
index 41a1fef..7a3029a 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java
@@ -615,7 +615,7 @@ public class WikiContext implements Cloneable, Command {
      *  @return An URL to the given context and page.
      */
     public String getURL( final String context, final String page, final String params ) {
-        final boolean absolute = "absolute".equals(m_engine.getVariable( this, WikiEngine.PROP_REFSTYLE ));
+        final boolean absolute = "absolute".equals(m_engine.getVariableManager().getVariable( this, WikiEngine.PROP_REFSTYLE ));
 
         // FIXME: is rather slow
         return m_engine.getURL( context, page, params, absolute );
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 3258915..5be6d67 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -1650,21 +1650,18 @@ public class WikiEngine  {
      *
      *  @return Set of WikiPage objects.
      */
-
-    // FIXME: Should really get a Date object and do proper comparisons. This is terribly wasteful.
-    public Set< WikiPage > getRecentChanges()
-    {
+    public Set< WikiPage > getRecentChanges() {
         try {
-            Collection<WikiPage>   pages = m_pageManager.getAllPages();
-            Collection<Attachment>  atts = m_attachmentManager.getAllAttachments();
+            final Collection< WikiPage >   pages = m_pageManager.getAllPages();
+            final Collection< Attachment >  atts = m_attachmentManager.getAllAttachments();
 
-            TreeSet<WikiPage> sortedPages = new TreeSet<>( new PageTimeComparator() );
+            final TreeSet< WikiPage > sortedPages = new TreeSet<>( new PageTimeComparator() );
 
             sortedPages.addAll( pages );
             sortedPages.addAll( atts );
 
             return sortedPages;
-        } catch( ProviderException e ) {
+        } catch( final ProviderException e ) {
             log.error( "Unable to fetch all pages: ",e);
             return null;
         }
@@ -1815,24 +1812,6 @@ public class WikiEngine  {
     }
 
     /**
-     *  Shortcut to getVariableManager().getValue(). However, this method does not
-     *  throw a NoSuchVariableException, but returns null in case the variable does
-     *  not exist.
-     *
-     *  @param context WikiContext to look the variable in
-     *  @param name Name of the variable to look for
-     *  @return Variable value, or null, if there is no such variable.
-     *  @since 2.2
-     */
-    public String getVariable( WikiContext context, String name ) {
-        try {
-            return m_variableManager.getValue( context, name );
-        } catch( NoSuchVariableException e ) {
-            return null;
-        }
-    }
-
-    /**
      *  Returns the current PageManager which is responsible for storing
      *  and managing WikiPages.
      *
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/IfPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/IfPlugin.java
index 71490fb..2275b94 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/IfPlugin.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/IfPlugin.java
@@ -139,8 +139,7 @@ public class IfPlugin implements WikiPlugin
     /**
      *  {@inheritDoc}
      */
-    public String execute(WikiContext context, Map<String, String> params) throws PluginException
-    {
+    public String execute( final WikiContext context, final Map< String, String > params ) throws PluginException {
         return ifInclude( context,params )
                 ? context.getEngine().textToHTML( context, params.get( DefaultPluginManager.PARAM_BODY ) )
                 : "" ;
@@ -158,34 +157,29 @@ public class IfPlugin implements WikiPlugin
      * @throws PluginException If something goes wrong
      * @return True, if the condition holds.
      */
-    public static boolean ifInclude( WikiContext context, Map<String, String> params ) throws PluginException
-    {
-        boolean include = false;
-
-        String group    = params.get( PARAM_GROUP );
-        String user     = params.get( PARAM_USER );
-        String ip       = params.get( PARAM_IP );
-        String page     = params.get( PARAM_PAGE );
-        String contains = params.get( PARAM_CONTAINS );
-        String var      = params.get( PARAM_VAR );
-        String is       = params.get( PARAM_IS );
-        String exists   = params.get( PARAM_EXISTS );
-
-        include |= checkGroup(context, group);
+    public static boolean ifInclude( final WikiContext context, final Map< String, String > params ) throws PluginException {
+        final String group    = params.get( PARAM_GROUP );
+        final String user     = params.get( PARAM_USER );
+        final String ip       = params.get( PARAM_IP );
+        final String page     = params.get( PARAM_PAGE );
+        final String contains = params.get( PARAM_CONTAINS );
+        final String var      = params.get( PARAM_VAR );
+        final String is       = params.get( PARAM_IS );
+        final String exists   = params.get( PARAM_EXISTS );
+
+        boolean include = checkGroup( context, group );
         include |= checkUser(context, user);
         include |= checkIP(context, ip);
 
-        if( page != null )
-        {
-            String content = context.getEngine().getPureText(page, WikiProvider.LATEST_VERSION).trim();
+        if( page != null ) {
+            final String content = context.getEngine().getPureText(page, WikiProvider.LATEST_VERSION).trim();
             include |= checkContains(content,contains);
             include |= checkIs(content,is);
             include |= checkExists(context,page,exists);
         }
 
-        if( var != null )
-        {
-            String content = context.getEngine().getVariable(context, var);
+        if( var != null ) {
+            final String content = context.getEngine().getVariableManager().getVariable(context, var);
             include |= checkContains(content,contains);
             include |= checkIs(content,is);
             include |= checkVarExists(content,exists);
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/rss/RSS20Feed.java b/jspwiki-main/src/main/java/org/apache/wiki/rss/RSS20Feed.java
index b3b09f5..ba69b7b 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/rss/RSS20Feed.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/rss/RSS20Feed.java
@@ -18,22 +18,24 @@
  */
 package org.apache.wiki.rss;
 
-import java.io.IOException;
-import java.io.StringWriter;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-import javax.servlet.ServletContext;
-
-import org.jdom2.Element;
-import org.jdom2.output.Format;
-import org.jdom2.output.XMLOutputter;
 import org.apache.wiki.Release;
 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.attachment.Attachment;
+import org.jdom2.Element;
+import org.jdom2.output.Format;
+import org.jdom2.output.XMLOutputter;
+
+import javax.servlet.ServletContext;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  *  Represents an RSS 2.0 feed (with enclosures).  This feed provides no
@@ -150,10 +152,10 @@ public class RSS20Feed extends Feed
         channel.addContent( new Element("language").setText(getChannelLanguage()));
         channel.addContent( new Element("generator").setText("JSPWiki "+Release.VERSTR));
 
-        String mail = engine.getVariable(m_wikiContext,RSSGenerator.PROP_RSS_AUTHOREMAIL);
+        String mail = engine.getVariableManager().getVariable(m_wikiContext,RSSGenerator.PROP_RSS_AUTHOREMAIL);
         if( mail != null )
         {
-            String editor = engine.getVariable( m_wikiContext,RSSGenerator.PROP_RSS_AUTHOR );
+            String editor = engine.getVariableManager().getVariable( m_wikiContext,RSSGenerator.PROP_RSS_AUTHOR );
 
             if( editor != null )
                 mail = mail + " ("+editor+")";
@@ -174,15 +176,12 @@ public class RSS20Feed extends Feed
 
         output.setFormat( Format.getPrettyFormat() );
 
-        try
-        {
-            StringWriter res = new StringWriter();
+        try {
+            final StringWriter res = new StringWriter();
             output.output( root, res );
 
             return res.toString();
-        }
-        catch( IOException e )
-        {
+        } catch( final IOException e ) {
             return null;
         }
     }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java b/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
index 383bafa..058d9e6 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/rss/RSSGenerator.java
@@ -421,14 +421,14 @@ public class RSSGenerator {
     {
         feed.setChannelTitle( m_engine.getApplicationName()+": "+wikiContext.getPage().getName() );
         feed.setFeedURL( wikiContext.getViewURL( wikiContext.getPage().getName() ) );
-        String language = m_engine.getVariable( wikiContext, PROP_CHANNEL_LANGUAGE );
+        String language = m_engine.getVariableManager().getVariable( wikiContext, PROP_CHANNEL_LANGUAGE );
 
         if( language != null )
             feed.setChannelLanguage( language );
         else
             feed.setChannelLanguage( m_channelLanguage );
 
-        String channelDescription = m_engine.getVariable( wikiContext, PROP_CHANNEL_DESCRIPTION );
+        String channelDescription = m_engine.getVariableManager().getVariable( wikiContext, PROP_CHANNEL_DESCRIPTION );
 
         if( channelDescription != null )
         {
@@ -490,39 +490,39 @@ public class RSSGenerator {
      *  @return A String of valid RSS or Atom.
      *  @throws ProviderException If reading of pages was not possible.
      */
-    protected String generateBlogRSS( WikiContext wikiContext, List< WikiPage > changed, Feed feed )
-        throws ProviderException
-    {
-        if( log.isDebugEnabled() ) log.debug("Generating RSS for blog, size="+changed.size());
+    protected String generateBlogRSS( WikiContext wikiContext, List< WikiPage > changed, Feed feed ) {
+        if( log.isDebugEnabled() ) {
+            log.debug( "Generating RSS for blog, size=" + changed.size() );
+        }
 
-        String ctitle = m_engine.getVariable( wikiContext, PROP_CHANNEL_TITLE );
+        String ctitle = m_engine.getVariableManager().getVariable( wikiContext, PROP_CHANNEL_TITLE );
 
-        if( ctitle != null )
+        if( ctitle != null ) {
             feed.setChannelTitle( ctitle );
-        else
-            feed.setChannelTitle( m_engine.getApplicationName()+":"+wikiContext.getPage().getName() );
+        } else {
+            feed.setChannelTitle( m_engine.getApplicationName() + ":" + wikiContext.getPage().getName() );
+        }
 
         feed.setFeedURL( wikiContext.getViewURL( wikiContext.getPage().getName() ) );
 
-        String language = m_engine.getVariable( wikiContext, PROP_CHANNEL_LANGUAGE );
+        String language = m_engine.getVariableManager().getVariable( wikiContext, PROP_CHANNEL_LANGUAGE );
 
-        if( language != null )
+        if( language != null ) {
             feed.setChannelLanguage( language );
-        else
+        } else {
             feed.setChannelLanguage( m_channelLanguage );
+        }
 
-        String channelDescription = m_engine.getVariable( wikiContext, PROP_CHANNEL_DESCRIPTION );
+        String channelDescription = m_engine.getVariableManager().getVariable( wikiContext, PROP_CHANNEL_DESCRIPTION );
 
-        if( channelDescription != null )
-        {
+        if( channelDescription != null ) {
             feed.setChannelDescription( channelDescription );
         }
 
         Collections.sort( changed, new PageTimeComparator() );
 
         int items = 0;
-        for( Iterator< WikiPage > i = changed.iterator(); i.hasNext() && items < 15; items++ )
-        {
+        for( Iterator< WikiPage > i = changed.iterator(); i.hasNext() && items < 15; items++ ) {
             WikiPage page = i.next();
 
             Entry e = new Entry();
@@ -531,19 +531,10 @@ public class RSSGenerator {
 
             String url;
 
-            if( page instanceof Attachment )
-            {
-                url = m_engine.getURL( WikiContext.ATTACH,
-                                       page.getName(),
-                                       null,
-                                       true );
-            }
-            else
-            {
-                url = m_engine.getURL( WikiContext.VIEW,
-                                       page.getName(),
-                                       null,
-                                       true );
+            if( page instanceof Attachment ) {
+                url = m_engine.getURL( WikiContext.ATTACH, page.getName(),null,true );
+            } else {
+                url = m_engine.getURL( WikiContext.VIEW, page.getName(),null, true );
             }
 
             e.setURL( url );
@@ -557,15 +548,18 @@ public class RSSGenerator {
             String title = "";
             int firstLine = pageText.indexOf('\n');
 
-            if( firstLine > 0 )
-            {
+            if( firstLine > 0 ) {
                 title = pageText.substring( 0, firstLine ).trim();
             }
 
-            if( title.length() == 0 ) title = page.getName();
+            if( title.length() == 0 ) {
+                title = page.getName();
+            }
 
             // Remove wiki formatting
-            while( title.startsWith("!") ) title = title.substring(1);
+            while( title.startsWith("!") ) {
+                title = title.substring(1);
+            }
 
             e.setTitle( title );
 
@@ -573,28 +567,24 @@ public class RSSGenerator {
             //  Description
             //
 
-            if( firstLine > 0 )
-            {
+            if( firstLine > 0 ) {
                 int maxlen = pageText.length();
                 if( maxlen > MAX_CHARACTERS ) maxlen = MAX_CHARACTERS;
 
-                if( maxlen > 0 )
-                {
+                if( maxlen > 0 ) {
                     pageText = m_engine.textToHTML( wikiContext,
                                                     pageText.substring( firstLine+1,
                                                                         maxlen ).trim() );
 
-                    if( maxlen == MAX_CHARACTERS ) pageText += "...";
+                    if( maxlen == MAX_CHARACTERS ) {
+                        pageText += "...";
+                    }
 
                     e.setContent( pageText );
-                }
-                else
-                {
+                } else {
                     e.setContent( title );
                 }
-            }
-            else
-            {
+            } else {
                 e.setContent( title );
             }
 
diff --git a/jspwiki-war/src/main/webapp/templates/210/DiffTab.jsp b/jspwiki-war/src/main/webapp/templates/210/DiffTab.jsp
index 17d7f56..f55b68f 100644
--- a/jspwiki-war/src/main/webapp/templates/210/DiffTab.jsp
+++ b/jspwiki-war/src/main/webapp/templates/210/DiffTab.jsp
@@ -31,7 +31,7 @@
   WikiContext c = WikiContext.findContext( pageContext );
   List history = c.getEngine().getVersionHistory(c.getPage().getName());
   pageContext.setAttribute( "history", history );
-  pageContext.setAttribute( "diffprovider", c.getEngine().getVariable(c,"jspwiki.diffProvider"));
+  pageContext.setAttribute( "diffprovider", c.getEngine().getVariableManager().getVariable(c,"jspwiki.diffProvider"));
  %>
 
 <wiki:PageExists>
diff --git a/jspwiki-war/src/main/webapp/templates/default/DiffTab.jsp b/jspwiki-war/src/main/webapp/templates/default/DiffTab.jsp
index f7986dc..1f7972b 100644
--- a/jspwiki-war/src/main/webapp/templates/default/DiffTab.jsp
+++ b/jspwiki-war/src/main/webapp/templates/default/DiffTab.jsp
@@ -30,7 +30,7 @@
   WikiContext c = WikiContext.findContext( pageContext );
 %>
 <c:set var="history" value="<%= c.getEngine().getVersionHistory(c.getPage().getName()) %>" />
-<c:set var="diffprovider" value='<%= c.getEngine().getVariable(c,"jspwiki.diffProvider") %>' />
+<c:set var="diffprovider" value='<%= c.getEngine().getVariableManager().getVariable(c,"jspwiki.diffProvider") %>' />
 <wiki:PageExists>
 <form action="<wiki:Link jsp='Diff.jsp' format='url' />"
        class="diffbody form-inline"


[jspwiki] 03/10: more formatting + intellij fixes on VariableManager

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 42379927daa983c346ddab0c424999e404ea6e7e
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 17:25:07 2019 +0100

    more formatting + intellij fixes on VariableManager
---
 .../main/java/org/apache/wiki/VariableManager.java | 228 +++++++++------------
 1 file changed, 99 insertions(+), 129 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java b/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
index 71a6ba5..0ce2d02 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
@@ -37,13 +37,12 @@ import java.util.Properties;
 import java.util.ResourceBundle;
 
 /**
- *  Manages variables.  Variables are case-insensitive.  A list of all
- *  available variables is on a Wiki page called "WikiVariables".
+ *  Manages variables.  Variables are case-insensitive.  A list of all available variables is on a Wiki page called "WikiVariables".
  *
  *  @since 1.9.20.
  */
-public class VariableManager
-{
+public class VariableManager {
+
     private static Logger log = Logger.getLogger( VariableManager.class );
 
     // FIXME: These are probably obsolete.
@@ -51,10 +50,8 @@ public class VariableManager
     public static final String VAR_MSG   = "msg";
 
     /**
-     *  Contains a list of those properties that shall never be shown.
-     *  Put names here in lower case.
+     *  Contains a list of those properties that shall never be shown. Put names here in lower case.
      */
-
     static final String[] THE_BIG_NO_NO_LIST = {
         "jspwiki.auth.masterpassword"
     };
@@ -63,7 +60,7 @@ public class VariableManager
      *  Creates a VariableManager object using the property list given.
      *  @param props The properties.
      */
-    public VariableManager( Properties props )
+    public VariableManager( final Properties props )
     {
     }
 
@@ -76,18 +73,17 @@ public class VariableManager
      *  @param  context The WikiContext
      *  @param  link    The link text containing the variable name.
      *  @return The variable value.
-     *  @throws IllegalArgumentException If the format is not valid (does not
-     *          start with "{$", is zero length, etc.)
+     *  @throws IllegalArgumentException If the format is not valid (does not start with "{$", is zero length, etc.)
      *  @throws NoSuchVariableException If a variable is not known.
      */
-    public String parseAndGetValue( WikiContext context, String link ) throws IllegalArgumentException, NoSuchVariableException {
-        if( !link.startsWith("{$") ) {
+    public String parseAndGetValue( final WikiContext context, final String link ) throws IllegalArgumentException, NoSuchVariableException {
+        if( !link.startsWith( "{$" ) ) {
             throw new IllegalArgumentException( "Link does not start with {$" );
         }
-        if( !link.endsWith("}") ) {
+        if( !link.endsWith( "}" ) ) {
             throw new IllegalArgumentException( "Link does not end with }" );
         }
-        String varName = link.substring(2,link.length()-1);
+        final String varName = link.substring( 2, link.length() - 1 );
 
         return getValue( context, varName.trim() );
     }
@@ -188,7 +184,7 @@ public class VariableManager
      *  @throws IllegalArgumentException If the name is somehow broken.
      *  @throws NoSuchVariableException If a variable is not known.
      */
-    public String getValue( WikiContext context, String varName ) throws IllegalArgumentException, NoSuchVariableException {
+    public String getValue( final WikiContext context, final String varName ) throws IllegalArgumentException, NoSuchVariableException {
         if( varName == null ) {
             throw new IllegalArgumentException( "Null variable name." );
         }
@@ -196,15 +192,15 @@ public class VariableManager
             throw new IllegalArgumentException( "Zero length variable name." );
         }
         // Faster than doing equalsIgnoreCase()
-        String name = varName.toLowerCase();
+        final String name = varName.toLowerCase();
 
-        for( int i = 0; i < THE_BIG_NO_NO_LIST.length; i++ ) {
-            if( name.equals(THE_BIG_NO_NO_LIST[i]) )
+        for( final String value : THE_BIG_NO_NO_LIST ) {
+            if( name.equals( value ) ) {
                 return ""; // FIXME: Should this be something different?
+            }
         }
 
-        try
-        {
+        try {
             //
             //  Using reflection to get system variables adding a new system variable
             //  now only involves creating a new method in the SystemVariables class
@@ -214,86 +210,75 @@ public class VariableManager
             //      return "Hello World";
             //    }
             //
-            SystemVariables sysvars = new SystemVariables(context);
-            String methodName = "get"+Character.toUpperCase(name.charAt(0))+name.substring(1);
-            Method method = sysvars.getClass().getMethod(methodName);
-            return (String)method.invoke(sysvars);
-        }
-        catch( NoSuchMethodException e1 )
-        {
+            final SystemVariables sysvars = new SystemVariables( context );
+            final String methodName = "get" + Character.toUpperCase( name.charAt( 0 ) ) + name.substring( 1 );
+            final Method method = sysvars.getClass().getMethod( methodName );
+            return ( String )method.invoke( sysvars );
+        } catch( final NoSuchMethodException e1 ) {
             //
             //  It is not a system var. Time to handle the other cases.
             //
-            //  Check if such a context variable exists,
-            //  returning its string representation.
+            //  Check if such a context variable exists, returning its string representation.
             //
-            if( (context.getVariable( varName )) != null )
-            {
+            if( ( context.getVariable( varName ) ) != null ) {
                 return context.getVariable( varName ).toString();
             }
 
             //
-            //  Well, I guess it wasn't a final straw.  We also allow
-            //  variables from the session and the request (in this order).
+            //  Well, I guess it wasn't a final straw.  We also allow variables from the session and the request (in this order).
             //
+            final HttpServletRequest req = context.getHttpRequest();
+            if( req != null && req.getSession() != null ) {
+                final HttpSession session = req.getSession();
 
-            HttpServletRequest req = context.getHttpRequest();
-            if( req != null && req.getSession() != null )
-            {
-                HttpSession session = req.getSession();
+                try {
+                    String s = ( String )session.getAttribute( varName );
 
-                try
-                {
-                    String s;
-
-                    if( (s = (String)session.getAttribute( varName )) != null )
+                    if( s != null ) {
                         return s;
+                    }
 
-                    if( (s = context.getHttpParameter( varName )) != null )
+                    s = context.getHttpParameter( varName );
+                    if( s != null ) {
                         return s;
+                    }
+                } catch( final ClassCastException e ) {
+                    log.debug( "Not a String: " + varName );
                 }
-                catch( ClassCastException e ) {}
             }
 
             //
             // And the final straw: see if the current page has named metadata.
             //
-
-            WikiPage pg = context.getPage();
-            if( pg != null )
-            {
-                Object metadata = pg.getAttribute( varName );
-                if( metadata != null )
+            final WikiPage pg = context.getPage();
+            if( pg != null ) {
+                final Object metadata = pg.getAttribute( varName );
+                if( metadata != null ) {
                     return metadata.toString();
+                }
             }
 
             //
-            // And the final straw part 2: see if the "real" current page has
-            // named metadata. This allows a parent page to control a inserted
-            // page through defining variables
+            // And the final straw part 2: see if the "real" current page has named metadata. This allows
+            // a parent page to control a inserted page through defining variables
             //
-            WikiPage rpg = context.getRealPage();
-            if( rpg != null )
-            {
-                Object metadata = rpg.getAttribute( varName );
-                if( metadata != null )
+            final WikiPage rpg = context.getRealPage();
+            if( rpg != null ) {
+                final Object metadata = rpg.getAttribute( varName );
+                if( metadata != null ) {
                     return metadata.toString();
+                }
             }
 
             //
-            // Next-to-final straw: attempt to fetch using property name
-            // We don't allow fetching any other properties than those starting
-            // with "jspwiki.".  I know my own code, but I can't vouch for bugs
+            // Next-to-final straw: attempt to fetch using property name. We don't allow fetching any other
+            // properties than those starting with "jspwiki.".  I know my own code, but I can't vouch for bugs
             // in other people's code... :-)
             //
-
-            if( varName.startsWith("jspwiki.") )
-            {
-                Properties props = context.getEngine().getWikiProperties();
-
-                String s = props.getProperty( varName );
-                if( s != null )
-                {
+            if( varName.startsWith("jspwiki.") ) {
+                final Properties props = context.getEngine().getWikiProperties();
+                final String s = props.getProperty( varName );
+                if( s != null ) {
                     return s;
                 }
             }
@@ -301,15 +286,13 @@ public class VariableManager
             //
             //  Final defaults for some known quantities.
             //
-
-            if( varName.equals( VAR_ERROR ) || varName.equals( VAR_MSG ) )
+            if( varName.equals( VAR_ERROR ) || varName.equals( VAR_MSG ) ) {
                 return "";
+            }
 
-            throw new NoSuchVariableException( "No variable "+varName+" defined." );
-        }
-        catch( Exception e )
-        {
-            log.info("Interesting exception: cannot fetch variable value",e);
+            throw new NoSuchVariableException( "No variable " + varName + " defined." );
+        } catch( final Exception e ) {
+            log.info("Interesting exception: cannot fetch variable value", e );
         }
         return "";
     }
@@ -332,9 +315,9 @@ public class VariableManager
     @SuppressWarnings( "unused" )
     private static class SystemVariables
     {
-        private WikiContext m_context;
+        private final WikiContext m_context;
 
-        public SystemVariables(WikiContext context)
+        public SystemVariables( final WikiContext context )
         {
             m_context=context;
         }
@@ -382,43 +365,37 @@ public class VariableManager
             return (p != null) ? p.getProviderInfo() : "-";
         }
 
-        public String getInterwikilinks()
-        {
-        	StringBuilder res = new StringBuilder();
+        public String getInterwikilinks() {
+            final StringBuilder res = new StringBuilder();
 
-            for( String link : m_context.getEngine().getAllInterWikiLinks() )
-            {
+            for( final String link : m_context.getEngine().getAllInterWikiLinks() ) {
                 if( res.length() > 0 ) {
-                    res.append(", ");
+                    res.append( ", " );
                 }
                 res.append( link );
                 res.append( " --> " );
-                res.append( m_context.getEngine().getInterWikiURL(link) );
+                res.append( m_context.getEngine().getInterWikiURL( link ) );
             }
             return res.toString();
         }
 
-        public String getInlinedimages()
-        {
-        	StringBuilder res = new StringBuilder();
-
-            for( String ptrn : m_context.getEngine().getAllInlinedImagePatterns() )
-            {
+        public String getInlinedimages() {
+            final StringBuilder res = new StringBuilder();
+            for( final String ptrn : m_context.getEngine().getAllInlinedImagePatterns() ) {
                 if( res.length() > 0 ) {
-                    res.append(", ");
+                    res.append( ", " );
                 }
 
-                res.append(ptrn);
+                res.append( ptrn );
             }
 
             return res.toString();
         }
 
-        public String getPluginpath()
-        {
-            String s = m_context.getEngine().getPluginManager().getPluginSearchPath();
+        public String getPluginpath() {
+            final String s = m_context.getEngine().getPluginManager().getPluginSearchPath();
 
-            return (s == null) ? "-" : s;
+            return ( s == null ) ? "-" : s;
         }
 
         public String getBaseurl()
@@ -426,30 +403,26 @@ public class VariableManager
             return m_context.getEngine().getBaseURL();
         }
 
-        public String getUptime()
-        {
-            Date now = new Date();
-            long secondsRunning = (now.getTime() - m_context.getEngine().getStartTime().getTime()) / 1000L;
+        public String getUptime() {
+            final Date now = new Date();
+            long secondsRunning = ( now.getTime() - m_context.getEngine().getStartTime().getTime() ) / 1_000L;
 
-            long seconds = secondsRunning % 60;
-            long minutes = (secondsRunning /= 60) % 60;
-            long hours = (secondsRunning /= 60) % 24;
-            long days = secondsRunning /= 24;
+            final long seconds = secondsRunning % 60;
+            final long minutes = (secondsRunning /= 60) % 60;
+            final long hours = (secondsRunning /= 60) % 24;
+            final long days = secondsRunning /= 24;
 
             return days + "d, " + hours + "h " + minutes + "m " + seconds + "s";
         }
 
-        public String getLoginstatus()
-        {
-            WikiSession session = m_context.getWikiSession();
-            return Preferences.getBundle( m_context, InternationalizationManager.CORE_BUNDLE ).getString( "varmgr." + session.getStatus());
+        public String getLoginstatus() {
+            final WikiSession session = m_context.getWikiSession();
+            return Preferences.getBundle( m_context, InternationalizationManager.CORE_BUNDLE ).getString( "varmgr." + session.getStatus() );
         }
 
-        public String getUsername()
-        {
-            Principal wup = m_context.getCurrentUser();
-
-            ResourceBundle rb = Preferences.getBundle( m_context, InternationalizationManager.CORE_BUNDLE );
+        public String getUsername() {
+            final Principal wup = m_context.getCurrentUser();
+            final ResourceBundle rb = Preferences.getBundle( m_context, InternationalizationManager.CORE_BUNDLE );
             return wup != null ? wup.getName() : rb.getString( "varmgr.not.logged.in" );
         }
 
@@ -458,24 +431,21 @@ public class VariableManager
             return m_context.getRequestContext();
         }
 
-        public String getPagefilters()
-        {
-            FilterManager fm = m_context.getEngine().getFilterManager();
-            List<PageFilter> filters = fm.getFilterList();
-            StringBuilder sb = new StringBuilder();
-
-            for (PageFilter pf : filters )
-            {
-                String f = pf.getClass().getName();
-
-                if( pf instanceof InternalModule )
+        public String getPagefilters() {
+            final FilterManager fm = m_context.getEngine().getFilterManager();
+            final List< PageFilter > filters = fm.getFilterList();
+            final StringBuilder sb = new StringBuilder();
+            for( final PageFilter pf : filters ) {
+                final String f = pf.getClass().getName();
+                if( pf instanceof InternalModule ) {
                     continue;
+                }
 
-                if( sb.length() > 0 )
-                    sb.append(", ");
-                sb.append(f);
+                if( sb.length() > 0 ) {
+                    sb.append( ", " );
+                }
+                sb.append( f );
             }
-
             return sb.toString();
         }
     }


[jspwiki] 05/10: intellij format + fixes

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 e0f1975e7713ce3d3f221b8a2904ceab4fefe4dc
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 18:51:14 2019 +0100

    intellij format + fixes
---
 .../apache/wiki/diff/ContextualDiffProvider.java   | 311 +++++++++------------
 .../java/org/apache/wiki/diff/DiffProvider.java    |  22 +-
 .../org/apache/wiki/diff/DifferenceManager.java    |  55 ++--
 .../org/apache/wiki/diff/ExternalDiffProvider.java |  80 +++---
 .../apache/wiki/diff/TraditionalDiffProvider.java  | 135 ++++-----
 5 files changed, 250 insertions(+), 353 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
index c568b0f..4b4ee3b 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/ContextualDiffProvider.java
@@ -19,12 +19,6 @@
 
 package org.apache.wiki.diff;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
 import org.apache.log4j.Logger;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
@@ -41,13 +35,17 @@ import org.suigeneris.jrcs.diff.delta.DeleteDelta;
 import org.suigeneris.jrcs.diff.delta.Delta;
 import org.suigeneris.jrcs.diff.myers.MyersDiff;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
 
 /**
- * A seriously better diff provider, which highlights changes word-by-word using
- * CSS.
+ * A seriously better diff provider, which highlights changes word-by-word using CSS.
  *
  * Suggested by John Volkar.
- *
  */
 public class ContextualDiffProvider implements DiffProvider {
 
@@ -65,27 +63,27 @@ public class ContextualDiffProvider implements DiffProvider {
     public boolean m_emitChangeNextPreviousHyperlinks = true;
 
     //Don't use spans here the deletion and insertions are nested in this...
-    public String m_changeStartHtml    = ""; //This could be a image '>' for a start marker
-    public String m_changeEndHtml      = ""; //and an image for an end '<' marker
-    public String m_diffStart          = "<div class=\"diff-wikitext\">";
-    public String m_diffEnd            = "</div>";
+    public static final String CHANGE_START_HTML = ""; //This could be a image '>' for a start marker
+    public static final String CHANGE_END_HTML = ""; //and an image for an end '<' marker
+    public static final String DIFF_START = "<div class=\"diff-wikitext\">";
+    public static final String DIFF_END = "</div>";
 
     // Unfortunately we need to do dumb HTML here for RSS feeds.
 
-    public String m_insertionStartHtml = "<font color=\"#8000FF\"><span class=\"diff-insertion\">";
-    public String m_insertionEndHtml   = "</span></font>";
-    public String m_deletionStartHtml  = "<strike><font color=\"red\"><span class=\"diff-deletion\">";
-    public String m_deletionEndHtml    = "</span></font></strike>";
-    private String m_anchorPreIndex    = "<a name=\"change-";
-    private String m_anchorPostIndex   = "\" />";
-    private String m_backPreIndex      = "<a class=\"diff-nextprev\" title=\"Go to previous change\" href=\"#change-";
-    private String m_backPostIndex     = "\">&lt;&lt;</a>";
-    private String m_forwardPreIndex   = "<a class=\"diff-nextprev\" title=\"Go to next change\" href=\"#change-";
-    private String m_forwardPostIndex  = "\">&gt;&gt;</a>";
-    public String m_elidedHeadIndicatorHtml = "<br/><br/><b>...</b>";
-    public String m_elidedTailIndicatorHtml = "<b>...</b><br/><br/>";
-    public String m_lineBreakHtml = "<br />";
-    public String m_alternatingSpaceHtml = "&nbsp;";
+    public static final String INSERTION_START_HTML = "<font color=\"#8000FF\"><span class=\"diff-insertion\">";
+    public static final String INSERTION_END_HTML = "</span></font>";
+    public static final String DELETION_START_HTML = "<strike><font color=\"red\"><span class=\"diff-deletion\">";
+    public static final String DELETION_END_HTML = "</span></font></strike>";
+    private static final String ANCHOR_PRE_INDEX = "<a name=\"change-";
+    private static final String ANCHOR_POST_INDEX = "\" />";
+    private static final String BACK_PRE_INDEX = "<a class=\"diff-nextprev\" title=\"Go to previous change\" href=\"#change-";
+    private static final String BACK_POST_INDEX = "\">&lt;&lt;</a>";
+    private static final String FORWARD_PRE_INDEX = "<a class=\"diff-nextprev\" title=\"Go to next change\" href=\"#change-";
+    private static final String FORWARD_POST_INDEX = "\">&gt;&gt;</a>";
+    public static final String ELIDED_HEAD_INDICATOR_HTML = "<br/><br/><b>...</b>";
+    public static final String ELIDED_TAIL_INDICATOR_HTML = "<b>...</b><br/><br/>";
+    public static final String LINE_BREAK_HTML = "<br />";
+    public static final String ALTERNATING_SPACE_HTML = "&nbsp;";
 
     // This one, I will make property file based...
     private static final int LIMIT_MAX_VALUE = (Integer.MAX_VALUE /2) - 1;
@@ -114,19 +112,13 @@ public class ContextualDiffProvider implements DiffProvider {
      *      
      * {@inheritDoc}
      */
-    public void initialize(WikiEngine engine, Properties properties) throws NoRequiredPropertyException, IOException
-    {
-        String configuredLimit = properties.getProperty(PROP_UNCHANGED_CONTEXT_LIMIT, 
-                                                        Integer.toString(LIMIT_MAX_VALUE));
+    public void initialize( final WikiEngine engine, final Properties properties) throws NoRequiredPropertyException, IOException {
+        final String configuredLimit = properties.getProperty( PROP_UNCHANGED_CONTEXT_LIMIT, Integer.toString( LIMIT_MAX_VALUE ) );
         int limit = LIMIT_MAX_VALUE;
-        try
-        {
-            limit = Integer.parseInt(configuredLimit);
-        }
-        catch (NumberFormatException e)
-        {
-            log.warn("Failed to parseInt " + PROP_UNCHANGED_CONTEXT_LIMIT + "=" + configuredLimit
-                + "   Will use a huge number as limit.", e);
+        try {
+            limit = Integer.parseInt( configuredLimit );
+        } catch( final NumberFormatException e ) {
+            log.warn("Failed to parseInt " + PROP_UNCHANGED_CONTEXT_LIMIT + "=" + configuredLimit + " Will use a huge number as limit.", e );
         }
         m_unchangedContextLimit = limit;
     }
@@ -140,43 +132,34 @@ public class ContextualDiffProvider implements DiffProvider {
      * 
      * {@inheritDoc}
      */
-    public synchronized String makeDiffHtml( WikiContext ctx, String wikiOld, String wikiNew )
-    {
+    public synchronized String makeDiffHtml( final WikiContext ctx, final String wikiOld, final String wikiNew ) {
         //
         // Sequencing handles lineterminator to <br /> and every-other consequtive space to a &nbsp;
         //
-        String[] alpha = sequence( TextUtil.replaceEntities( wikiOld ) );
-        String[] beta  = sequence( TextUtil.replaceEntities( wikiNew ) );
+        final String[] alpha = sequence( TextUtil.replaceEntities( wikiOld ) );
+        final String[] beta  = sequence( TextUtil.replaceEntities( wikiNew ) );
 
-        Revision rev = null;
-        try
-        {
+        final Revision rev;
+        try {
             rev = Diff.diff( alpha, beta, new MyersDiff() );
-        }
-        catch( DifferentiationFailedException dfe )
-        {
+        } catch( final DifferentiationFailedException dfe ) {
             log.error( "Diff generation failed", dfe );
             return "Error while creating version diff.";
         }
 
-        int revSize = rev.size();
-
-        StringBuffer sb = new StringBuffer();
+        final int revSize = rev.size();
+        final StringBuffer sb = new StringBuffer();
 
-        sb.append( m_diffStart );
+        sb.append( DIFF_START );
 
         //
         // The MyersDiff is a bit dumb by converting a single line multi-word diff into a series
         // of Changes. The ChangeMerger pulls them together again...
         //
-        ChangeMerger cm = new ChangeMerger( sb, alpha, revSize );
-
+        final ChangeMerger cm = new ChangeMerger( sb, alpha, revSize );
         rev.accept( cm );
-
         cm.shutdown();
-
-        sb.append( m_diffEnd );
-
+        sb.append( DIFF_END );
         return sb.toString();
     }
 
@@ -188,34 +171,29 @@ public class ContextualDiffProvider implements DiffProvider {
      * All this preseving of newlines and spaces is so the wikitext when diffed will have fidelity
      * to it's original form.  As a side affect we see edits of purely whilespace.
      */
-    private String[] sequence( String wikiText )
-    {
-        String[] linesArray = Diff.stringToArray( wikiText );
-
-        List<String> list = new ArrayList<String>();
-
-        for( int i = 0; i < linesArray.length; i++ )
-        {
-            String line = linesArray[i];
+    private String[] sequence( final String wikiText ) {
+        final String[] linesArray = Diff.stringToArray( wikiText );
+        final List< String > list = new ArrayList<>();
+        for( final String line : linesArray ) {
 
             String lastToken = null;
-            String token = null;
+            String token;
             // StringTokenizer might be discouraged but it still is perfect here...
-            for (StringTokenizer st = new StringTokenizer( line, " ", true ); st.hasMoreTokens();)
-            {
+            for( final StringTokenizer st = new StringTokenizer( line, " ", true ); st.hasMoreTokens(); ) {
                 token = st.nextToken();
 
-                if(" ".equals( lastToken) && " ".equals( token ))
-                    token = m_alternatingSpaceHtml;
+                if( " ".equals( lastToken ) && " ".equals( token ) ) {
+                    token = ALTERNATING_SPACE_HTML;
+                }
 
-                list.add(token);
+                list.add( token );
                 lastToken = token;
             }
 
-            list.add(m_lineBreakHtml); // Line Break
+            list.add( LINE_BREAK_HTML ); // Line Break
         }
 
-        return list.toArray( new String[0] );
+        return list.toArray( new String[ 0 ] );
     }
 
     /**
@@ -224,12 +202,11 @@ public class ContextualDiffProvider implements DiffProvider {
      * whole change process is threadsafe by encapsulating
      * all necessary variables.
      */
-    private final class ChangeMerger implements RevisionVisitor
-    {
-        private StringBuffer m_sb = null;
+    private final class ChangeMerger implements RevisionVisitor {
+        private StringBuffer m_sb;
 
         /** Keeping score of the original lines to process */
-        private int m_max = -1;
+        private int m_max;
 
         private int m_index = 0;
 
@@ -243,15 +220,14 @@ public class ContextualDiffProvider implements DiffProvider {
         private int m_mode = -1; /* -1: Unset, 0: Add, 1: Del, 2: Change mode */
 
         /** Buffer to coalesce the changes together */
-        private StringBuffer m_origBuf = null;
+        private StringBuffer m_origBuf;
 
-        private StringBuffer m_newBuf = null;
+        private StringBuffer m_newBuf;
 
         /** Reference to the source string array */
-        private String[] m_origStrings = null;
+        private String[] m_origStrings;
 
-        private ChangeMerger( final StringBuffer sb, final String[] origStrings, final int max )
-        {
+        private ChangeMerger( final StringBuffer sb, final String[] origStrings, final int max ) {
             m_sb = sb;
             m_origStrings = origStrings != null ? origStrings.clone() : null;
             m_max = max;
@@ -260,85 +236,73 @@ public class ContextualDiffProvider implements DiffProvider {
             m_newBuf = new StringBuffer();
         }
 
-        private void updateState( Delta delta )
-        {
+        private void updateState( final Delta delta ) {
             m_index++;
-
-            Chunk orig = delta.getOriginal();
-
-            if (orig.first() > m_firstElem)
-            {
+            final Chunk orig = delta.getOriginal();
+            if( orig.first() > m_firstElem ) {
                 // We "skip" some lines in the output.
                 // So flush out the last Change, if one exists.
                 flushChanges();
 
                 // Allow us to "skip" large swaths of unchanged text, show a "limited" amound of
                 // unchanged context so the changes are shown in
-                if ((orig.first() - m_firstElem) > 2 * m_unchangedContextLimit)
-                {
-                    if (m_firstElem > 0)
-                    {
-                        int endIndex = Math.min( m_firstElem + m_unchangedContextLimit, m_origStrings.length -1 );
+                if( ( orig.first() - m_firstElem ) > 2 * m_unchangedContextLimit ) {
+                    if (m_firstElem > 0) {
+                        final int endIndex = Math.min( m_firstElem + m_unchangedContextLimit, m_origStrings.length -1 );
 
-                        for (int j = m_firstElem; j < endIndex; j++)
-                            m_sb.append(m_origStrings[j]);
+                        for( int j = m_firstElem; j < endIndex; j++ ) {
+                            m_sb.append( m_origStrings[ j ] );
+                        }
 
-                        m_sb.append(m_elidedTailIndicatorHtml);
+                        m_sb.append( ELIDED_TAIL_INDICATOR_HTML );
                     }
 
-                    m_sb.append(m_elidedHeadIndicatorHtml);
+                    m_sb.append( ELIDED_HEAD_INDICATOR_HTML );
 
-                    int startIndex = Math.max(orig.first() - m_unchangedContextLimit, 0);
-                    for (int j = startIndex; j < orig.first(); j++)
-                        m_sb.append(m_origStrings[j]);
+                    final int startIndex = Math.max(orig.first() - m_unchangedContextLimit, 0);
+                    for (int j = startIndex; j < orig.first(); j++) {
+                        m_sb.append( m_origStrings[ j ] );
+                    }
 
-                }
-                else
-                {
+                } else {
                     // No need to skip anything, just output the whole range...
-                    for (int j = m_firstElem; j < orig.first(); j++)
-                    m_sb.append( m_origStrings[j] );
+                    for( int j = m_firstElem; j < orig.first(); j++ ) {
+                        m_sb.append( m_origStrings[ j ] );
+                    }
                 }
             }
             m_firstElem = orig.last() + 1;
         }
 
-        public void visit( Revision rev )
-        {
+        public void visit( final Revision rev ) {
             // GNDN (Goes nowhere, does nothing)
         }
 
-        public void visit( AddDelta delta )
-        {
+        public void visit( final AddDelta delta ) {
             updateState( delta );
 
             // We have run Deletes up to now. Flush them out.
-            if( m_mode == 1 )
-            {
+            if( m_mode == 1 ) {
                 flushChanges();
                 m_mode = -1;
             }
             // We are in "neutral mode". Start a new Change
-            if( m_mode == -1 )
-            {
+            if( m_mode == -1 ) {
                 m_mode = 0;
             }
 
             // We are in "add mode".
-            if( m_mode == 0 || m_mode == 2 )
-            {
+            if( m_mode == 0 || m_mode == 2 ) {
                 addNew( delta.getRevised() );
                 m_mode = 1;
             }
         }
 
-        public void visit( ChangeDelta delta )
-        {
+        public void visit( final ChangeDelta delta ) {
             updateState( delta );
 
             // We are in "neutral mode". A Change might be merged with an add or delete.
-            if( m_mode == -1 )
-            {
+            if( m_mode == -1 ) {
                 m_mode = 2;
             }
 
@@ -347,123 +311,101 @@ public class ContextualDiffProvider implements DiffProvider {
             addNew( delta.getRevised() );
         }
 
-        public void visit( DeleteDelta delta )
-        {
+        public void visit( final DeleteDelta delta ) {
             updateState( delta );
 
             // We have run Adds up to now. Flush them out.
-            if( m_mode == 0 )
-            {
+            if( m_mode == 0 ) {
                 flushChanges();
                 m_mode = -1;
             }
             // We are in "neutral mode". Start a new Change
-            if( m_mode == -1 )
-            {
+            if( m_mode == -1 ) {
                 m_mode = 1;
             }
 
             // We are in "delete mode".
-            if( m_mode == 1 || m_mode == 2 )
-            {
+            if( m_mode == 1 || m_mode == 2 ) {
                 addOrig( delta.getOriginal() );
                 m_mode = 1;
             }
         }
 
-        public void shutdown()
-        {
+        public void shutdown() {
             m_index = m_max + 1; // Make sure that no hyperlink gets created
             flushChanges();
 
-            if (m_firstElem < m_origStrings.length)
-            {
+            if( m_firstElem < m_origStrings.length ) {
                 // If there's more than the limit of the orginal left just emit limit and elided...
-                if ((m_origStrings.length - m_firstElem) > m_unchangedContextLimit)
-                {
-                    int endIndex = Math.min( m_firstElem + m_unchangedContextLimit, m_origStrings.length -1 );
-
-                    for (int j = m_firstElem; j < endIndex; j++)
-                    m_sb.append( m_origStrings[j] );
+                if( ( m_origStrings.length - m_firstElem ) > m_unchangedContextLimit ) {
+                    final int endIndex = Math.min( m_firstElem + m_unchangedContextLimit, m_origStrings.length -1 );
+                    for (int j = m_firstElem; j < endIndex; j++) {
+                        m_sb.append( m_origStrings[ j ] );
+                    }
 
-                    m_sb.append(m_elidedTailIndicatorHtml);
-                }
-                else
+                    m_sb.append( ELIDED_TAIL_INDICATOR_HTML );
+                } else {
                 // emit entire tail of original...
-                {
-                    for (int j = m_firstElem; j < m_origStrings.length; j++)
-                        m_sb.append(m_origStrings[j]);
+                    for( int j = m_firstElem; j < m_origStrings.length; j++ ) {
+                        m_sb.append( m_origStrings[ j ] );
+                    }
                 }
             }
         }
 
-        private void addOrig( Chunk chunk )
-        {
-            if( chunk != null )
-            {
+        private void addOrig( final Chunk chunk ) {
+            if( chunk != null ) {
                 chunk.toString( m_origBuf );
             }
         }
 
-        private void addNew( Chunk chunk )
-        {
-            if( chunk != null )
-            {
+        private void addNew( final Chunk chunk ) {
+            if( chunk != null ) {
                 chunk.toString( m_newBuf );
             }
         }
 
-
-
-        private void flushChanges()
-        {
-
-            if( m_newBuf.length() + m_origBuf.length() > 0 )
-            {
+        private void flushChanges() {
+            if( m_newBuf.length() + m_origBuf.length() > 0 ) {
                 // This is the span element which encapsulates anchor and the change itself
-                m_sb.append( m_changeStartHtml );
+                m_sb.append( CHANGE_START_HTML );
 
                 // Do we want to have a "back link"?
-                if( m_emitChangeNextPreviousHyperlinks && m_count > 1 )
-                {
-                    m_sb.append( m_backPreIndex );
+                if( m_emitChangeNextPreviousHyperlinks && m_count > 1 ) {
+                    m_sb.append( BACK_PRE_INDEX );
                     m_sb.append( m_count - 1 );
-                    m_sb.append( m_backPostIndex );
+                    m_sb.append( BACK_POST_INDEX );
                 }
 
                 // An anchor for the change.
-                if (m_emitChangeNextPreviousHyperlinks)
-                {
-                    m_sb.append( m_anchorPreIndex );
+                if (m_emitChangeNextPreviousHyperlinks) {
+                    m_sb.append( ANCHOR_PRE_INDEX );
                     m_sb.append( m_count++ );
-                    m_sb.append( m_anchorPostIndex );
+                    m_sb.append( ANCHOR_POST_INDEX );
                 }
 
                 // ... has been added
-                if( m_newBuf.length() > 0 )
-                {
-                    m_sb.append( m_insertionStartHtml );
+                if( m_newBuf.length() > 0 ) {
+                    m_sb.append( INSERTION_START_HTML );
                     m_sb.append( m_newBuf );
-                    m_sb.append( m_insertionEndHtml );
+                    m_sb.append( INSERTION_END_HTML );
                 }
 
                 // .. has been removed
-                if( m_origBuf.length() > 0 )
-                {
-                    m_sb.append( m_deletionStartHtml );
+                if( m_origBuf.length() > 0 ) {
+                    m_sb.append( DELETION_START_HTML );
                     m_sb.append( m_origBuf );
-                    m_sb.append( m_deletionEndHtml );
+                    m_sb.append( DELETION_END_HTML );
                 }
 
                 // Do we want a "forward" link?
-                if( m_emitChangeNextPreviousHyperlinks && (m_index < m_max) )
-                {
-                    m_sb.append( m_forwardPreIndex );
+                if( m_emitChangeNextPreviousHyperlinks && (m_index < m_max) ) {
+                    m_sb.append( FORWARD_PRE_INDEX );
                     m_sb.append( m_count ); // Has already been incremented.
-                    m_sb.append( m_forwardPostIndex );
+                    m_sb.append( FORWARD_POST_INDEX );
                 }
 
-                m_sb.append( m_changeEndHtml );
+                m_sb.append( CHANGE_END_HTML );
 
                 // Nuke the buffers.
                 m_origBuf = new StringBuffer();
@@ -474,4 +416,5 @@ public class ContextualDiffProvider implements DiffProvider {
             m_mode = -1;
         }
     }
+
 }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/DiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/DiffProvider.java
index 774eaa6..4a0aced 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/DiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/DiffProvider.java
@@ -18,19 +18,19 @@
  */
 package org.apache.wiki.diff;
 
-import java.io.IOException;
-import java.util.Properties;
-
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiProvider;
 import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
 
+import java.io.IOException;
+import java.util.Properties;
+
+
 /**
  *  Provides an SPI for creating a diff between two page versions.
  */
-public interface DiffProvider extends WikiProvider
-{
+public interface DiffProvider extends WikiProvider {
     /**
      * The return string is to be XHTML compliant ready to display html.  No further
      * processing of this text will be done by the wiki engine.
@@ -40,27 +40,23 @@ public interface DiffProvider extends WikiProvider
      * @param oldWikiText the old text
      * @param newWikiText the new text
      */
-    String makeDiffHtml(WikiContext context, String oldWikiText, String newWikiText);
+    String makeDiffHtml( WikiContext context, String oldWikiText, String newWikiText );
     
     /**
      *  If there is no diff provider set, this provider will work instead.
      */
-    class NullDiffProvider implements DiffProvider
-    {
+    class NullDiffProvider implements DiffProvider {
         /**
          *  {@inheritDoc}
          */
-        public String makeDiffHtml(WikiContext ctx, String oldWikiText, String newWikiText)
-        {
+        public String makeDiffHtml( final WikiContext ctx, final String oldWikiText, final String newWikiText ) {
             return "You are using the NullDiffProvider, check your properties file.";
         }
 
         /**
          *  {@inheritDoc}
          */
-        public void initialize(WikiEngine engine, Properties properties) 
-            throws NoRequiredPropertyException, IOException
-        {
+        public void initialize( final WikiEngine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
         }
 
         /**
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
index d15d5ce..6643847 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/DifferenceManager.java
@@ -19,21 +19,22 @@
 
 package org.apache.wiki.diff;
 
-import java.io.IOException;
-import java.util.Properties;
-
 import org.apache.log4j.Logger;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
 import org.apache.wiki.util.ClassUtil;
 
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Properties;
+
 
 /**
  * Load, initialize and delegate to the DiffProvider that will actually do the work.
  */
 public class DifferenceManager {
-    private static final Logger log = Logger.getLogger(DifferenceManager.class);
+    private static final Logger log = Logger.getLogger( DifferenceManager.class );
 
     /**
      * Property value for storing a diff provider.  Value is {@value}.
@@ -48,42 +49,32 @@ public class DifferenceManager {
      * @param engine The WikiEngine.
      * @param props  A set of properties.
      */
-    public DifferenceManager(WikiEngine engine, Properties props) {
-        loadProvider(props);
+    public DifferenceManager( final WikiEngine engine, final Properties props ) {
+        loadProvider( props );
+        initializeProvider( engine, props );
 
-        initializeProvider(engine, props);
-
-        log.info("Using difference provider: " + m_provider.getProviderInfo());
+        log.info( "Using difference provider: " + m_provider.getProviderInfo() );
     }
 
-    private void loadProvider(Properties props) {
-        String providerClassName = props.getProperty(PROP_DIFF_PROVIDER,
-                TraditionalDiffProvider.class.getName());
-
+    private void loadProvider( final Properties props ) {
+        final String providerClassName = props.getProperty( PROP_DIFF_PROVIDER, TraditionalDiffProvider.class.getName() );
         try {
-            Class<?> providerClass = ClassUtil.findClass("org.apache.wiki.diff", providerClassName);
-            m_provider = (DiffProvider) providerClass.newInstance();
-        } catch (ClassNotFoundException e) {
-            log.warn("Failed loading DiffProvider, will use NullDiffProvider.", e);
-        } catch (InstantiationException e) {
-            log.warn("Failed loading DiffProvider, will use NullDiffProvider.", e);
-        } catch (IllegalAccessException e) {
+            final Class< ? > providerClass = ClassUtil.findClass("org.apache.wiki.diff", providerClassName );
+            m_provider = (DiffProvider) providerClass.getDeclaredConstructor().newInstance();
+        } catch( final ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e ) {
             log.warn("Failed loading DiffProvider, will use NullDiffProvider.", e);
         }
 
-        if (null == m_provider) {
+        if( m_provider == null ) {
             m_provider = new DiffProvider.NullDiffProvider();
         }
     }
 
 
-    private void initializeProvider(WikiEngine engine, Properties props) {
+    private void initializeProvider( final WikiEngine engine, final Properties props ) {
         try {
             m_provider.initialize(engine, props);
-        } catch (NoRequiredPropertyException e1) {
-            log.warn("Failed initializing DiffProvider, will use NullDiffProvider.", e1);
-            m_provider = new DiffProvider.NullDiffProvider(); //doesn't need init'd
-        } catch (IOException e1) {
+        } catch( final NoRequiredPropertyException | IOException e1 ) {
             log.warn("Failed initializing DiffProvider, will use NullDiffProvider.", e1);
             m_provider = new DiffProvider.NullDiffProvider(); //doesn't need init'd
         }
@@ -97,17 +88,17 @@ public class DifferenceManager {
      * @param secondWikiText the new text
      * @return XHTML, or empty string, if no difference detected.
      */
-    public String makeDiff(WikiContext context, String firstWikiText, String secondWikiText) {
-        String diff = null;
+    public String makeDiff( final WikiContext context, final String firstWikiText, final String secondWikiText ) {
+        String diff;
         try {
-            diff = m_provider.makeDiffHtml(context, firstWikiText, secondWikiText);
+            diff = m_provider.makeDiffHtml( context, firstWikiText, secondWikiText );
 
-            if (diff == null) {
+            if( diff == null ) {
                 diff = "";
             }
-        } catch (Exception e) {
+        } catch( final Exception e ) {
             diff = "Failed to create a diff, check the logs.";
-            log.warn(diff, e);
+            log.warn( diff, e );
         }
         return diff;
     }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/ExternalDiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/ExternalDiffProvider.java
index 48b920f..fdf7cee 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/ExternalDiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/ExternalDiffProvider.java
@@ -35,11 +35,10 @@ import java.nio.charset.StandardCharsets;
 import java.util.Properties;
 
 /**
- * This DiffProvider allows external command line tools to be used to generate
- * the diff.
+ * This DiffProvider allows external command line tools to be used to generate the diff.
  */
-public class ExternalDiffProvider implements DiffProvider
-{
+public class ExternalDiffProvider implements DiffProvider {
+
     private static final Logger log = Logger.getLogger(ExternalDiffProvider.class);
 
     /**
@@ -85,13 +84,9 @@ public class ExternalDiffProvider implements DiffProvider
      * {@inheritDoc}
      * @see org.apache.wiki.WikiProvider#initialize(org.apache.wiki.WikiEngine, java.util.Properties)
      */
-    public void initialize( WikiEngine engine, Properties properties )
-        throws NoRequiredPropertyException, IOException
-    {
+    public void initialize( final WikiEngine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
         m_diffCommand = properties.getProperty( PROP_DIFFCOMMAND );
-
-        if( (null == m_diffCommand) || (m_diffCommand.trim().equals( "" )) )
-        {
+        if( m_diffCommand == null || m_diffCommand.trim().equals( "" ) ) {
             throw new NoRequiredPropertyException( "ExternalDiffProvider missing required property", PROP_DIFFCOMMAND );
         }
 
@@ -103,36 +98,33 @@ public class ExternalDiffProvider implements DiffProvider
      * Makes the diff by calling "diff" program.
      * {@inheritDoc}
      */
-    public String makeDiffHtml( WikiContext ctx, String p1, String p2 )
-    {
+    public String makeDiffHtml( final WikiContext ctx, final String p1, final String p2 ) {
         File f1 = null;
         File f2 = null;
         String diff = null;
 
-        try
-        {
+        try {
             f1 = FileUtil.newTmpFile(p1, m_encoding);
             f2 = FileUtil.newTmpFile(p2, m_encoding);
 
             String cmd = TextUtil.replaceString(m_diffCommand, "%s1", f1.getPath());
             cmd = TextUtil.replaceString(cmd, "%s2", f2.getPath());
 
-            String output = FileUtil.runSimpleCommand(cmd, f1.getParent());
+            final String output = FileUtil.runSimpleCommand(cmd, f1.getParent());
 
             // FIXME: Should this rely on the system default encoding?
-            String rawWikiDiff = new String( output.getBytes( StandardCharsets.ISO_8859_1 ), m_encoding );
-
-            String htmlWikiDiff = TextUtil.replaceEntities( rawWikiDiff );
+            final String rawWikiDiff = new String( output.getBytes( StandardCharsets.ISO_8859_1 ), m_encoding );
+            final String htmlWikiDiff = TextUtil.replaceEntities( rawWikiDiff );
 
-            if (m_traditionalColorization) //FIXME, see comment near declaration...
-                diff = colorizeDiff(htmlWikiDiff);
-            else
+            if (m_traditionalColorization) { //FIXME, see comment near declaration...
+                diff = colorizeDiff( htmlWikiDiff );
+            } else {
                 diff = htmlWikiDiff;
-
-        } catch (IOException e) {
-            log.error("Failed to do file diff", e);
-        } catch (InterruptedException e) {
-            log.error("Interrupted", e);
+            }
+        } catch( final IOException e ) {
+            log.error("Failed to do file diff", e );
+        } catch( final InterruptedException e ) {
+            log.error("Interrupted", e );
         } finally {
             if( f1 != null ) {
                 f1.delete();
@@ -149,30 +141,26 @@ public class ExternalDiffProvider implements DiffProvider
     /**
      * Goes through output provided by a diff command and inserts HTML tags to
      * make the result more legible. Currently colors lines starting with a +
-     * green, those starting with - reddish (hm, got to think of color blindness
-     * here...).
+     * green, those starting with - reddish (hm, got to think of color blindness here...).
      */
-    static String colorizeDiff(String diffText) throws IOException {
+    static String colorizeDiff( final String diffText ) throws IOException {
         if( diffText == null ) {
             return "Invalid diff - probably something wrong with server setup.";
         }
 
-        String line = null;
-        String start = null;
-        String stop = null;
+        String line;
+        String start;
+        String stop;
 
-        BufferedReader in = new BufferedReader( new StringReader( diffText ) );
-        StringBuilder out = new StringBuilder();
+        final BufferedReader in = new BufferedReader( new StringReader( diffText ) );
+        final StringBuilder out = new StringBuilder();
 
         out.append("<table class=\"diff\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
-        while( (line = in.readLine()) != null )
-        {
+        while( (line = in.readLine()) != null ) {
             stop = CSS_DIFF_CLOSE;
 
-            if( line.length() > 0 )
-            {
-                switch( line.charAt( 0 ) )
-                {
+            if( line.length() > 0 ) {
+                switch( line.charAt( 0 ) ) {
                     case DIFF_ADDED_SYMBOL:
                         start = CSS_DIFF_ADDED;
                         break;
@@ -182,18 +170,18 @@ public class ExternalDiffProvider implements DiffProvider
                     default:
                         start = CSS_DIFF_UNCHANGED;
                 }
-            }
-            else
-            {
+            } else {
                 start = CSS_DIFF_UNCHANGED;
             }
 
-            out.append( start );
-            out.append( line.trim() );
-            out.append( stop + "\n" );
+            out.append( start )
+               .append( line.trim() )
+               .append( stop )
+               .append( "\n" );
         }
 
         out.append( "</table>\n" );
         return out.toString();
     }
+
 }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/diff/TraditionalDiffProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/diff/TraditionalDiffProvider.java
index 14df7d9..6bd60bf 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/diff/TraditionalDiffProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/diff/TraditionalDiffProvider.java
@@ -19,14 +19,6 @@
 
 package org.apache.wiki.diff;
 
-import java.io.IOException;
-import java.text.ChoiceFormat;
-import java.text.Format;
-import java.text.MessageFormat;
-import java.text.NumberFormat;
-import java.util.Properties;
-import java.util.ResourceBundle;
-
 import org.apache.log4j.Logger;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
@@ -44,29 +36,32 @@ import org.suigeneris.jrcs.diff.delta.Chunk;
 import org.suigeneris.jrcs.diff.delta.DeleteDelta;
 import org.suigeneris.jrcs.diff.myers.MyersDiff;
 
+import java.io.IOException;
+import java.text.ChoiceFormat;
+import java.text.Format;
+import java.text.MessageFormat;
+import java.text.NumberFormat;
+import java.util.Properties;
+import java.util.ResourceBundle;
+
 
 /**
  * This is the JSPWiki 'traditional' diff.  It uses an internal diff engine.
- * 
  */
-public class TraditionalDiffProvider implements DiffProvider
-{
-    private static final Logger log = Logger.getLogger(TraditionalDiffProvider.class);
+public class TraditionalDiffProvider implements DiffProvider {
 
+    private static final Logger log = Logger.getLogger( TraditionalDiffProvider.class );
     private static final String CSS_DIFF_ADDED = "<tr><td class=\"diffadd\">";
     private static final String CSS_DIFF_REMOVED = "<tr><td class=\"diffrem\">";
     private static final String CSS_DIFF_UNCHANGED = "<tr><td class=\"diff\">";
     private static final String CSS_DIFF_CLOSE = "</td></tr>" + Diff.NL;
 
-
     /**
      *  Constructs the provider.
      */
-    public TraditionalDiffProvider()
-    {
+    public TraditionalDiffProvider() {
     }
 
-
     /**
      * {@inheritDoc}
      * @see org.apache.wiki.WikiProvider#getProviderInfo()
@@ -80,9 +75,7 @@ public class TraditionalDiffProvider implements DiffProvider
      * {@inheritDoc}
      * @see org.apache.wiki.WikiProvider#initialize(org.apache.wiki.WikiEngine, java.util.Properties)
      */
-    public void initialize(WikiEngine engine, Properties properties)
-        throws NoRequiredPropertyException, IOException
-    {
+    public void initialize( final WikiEngine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
     }
 
     /**
@@ -95,105 +88,91 @@ public class TraditionalDiffProvider implements DiffProvider
      * 
      * @return Full HTML diff.
      */
-    public String makeDiffHtml( WikiContext ctx, String p1, String p2 )
-    {
-        String diffResult = "";
+    public String makeDiffHtml( final WikiContext ctx, final String p1, final String p2 ) {
+        final String diffResult;
 
-        try
-        {
-            String[] first  = Diff.stringToArray(TextUtil.replaceEntities(p1));
-            String[] second = Diff.stringToArray(TextUtil.replaceEntities(p2));
-            Revision rev = Diff.diff(first, second, new MyersDiff());
+        try {
+            final String[] first  = Diff.stringToArray(TextUtil.replaceEntities(p1));
+            final String[] second = Diff.stringToArray(TextUtil.replaceEntities(p2));
+            final Revision rev = Diff.diff(first, second, new MyersDiff());
 
-            if( rev == null || rev.size() == 0 )
-            {
+            if( rev == null || rev.size() == 0 ) {
                 // No difference
-
                 return "";
             }
 
-            StringBuffer ret = new StringBuffer(rev.size() * 20); // Guessing how big it will become...
+            final StringBuffer ret = new StringBuffer(rev.size() * 20); // Guessing how big it will become...
 
-            ret.append("<table class=\"diff\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
-            rev.accept( new RevisionPrint(ctx,ret) );
-            ret.append("</table>\n");
+            ret.append( "<table class=\"diff\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n" );
+            rev.accept( new RevisionPrint( ctx, ret ) );
+            ret.append( "</table>\n" );
 
             return ret.toString();
-        }
-        catch( DifferentiationFailedException e )
-        {
+        } catch( final DifferentiationFailedException e ) {
             diffResult = "makeDiff failed with DifferentiationFailedException";
-            log.error(diffResult, e);
+            log.error( diffResult, e );
         }
 
         return diffResult;
     }
 
 
-    private static final class RevisionPrint
-        implements RevisionVisitor
-    {
-        private StringBuffer m_result = null;
+    private static final class RevisionPrint implements RevisionVisitor {
+
+        private StringBuffer m_result;
         private WikiContext  m_context;
         private ResourceBundle m_rb;
         
-        private RevisionPrint(WikiContext ctx,StringBuffer sb)
-        {
+        private RevisionPrint( final WikiContext ctx, final StringBuffer sb ) {
             m_result = sb;
             m_context = ctx;
             m_rb = Preferences.getBundle( ctx, InternationalizationManager.CORE_BUNDLE );
         }
 
-        public void visit(Revision rev)
-        {
+        public void visit( final Revision rev ) {
             // GNDN (Goes nowhere, does nothing)
         }
 
-        public void visit(AddDelta delta)
-        {
-            Chunk changed = delta.getRevised();
-            print(changed, m_rb.getString( "diff.traditional.added" ) );
-            changed.toString(m_result, CSS_DIFF_ADDED, CSS_DIFF_CLOSE);
+        public void visit( final AddDelta delta ) {
+            final Chunk changed = delta.getRevised();
+            print( changed, m_rb.getString( "diff.traditional.added" ) );
+            changed.toString( m_result, CSS_DIFF_ADDED, CSS_DIFF_CLOSE );
         }
 
-        public void visit(ChangeDelta delta)
-        {
-            Chunk changed = delta.getOriginal();
-            print(changed, m_rb.getString( "diff.traditional.changed") );
-            changed.toString(m_result, CSS_DIFF_REMOVED, CSS_DIFF_CLOSE);
-            delta.getRevised().toString(m_result, CSS_DIFF_ADDED, CSS_DIFF_CLOSE);
+        public void visit( final ChangeDelta delta ) {
+            final Chunk changed = delta.getOriginal();
+            print(changed, m_rb.getString( "diff.traditional.changed" ) );
+            changed.toString( m_result, CSS_DIFF_REMOVED, CSS_DIFF_CLOSE );
+            delta.getRevised().toString( m_result, CSS_DIFF_ADDED, CSS_DIFF_CLOSE );
         }
 
-        public void visit(DeleteDelta delta)
-        {
-            Chunk changed = delta.getOriginal();
-            print(changed, m_rb.getString( "diff.traditional.removed") );
-            changed.toString(m_result, CSS_DIFF_REMOVED, CSS_DIFF_CLOSE);
+        public void visit( final DeleteDelta delta ) {
+            final Chunk changed = delta.getOriginal();
+            print( changed, m_rb.getString( "diff.traditional.removed" ) );
+            changed.toString( m_result, CSS_DIFF_REMOVED, CSS_DIFF_CLOSE );
         }
 
-        private void print(Chunk changed, String type)
-        {
-            m_result.append(CSS_DIFF_UNCHANGED);
-            
-            String[] choiceString = 
-            {
+        private void print( final Chunk changed, final String type ) {
+            m_result.append( CSS_DIFF_UNCHANGED );
+
+            final String[] choiceString = {
                m_rb.getString("diff.traditional.oneline"),
                m_rb.getString("diff.traditional.lines")
             };
-            double[] choiceLimits = { 1, 2 };
-            
-            MessageFormat fmt = new MessageFormat("");
+            final double[] choiceLimits = { 1, 2 };
+
+            final MessageFormat fmt = new MessageFormat("");
             fmt.setLocale( Preferences.getLocale(m_context) );
-            ChoiceFormat cfmt = new ChoiceFormat( choiceLimits, choiceString );
+            final ChoiceFormat cfmt = new ChoiceFormat( choiceLimits, choiceString );
             fmt.applyPattern( type );
-            Format[] formats = { NumberFormat.getInstance(), cfmt, NumberFormat.getInstance() };
+            final Format[] formats = { NumberFormat.getInstance(), cfmt, NumberFormat.getInstance() };
             fmt.setFormats( formats );
-            
-            Object[] params = { changed.first() + 1, 
-                                changed.size(),
-                                changed.size() };
+
+            final Object[] params = { changed.first() + 1,
+                                      changed.size(),
+                                      changed.size() };
             m_result.append( fmt.format(params) );
-            m_result.append(CSS_DIFF_CLOSE);
+            m_result.append( CSS_DIFF_CLOSE );
         }
     }
 }


[jspwiki] 04/10: JSPWIKI-120: rename VariableManager as WikiVariableManager and extract interface from it (again, VariableManager)

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 203213bffba0fb3cb763abd755e7c47f904c6f40
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 18:16:53 2019 +0100

    JSPWIKI-120: rename VariableManager as WikiVariableManager and extract interface from it (again, VariableManager)
---
 .../main/java/org/apache/wiki/VariableManager.java | 360 +--------------------
 ...riableManager.java => WikiVariableManager.java} |  12 +-
 .../src/main/resources/ini/classmappings.xml       |   2 +-
 .../java/org/apache/wiki/VariableManagerTest.java  | 194 -----------
 .../org/apache/wiki/WikiVariableManagerTest.java   | 109 +++++++
 5 files changed, 122 insertions(+), 555 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java b/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
index 0ce2d02..ba51fc5 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
@@ -18,51 +18,19 @@
  */
 package org.apache.wiki;
 
-import org.apache.log4j.Logger;
-import org.apache.wiki.api.engine.FilterManager;
 import org.apache.wiki.api.exceptions.NoSuchVariableException;
-import org.apache.wiki.api.filters.PageFilter;
-import org.apache.wiki.i18n.InternationalizationManager;
-import org.apache.wiki.modules.InternalModule;
 import org.apache.wiki.parser.LinkParsingOperations;
-import org.apache.wiki.preferences.Preferences;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import java.lang.reflect.Method;
-import java.security.Principal;
-import java.util.Date;
-import java.util.List;
-import java.util.Properties;
-import java.util.ResourceBundle;
 
 /**
  *  Manages variables.  Variables are case-insensitive.  A list of all available variables is on a Wiki page called "WikiVariables".
  *
  *  @since 1.9.20.
  */
-public class VariableManager {
-
-    private static Logger log = Logger.getLogger( VariableManager.class );
+public interface VariableManager {
 
     // FIXME: These are probably obsolete.
-    public static final String VAR_ERROR = "error";
-    public static final String VAR_MSG   = "msg";
-
-    /**
-     *  Contains a list of those properties that shall never be shown. Put names here in lower case.
-     */
-    static final String[] THE_BIG_NO_NO_LIST = {
-        "jspwiki.auth.masterpassword"
-    };
-
-    /**
-     *  Creates a VariableManager object using the property list given.
-     *  @param props The properties.
-     */
-    public VariableManager( final Properties props )
-    {
-    }
+    String VAR_ERROR = "error";
+    String VAR_MSG   = "msg";
 
     /**
      *  Parses the link and finds a value.  This is essentially used once
@@ -76,17 +44,7 @@ public class VariableManager {
      *  @throws IllegalArgumentException If the format is not valid (does not start with "{$", is zero length, etc.)
      *  @throws NoSuchVariableException If a variable is not known.
      */
-    public String parseAndGetValue( final WikiContext context, final String link ) throws IllegalArgumentException, NoSuchVariableException {
-        if( !link.startsWith( "{$" ) ) {
-            throw new IllegalArgumentException( "Link does not start with {$" );
-        }
-        if( !link.endsWith( "}" ) ) {
-            throw new IllegalArgumentException( "Link does not end with }" );
-        }
-        final String varName = link.substring( 2, link.length() - 1 );
-
-        return getValue( context, varName.trim() );
-    }
+    String parseAndGetValue( final WikiContext context, final String link ) throws IllegalArgumentException, NoSuchVariableException;
 
     /**
      *  This method does in-place expansion of any variables.  However, the expansion is not done twice, that is,
@@ -98,37 +56,7 @@ public class VariableManager {
      *  @param source  The source string.
      *  @return The source string with variables expanded.
      */
-    // FIXME: somewhat slow.
-    public String expandVariables( final WikiContext context, final String source ) {
-        final StringBuilder result = new StringBuilder();
-        for( int i = 0; i < source.length(); i++ ) {
-            if( source.charAt(i) == '{' ) {
-                if( i < source.length()-2 && source.charAt(i+1) == '$' ) {
-                    final int end = source.indexOf( '}', i );
-
-                    if( end != -1 ) {
-                        final String varname = source.substring( i+2, end );
-                        String value;
-
-                        try {
-                            value = getValue( context, varname );
-                        } catch( final NoSuchVariableException | IllegalArgumentException e ) {
-                            value = e.getMessage();
-                        }
-
-                        result.append( value );
-                        i = end;
-                    }
-                } else {
-                    result.append( '{' );
-                }
-            } else {
-                result.append( source.charAt(i) );
-            }
-        }
-
-        return result.toString();
-    }
+    String expandVariables( final WikiContext context, final String source );
 
     /**
      *  Returns the value of a named variable.  See {@link #getValue(WikiContext, String)}. The only difference is that
@@ -139,13 +67,7 @@ public class VariableManager {
      *  @param defValue A default value.
      *  @return The variable value, or if not found, the default value.
      */
-    public String getValue( final WikiContext context, final String varName, final String defValue ) {
-        try {
-            return getValue( context, varName );
-        } catch( final NoSuchVariableException e ) {
-            return defValue;
-        }
-    }
+    String getValue( final WikiContext context, final String varName, final String defValue );
 
     /**
      *  Shortcut to getValue(). However, this method does not throw a NoSuchVariableException, but returns null
@@ -156,9 +78,7 @@ public class VariableManager {
      *  @return Variable value, or null, if there is no such variable.
      *  @since 2.2 on WikiEngine, moved to VariableManager on 2.11.0
      */
-    public String getVariable( final WikiContext context, final String name ) {
-        return getValue( context, name, null );
-    }
+    String getVariable( final WikiContext context, final String name );
 
     /**
      *  Returns a value of the named variable.  The resolving order is
@@ -184,270 +104,6 @@ public class VariableManager {
      *  @throws IllegalArgumentException If the name is somehow broken.
      *  @throws NoSuchVariableException If a variable is not known.
      */
-    public String getValue( final WikiContext context, final String varName ) throws IllegalArgumentException, NoSuchVariableException {
-        if( varName == null ) {
-            throw new IllegalArgumentException( "Null variable name." );
-        }
-        if( varName.length() == 0 ) {
-            throw new IllegalArgumentException( "Zero length variable name." );
-        }
-        // Faster than doing equalsIgnoreCase()
-        final String name = varName.toLowerCase();
-
-        for( final String value : THE_BIG_NO_NO_LIST ) {
-            if( name.equals( value ) ) {
-                return ""; // FIXME: Should this be something different?
-            }
-        }
-
-        try {
-            //
-            //  Using reflection to get system variables adding a new system variable
-            //  now only involves creating a new method in the SystemVariables class
-            //  with a name starting with get and the first character of the name of
-            //  the variable capitalized. Example:
-            //    public String getMysysvar(){
-            //      return "Hello World";
-            //    }
-            //
-            final SystemVariables sysvars = new SystemVariables( context );
-            final String methodName = "get" + Character.toUpperCase( name.charAt( 0 ) ) + name.substring( 1 );
-            final Method method = sysvars.getClass().getMethod( methodName );
-            return ( String )method.invoke( sysvars );
-        } catch( final NoSuchMethodException e1 ) {
-            //
-            //  It is not a system var. Time to handle the other cases.
-            //
-            //  Check if such a context variable exists, returning its string representation.
-            //
-            if( ( context.getVariable( varName ) ) != null ) {
-                return context.getVariable( varName ).toString();
-            }
-
-            //
-            //  Well, I guess it wasn't a final straw.  We also allow variables from the session and the request (in this order).
-            //
-            final HttpServletRequest req = context.getHttpRequest();
-            if( req != null && req.getSession() != null ) {
-                final HttpSession session = req.getSession();
-
-                try {
-                    String s = ( String )session.getAttribute( varName );
-
-                    if( s != null ) {
-                        return s;
-                    }
-
-                    s = context.getHttpParameter( varName );
-                    if( s != null ) {
-                        return s;
-                    }
-                } catch( final ClassCastException e ) {
-                    log.debug( "Not a String: " + varName );
-                }
-            }
-
-            //
-            // And the final straw: see if the current page has named metadata.
-            //
-            final WikiPage pg = context.getPage();
-            if( pg != null ) {
-                final Object metadata = pg.getAttribute( varName );
-                if( metadata != null ) {
-                    return metadata.toString();
-                }
-            }
-
-            //
-            // And the final straw part 2: see if the "real" current page has named metadata. This allows
-            // a parent page to control a inserted page through defining variables
-            //
-            final WikiPage rpg = context.getRealPage();
-            if( rpg != null ) {
-                final Object metadata = rpg.getAttribute( varName );
-                if( metadata != null ) {
-                    return metadata.toString();
-                }
-            }
-
-            //
-            // Next-to-final straw: attempt to fetch using property name. We don't allow fetching any other
-            // properties than those starting with "jspwiki.".  I know my own code, but I can't vouch for bugs
-            // in other people's code... :-)
-            //
-            if( varName.startsWith("jspwiki.") ) {
-                final Properties props = context.getEngine().getWikiProperties();
-                final String s = props.getProperty( varName );
-                if( s != null ) {
-                    return s;
-                }
-            }
-
-            //
-            //  Final defaults for some known quantities.
-            //
-            if( varName.equals( VAR_ERROR ) || varName.equals( VAR_MSG ) ) {
-                return "";
-            }
-
-            throw new NoSuchVariableException( "No variable " + varName + " defined." );
-        } catch( final Exception e ) {
-            log.info("Interesting exception: cannot fetch variable value", e );
-        }
-        return "";
-    }
-
-    /**
-     *  This class provides the implementation for the different system variables.
-     *  It is called via Reflection - any access to a variable called $xxx is mapped
-     *  to getXxx() on this class.
-     *  <p>
-     *  This is a lot neater than using a huge if-else if branching structure
-     *  that we used to have before.
-     *  <p>
-     *  Note that since we are case insensitive for variables, and VariableManager
-     *  calls var.toLowerCase(), the getters for the variables do not have
-     *  capitalization anywhere.  This may look a bit odd, but then again, this
-     *  is not meant to be a public class.
-     *
-     *  @since 2.7.0
-     */
-    @SuppressWarnings( "unused" )
-    private static class SystemVariables
-    {
-        private final WikiContext m_context;
-
-        public SystemVariables( final WikiContext context )
-        {
-            m_context=context;
-        }
-
-        public String getPagename()
-        {
-            return m_context.getPage().getName();
-        }
-
-        public String getApplicationname()
-        {
-            return m_context.getEngine().getApplicationName();
-        }
-
-        public String getJspwikiversion()
-        {
-            return Release.getVersionString();
-        }
-
-        public String getEncoding() {
-            return m_context.getEngine().getContentEncoding().displayName();
-        }
-
-        public String getTotalpages() {
-            return Integer.toString( m_context.getEngine().getPageCount() );
-        }
-
-        public String getPageprovider()
-        {
-            return m_context.getEngine().getCurrentProvider();
-        }
-
-        public String getPageproviderdescription()
-        {
-            return m_context.getEngine().getCurrentProviderInfo();
-        }
-
-        public String getAttachmentprovider() {
-            final WikiProvider p = m_context.getEngine().getAttachmentManager().getCurrentProvider();
-            return (p != null) ? p.getClass().getName() : "-";
-        }
-
-        public String getAttachmentproviderdescription() {
-            final WikiProvider p = m_context.getEngine().getAttachmentManager().getCurrentProvider();
-            return (p != null) ? p.getProviderInfo() : "-";
-        }
-
-        public String getInterwikilinks() {
-            final StringBuilder res = new StringBuilder();
-
-            for( final String link : m_context.getEngine().getAllInterWikiLinks() ) {
-                if( res.length() > 0 ) {
-                    res.append( ", " );
-                }
-                res.append( link );
-                res.append( " --> " );
-                res.append( m_context.getEngine().getInterWikiURL( link ) );
-            }
-            return res.toString();
-        }
-
-        public String getInlinedimages() {
-            final StringBuilder res = new StringBuilder();
-            for( final String ptrn : m_context.getEngine().getAllInlinedImagePatterns() ) {
-                if( res.length() > 0 ) {
-                    res.append( ", " );
-                }
-
-                res.append( ptrn );
-            }
-
-            return res.toString();
-        }
-
-        public String getPluginpath() {
-            final String s = m_context.getEngine().getPluginManager().getPluginSearchPath();
-
-            return ( s == null ) ? "-" : s;
-        }
-
-        public String getBaseurl()
-        {
-            return m_context.getEngine().getBaseURL();
-        }
-
-        public String getUptime() {
-            final Date now = new Date();
-            long secondsRunning = ( now.getTime() - m_context.getEngine().getStartTime().getTime() ) / 1_000L;
-
-            final long seconds = secondsRunning % 60;
-            final long minutes = (secondsRunning /= 60) % 60;
-            final long hours = (secondsRunning /= 60) % 24;
-            final long days = secondsRunning /= 24;
-
-            return days + "d, " + hours + "h " + minutes + "m " + seconds + "s";
-        }
-
-        public String getLoginstatus() {
-            final WikiSession session = m_context.getWikiSession();
-            return Preferences.getBundle( m_context, InternationalizationManager.CORE_BUNDLE ).getString( "varmgr." + session.getStatus() );
-        }
-
-        public String getUsername() {
-            final Principal wup = m_context.getCurrentUser();
-            final ResourceBundle rb = Preferences.getBundle( m_context, InternationalizationManager.CORE_BUNDLE );
-            return wup != null ? wup.getName() : rb.getString( "varmgr.not.logged.in" );
-        }
-
-        public String getRequestcontext()
-        {
-            return m_context.getRequestContext();
-        }
-
-        public String getPagefilters() {
-            final FilterManager fm = m_context.getEngine().getFilterManager();
-            final List< PageFilter > filters = fm.getFilterList();
-            final StringBuilder sb = new StringBuilder();
-            for( final PageFilter pf : filters ) {
-                final String f = pf.getClass().getName();
-                if( pf instanceof InternalModule ) {
-                    continue;
-                }
-
-                if( sb.length() > 0 ) {
-                    sb.append( ", " );
-                }
-                sb.append( f );
-            }
-            return sb.toString();
-        }
-    }
+    String getValue( final WikiContext context, final String varName ) throws IllegalArgumentException, NoSuchVariableException;
 
 }
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiVariableManager.java
similarity index 98%
copy from jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
copy to jspwiki-main/src/main/java/org/apache/wiki/WikiVariableManager.java
index 0ce2d02..5408e9b 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiVariableManager.java
@@ -36,18 +36,15 @@ import java.util.List;
 import java.util.Properties;
 import java.util.ResourceBundle;
 
+
 /**
  *  Manages variables.  Variables are case-insensitive.  A list of all available variables is on a Wiki page called "WikiVariables".
  *
  *  @since 1.9.20.
  */
-public class VariableManager {
-
-    private static Logger log = Logger.getLogger( VariableManager.class );
+public class WikiVariableManager implements VariableManager {
 
-    // FIXME: These are probably obsolete.
-    public static final String VAR_ERROR = "error";
-    public static final String VAR_MSG   = "msg";
+    private static Logger log = Logger.getLogger( WikiVariableManager.class );
 
     /**
      *  Contains a list of those properties that shall never be shown. Put names here in lower case.
@@ -60,8 +57,7 @@ public class VariableManager {
      *  Creates a VariableManager object using the property list given.
      *  @param props The properties.
      */
-    public VariableManager( final Properties props )
-    {
+    public WikiVariableManager( final Properties props ) {
     }
 
     /**
diff --git a/jspwiki-main/src/main/resources/ini/classmappings.xml b/jspwiki-main/src/main/resources/ini/classmappings.xml
index 649f034..90d13d3 100644
--- a/jspwiki-main/src/main/resources/ini/classmappings.xml
+++ b/jspwiki-main/src/main/resources/ini/classmappings.xml
@@ -57,7 +57,7 @@
   </mapping>
   <mapping>
     <requestedClass>org.apache.wiki.VariableManager</requestedClass>
-    <mappedClass>org.apache.wiki.VariableManager</mappedClass>
+    <mappedClass>org.apache.wiki.WikiVariableManager</mappedClass>
   </mapping>
   <mapping>
     <requestedClass>org.apache.wiki.api.engine.FilterManager</requestedClass>
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/VariableManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/VariableManagerTest.java
deleted file mode 100644
index 1ab7bc2..0000000
--- a/jspwiki-main/src/test/java/org/apache/wiki/VariableManagerTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
- */
-
-package org.apache.wiki;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.AfterEach;
-
-import java.util.Properties;
-
-import org.apache.log4j.PropertyConfigurator;
-import org.apache.wiki.api.exceptions.NoSuchVariableException;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.Assertions;
-
-public class VariableManagerTest
-{
-    VariableManager m_variableManager;
-    WikiContext     m_context;
-
-    static final String PAGE_NAME = "TestPage";
-
-    @BeforeEach
-    public void setUp()
-        throws Exception
-    {
-        Properties props = TestEngine.getTestProperties();
-        PropertyConfigurator.configure(props);
-
-        m_variableManager = new VariableManager( props );
-        TestEngine testEngine = new TestEngine( props );
-        m_context = new WikiContext( testEngine,
-                                     new WikiPage( testEngine, PAGE_NAME ) );
-    }
-
-    @AfterEach
-    public void tearDown()
-    {
-    }
-
-    @Test
-    public void testIllegalInsert1()
-        throws Exception
-    {
-        try
-        {
-            m_variableManager.parseAndGetValue( m_context, "" );
-            Assertions.fail( "Did not Assertions.fail" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK.
-        }
-    }
-
-    @Test
-    public void testIllegalInsert2()
-        throws Exception
-    {
-        try
-        {
-            m_variableManager.parseAndGetValue( m_context, "{$" );
-            Assertions.fail( "Did not Assertions.fail" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK.
-        }
-    }
-
-    @Test
-    public void testIllegalInsert3()
-        throws Exception
-    {
-        try
-        {
-            m_variableManager.parseAndGetValue( m_context, "{$pagename" );
-            Assertions.fail( "Did not Assertions.fail" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK.
-        }
-    }
-
-    @Test
-    public void testIllegalInsert4()
-        throws Exception
-    {
-        try
-        {
-            m_variableManager.parseAndGetValue( m_context, "{$}" );
-            Assertions.fail( "Did not Assertions.fail" );
-        }
-        catch( IllegalArgumentException e )
-        {
-            // OK.
-        }
-    }
-
-    @Test
-    public void testNonExistantVariable()
-    {
-        try
-        {
-            m_variableManager.parseAndGetValue( m_context, "{$no_such_variable}" );
-            Assertions.fail( "Did not Assertions.fail" );
-        }
-        catch( NoSuchVariableException e )
-        {
-            // OK.
-        }
-    }
-
-    @Test
-    public void testPageName()
-        throws Exception
-    {
-        String res = m_variableManager.getValue( m_context, "pagename" );
-
-        Assertions.assertEquals( PAGE_NAME, res );
-    }
-
-    @Test
-    public void testPageName2()
-        throws Exception
-    {
-        String res =  m_variableManager.parseAndGetValue( m_context, "{$  pagename  }" );
-
-        Assertions.assertEquals( PAGE_NAME, res );
-    }
-
-    @Test
-    public void testMixedCase()
-        throws Exception
-    {
-        String res =  m_variableManager.parseAndGetValue( m_context, "{$PAGeNamE}" );
-
-        Assertions.assertEquals( PAGE_NAME, res );
-    }
-
-    @Test
-    public void testExpand1()
-        throws Exception
-    {
-        String res = m_variableManager.expandVariables( m_context, "Testing {$pagename}..." );
-
-        Assertions.assertEquals( "Testing "+PAGE_NAME+"...", res );
-    }
-
-    @Test
-    public void testExpand2()
-        throws Exception
-    {
-        String res = m_variableManager.expandVariables( m_context, "{$pagename} tested..." );
-
-        Assertions.assertEquals( PAGE_NAME+" tested...", res );
-    }
-
-    @Test
-    public void testExpand3()
-        throws Exception
-    {
-        String res = m_variableManager.expandVariables( m_context, "Testing {$pagename}, {$applicationname}" );
-
-        Assertions.assertEquals( "Testing "+PAGE_NAME+", JSPWiki", res );
-    }
-
-    @Test
-    public void testExpand4()
-        throws Exception
-    {
-        String res = m_variableManager.expandVariables( m_context, "Testing {}, {{{}" );
-
-        Assertions.assertEquals( "Testing {}, {{{}", res );
-    }
-
-}
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/WikiVariableManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/WikiVariableManagerTest.java
new file mode 100644
index 0000000..86f8259
--- /dev/null
+++ b/jspwiki-main/src/test/java/org/apache/wiki/WikiVariableManagerTest.java
@@ -0,0 +1,109 @@
+/*
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+ */
+
+package org.apache.wiki;
+
+import org.apache.wiki.api.exceptions.NoSuchVariableException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+
+public class WikiVariableManagerTest  {
+
+    static VariableManager m_variableManager;
+    static WikiContext     m_context;
+
+    static final String PAGE_NAME = "TestPage";
+
+    @BeforeAll
+    public static void setUp() {
+        final TestEngine testEngine = TestEngine.build();
+        m_variableManager = new WikiVariableManager( TestEngine.getTestProperties() );
+        m_context = new WikiContext( testEngine, new WikiPage( testEngine, PAGE_NAME ) );
+    }
+
+    @Test
+    public void testIllegalInsert1() {
+        Assertions.assertThrows( IllegalArgumentException.class, () -> m_variableManager.parseAndGetValue( m_context, "" ) );
+    }
+
+    @Test
+    public void testIllegalInsert2() {
+        Assertions.assertThrows( IllegalArgumentException.class, () -> m_variableManager.parseAndGetValue( m_context, "{$" ) );
+    }
+
+    @Test
+    public void testIllegalInsert3() {
+        Assertions.assertThrows( IllegalArgumentException.class, () -> m_variableManager.parseAndGetValue( m_context, "{$pagename" ) );
+    }
+
+    @Test
+    public void testIllegalInsert4() {
+        Assertions.assertThrows( IllegalArgumentException.class, () -> m_variableManager.parseAndGetValue( m_context, "{$}" ) );
+    }
+
+    @Test
+    public void testNonExistantVariable() {
+        Assertions.assertThrows( NoSuchVariableException.class, () -> m_variableManager.parseAndGetValue( m_context, "{$no_such_variable}" ) );
+    }
+
+    @Test
+    public void testPageName() throws Exception {
+        final String res = m_variableManager.getValue( m_context, "pagename" );
+        Assertions.assertEquals( PAGE_NAME, res );
+    }
+
+    @Test
+    public void testPageName2() throws Exception {
+        final String res =  m_variableManager.parseAndGetValue( m_context, "{$  pagename  }" );
+        Assertions.assertEquals( PAGE_NAME, res );
+    }
+
+    @Test
+    public void testMixedCase() throws Exception {
+        final String res =  m_variableManager.parseAndGetValue( m_context, "{$PAGeNamE}" );
+        Assertions.assertEquals( PAGE_NAME, res );
+    }
+
+    @Test
+    public void testExpand1() {
+        final String res = m_variableManager.expandVariables( m_context, "Testing {$pagename}..." );
+        Assertions.assertEquals( "Testing "+PAGE_NAME+"...", res );
+    }
+
+    @Test
+    public void testExpand2() {
+        final String res = m_variableManager.expandVariables( m_context, "{$pagename} tested..." );
+        Assertions.assertEquals( PAGE_NAME+" tested...", res );
+    }
+
+    @Test
+    public void testExpand3() {
+        final String res = m_variableManager.expandVariables( m_context, "Testing {$pagename}, {$applicationname}" );
+        Assertions.assertEquals( "Testing "+PAGE_NAME+", JSPWiki", res );
+    }
+
+    @Test
+    public void testExpand4() {
+        final String res = m_variableManager.expandVariables( m_context, "Testing {}, {{{}" );
+        Assertions.assertEquals( "Testing {}, {{{}", res );
+    }
+
+}


[jspwiki] 10/10: 2.11.0-M7-git-02

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 528d825432866f7703346800231ae9813519175d
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 19:19:42 2019 +0100

    2.11.0-M7-git-02
---
 ChangeLog.md                                            | 10 ++++++++++
 jspwiki-main/src/main/java/org/apache/wiki/Release.java |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index b70ff72..a8ee2dc 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -17,6 +17,16 @@ specific language governing permissions and limitations
 under the License.
 -->
 
+**2019-12-20  Juan Pablo Santos (juanpablo AT apache DOT org)**
+
+* _2.11.0-M7-git-02_
+
+* [JSPWIKI-120](https://issues.apache.org/jira/browse/JSPWIKI-120): Separate rendering engine from core
+    * `DifferenceManager` renamed as `WikiDifferenceManager`, with new `DifferenceManager` extracted as interface of `WikiDifferenceManager`
+    * `getDiff(..)` method deleted from `WikiEngine`, use the one located on `DifferenceManager`
+    * `VariableManager` renamed as `WikiVariableManager`, with new `VariableManager` extracted as interface of `WikiVariableManager`
+    * `getVariable(..)` method deleted from `WikiEngine`, use the one located on `VariableManager`
+
 **2019-12-19  Juan Pablo Santos (juanpablo AT apache DOT org)**
 
 * _2.11.0-M7-git-01_
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 3fea463..8aaa884 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/Release.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/Release.java
@@ -72,7 +72,7 @@ public final class Release {
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "git-01";
+    public static final String     BUILD         = "git-02";
 
     /**
      *  This is the generic version string you should use when printing out the version.  It is of


[jspwiki] 08/10: JSPWIKI-120: move getDiff from WikiEngine to DifferenceManager

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 b1b73c03c97a945a2db570550e39428a33cf4b39
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 19:17:44 2019 +0100

    JSPWIKI-120: move getDiff from WikiEngine to DifferenceManager
---
 .../src/main/java/org/apache/wiki/WikiEngine.java  | 29 ----------------------
 1 file changed, 29 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 5be6d67..9db2f4e 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -1737,35 +1737,6 @@ public class WikiEngine  {
     }
 
     /**
-     *  Returns a diff of two versions of a page.
-     *  <p>
-     *  Note that the API was changed in 2.6 to provide a WikiContext object!
-     *
-     *  @param context The WikiContext of the page you wish to get a diff from
-     *  @param version1 Version number of the old page.  If WikiPageProvider.LATEST_VERSION (-1), then uses current page.
-     *  @param version2 Version number of the new page.  If WikiPageProvider.LATEST_VERSION (-1), then uses current page.
-     *
-     *  @return A HTML-ized difference between two pages.  If there is no difference, returns an empty string.
-     */
-    public String getDiff( WikiContext context, int version1, int version2 )
-    {
-        String page = context.getPage().getName();
-        String page1 = getPureText( page, version1 );
-        String page2 = getPureText( page, version2 );
-
-        // Kludge to make diffs for new pages to work this way.
-
-        if( version1 == WikiPageProvider.LATEST_VERSION )
-        {
-            page1 = "";
-        }
-
-        String diff  = m_differenceManager.makeDiff( context, page1, page2 );
-
-        return diff;
-    }
-
-    /**
      *  Returns this object's ReferenceManager.
      *  @return The current ReferenceManager instance.
      *


[jspwiki] 07/10: get rid of final on method parameters, is not needed there

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 15196d69f5b4db20c6549154dcaf6e04f85277cc
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 20 19:12:33 2019 +0100

    get rid of final on method parameters, is not needed there
---
 .../src/main/java/org/apache/wiki/VariableManager.java         | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java b/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
index ba51fc5..dda06a6 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/VariableManager.java
@@ -44,7 +44,7 @@ public interface VariableManager {
      *  @throws IllegalArgumentException If the format is not valid (does not start with "{$", is zero length, etc.)
      *  @throws NoSuchVariableException If a variable is not known.
      */
-    String parseAndGetValue( final WikiContext context, final String link ) throws IllegalArgumentException, NoSuchVariableException;
+    String parseAndGetValue( WikiContext context, String link ) throws IllegalArgumentException, NoSuchVariableException;
 
     /**
      *  This method does in-place expansion of any variables.  However, the expansion is not done twice, that is,
@@ -56,7 +56,7 @@ public interface VariableManager {
      *  @param source  The source string.
      *  @return The source string with variables expanded.
      */
-    String expandVariables( final WikiContext context, final String source );
+    String expandVariables( WikiContext context, String source );
 
     /**
      *  Returns the value of a named variable.  See {@link #getValue(WikiContext, String)}. The only difference is that
@@ -67,7 +67,7 @@ public interface VariableManager {
      *  @param defValue A default value.
      *  @return The variable value, or if not found, the default value.
      */
-    String getValue( final WikiContext context, final String varName, final String defValue );
+    String getValue( WikiContext context, String varName, String defValue );
 
     /**
      *  Shortcut to getValue(). However, this method does not throw a NoSuchVariableException, but returns null
@@ -78,7 +78,7 @@ public interface VariableManager {
      *  @return Variable value, or null, if there is no such variable.
      *  @since 2.2 on WikiEngine, moved to VariableManager on 2.11.0
      */
-    String getVariable( final WikiContext context, final String name );
+    String getVariable( WikiContext context, String name );
 
     /**
      *  Returns a value of the named variable.  The resolving order is
@@ -104,6 +104,6 @@ public interface VariableManager {
      *  @throws IllegalArgumentException If the name is somehow broken.
      *  @throws NoSuchVariableException If a variable is not known.
      */
-    String getValue( final WikiContext context, final String varName ) throws IllegalArgumentException, NoSuchVariableException;
+    String getValue( WikiContext context, String varName ) throws IllegalArgumentException, NoSuchVariableException;
 
 }