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/06 22:43:28 UTC

[jspwiki] branch master updated (bd44d4d -> 4c51713)

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 bd44d4d  sublists should use 4 spaces instead of 2
     new 8f8a98c  remove unneeded throws Exception from tests
     new 886a664  remove unnecessary log4j configuration on test
     new 03192b3  refactor test so that testEngine doesn't get garbage collected - should fix ocassional test failures
     new afa0035  Maven plugins changes + dependency updates
     new b705a6d  added note on generating javadocs with JDK >=9
     new bb06b04  move safeGetQueryParameter from WikiEngine to HttpUtil
     new 5826e99  use safeGetQueryParameter from HttpUtil, remove one superfluous if condition + remove other warnings noted by IntelliJ
     new 812bfbc  move getRequiredProperty from WikiEngine to TextUtil
     new ef5fb04  format interface
     new d169b50  fix javadocs on DummyUserDatabase + add format + fix some warnings reported by IntelliJ
     new e7c35b1  use method from TextUtil
     new 950a64c  use method from TextUtil
     new c087db6  update Tika to 1.23
     new 4c51713  2.11.0-M6-git-05

The 14 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                                       |  20 ++
 .../java/org/apache/wiki/its/AnonymousViewIT.java  |  13 +-
 .../src/main/java/org/apache/wiki/its/LoginIT.java |   4 +-
 .../src/main/java/org/apache/wiki/Release.java     |   2 +-
 .../src/main/java/org/apache/wiki/WikiEngine.java  |  56 +---
 .../main/java/org/apache/wiki/WikiProvider.java    |  10 +-
 .../java/org/apache/wiki/auth/UserManager.java     | 165 ++++-------
 .../org/apache/wiki/pages/DefaultPageManager.java  |   6 +-
 .../wiki/providers/CachingAttachmentProvider.java  |  38 +--
 .../org/apache/wiki/providers/CachingProvider.java |  36 +--
 .../java/org/apache/wiki/tags/CalendarTag.java     | 213 ++++++--------
 .../test/java/org/apache/wiki/WikiEngineTest.java  |  21 --
 .../org/apache/wiki/auth/user/UserProfileTest.java |  10 +-
 .../java/org/apache/wiki/ui/PageCommandTest.java   |  22 +-
 .../main/java/org/apache/wiki/util/HttpUtil.java   |  40 ++-
 .../main/java/org/apache/wiki/util/TextUtil.java   |  19 ++
 .../java/org/apache/wiki/util/TextUtilTest.java    | 317 ++++++++-------------
 jspwiki-war/src/main/webapp/rss.jsp                |   4 +-
 mvn_cheat-sheet.md                                 |   3 +-
 pom.xml                                            |  27 +-
 20 files changed, 417 insertions(+), 609 deletions(-)


[jspwiki] 11/14: use method from TextUtil

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 e7c35b14bf4d65f254e12ac24956a41287dd8c7d
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 23:27:32 2019 +0100

    use method from TextUtil
---
 .../org/apache/wiki/pages/DefaultPageManager.java  |  6 ++--
 .../wiki/providers/CachingAttachmentProvider.java  | 38 ++++++++++++----------
 .../org/apache/wiki/providers/CachingProvider.java | 36 +++++++++++---------
 3 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/pages/DefaultPageManager.java b/jspwiki-main/src/main/java/org/apache/wiki/pages/DefaultPageManager.java
index 7a305f6..0f508c5 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/pages/DefaultPageManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/pages/DefaultPageManager.java
@@ -53,6 +53,7 @@ import java.util.Date;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -91,9 +92,10 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
      *
      * @param engine WikiEngine instance
      * @param props  Properties to use for initialization
+     * @throws NoSuchElementException {@value #PROP_PAGEPROVIDER} property not found on WikiEngine properties
      * @throws WikiException If anything goes wrong, you get this.
      */
-    public DefaultPageManager(WikiEngine engine, Properties props) throws WikiException {
+    public DefaultPageManager(WikiEngine engine, Properties props) throws NoSuchElementException, WikiException {
         super(engine);
         String classname;
         m_engine = engine;
@@ -107,7 +109,7 @@ public class DefaultPageManager extends ModuleManager implements PageManager {
         if (useCache) {
             classname = "org.apache.wiki.providers.CachingProvider";
         } else {
-            classname = m_engine.getRequiredProperty(props, PROP_PAGEPROVIDER);
+            classname = TextUtil.getRequiredProperty(props, PROP_PAGEPROVIDER);
         }
 
         pageSorter.initialize( props );
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
index c089a68..930f8af 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingAttachmentProvider.java
@@ -18,15 +18,9 @@
  */
 package org.apache.wiki.providers;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
 import org.apache.log4j.Logger;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiPage;
@@ -37,10 +31,18 @@ import org.apache.wiki.attachment.Attachment;
 import org.apache.wiki.attachment.AttachmentManager;
 import org.apache.wiki.search.QueryItem;
 import org.apache.wiki.util.ClassUtil;
+import org.apache.wiki.util.TextUtil;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Properties;
 
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.CacheManager;
-import net.sf.ehcache.Element;
 
 /**
  *  Provides a caching attachment provider.  This class rests on top of a
@@ -95,10 +97,7 @@ public class CachingAttachmentProvider
      * {@inheritDoc}
      */
     @Override
-    public void initialize( WikiEngine engine, Properties properties )
-        throws NoRequiredPropertyException,
-               IOException
-    {
+    public void initialize( WikiEngine engine, Properties properties ) throws NoRequiredPropertyException, IOException {
         log.info("Initing CachingAttachmentProvider");
 
         String attCollCacheName = engine.getApplicationName() + "." + ATTCOLLCACHE_NAME;
@@ -122,7 +121,12 @@ public class CachingAttachmentProvider
         //
         //  Find and initialize real provider.
         //
-        String classname = engine.getRequiredProperty( properties, AttachmentManager.PROP_PROVIDER );
+        final String classname;
+        try {
+            classname = TextUtil.getRequiredProperty( properties, AttachmentManager.PROP_PROVIDER );
+        } catch( final NoSuchElementException e ) {
+            throw new NoRequiredPropertyException( e.getMessage(), AttachmentManager.PROP_PROVIDER );
+        }
 
         try
         {
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingProvider.java
index 6ae54c2..234d74b 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/providers/CachingProvider.java
@@ -18,14 +18,9 @@
  */
 package org.apache.wiki.providers;
 
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.TreeSet;
-
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
 import org.apache.log4j.Logger;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
@@ -38,10 +33,16 @@ import org.apache.wiki.render.RenderingManager;
 import org.apache.wiki.search.QueryItem;
 import org.apache.wiki.search.SearchResult;
 import org.apache.wiki.util.ClassUtil;
+import org.apache.wiki.util.TextUtil;
 
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.CacheManager;
-import net.sf.ehcache.Element;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Properties;
+import java.util.TreeSet;
 
 
 /**
@@ -105,14 +106,13 @@ public class CachingProvider implements WikiPageProvider {
      *  {@inheritDoc}
      */
     @Override
-    public void initialize( WikiEngine engine, Properties properties )
-        throws NoRequiredPropertyException, IOException {
+    public void initialize( final WikiEngine engine, final Properties properties ) throws NoRequiredPropertyException, IOException {
         log.debug("Initing CachingProvider");
 
         // engine is used for getting the search engine
         m_engine = engine;
 
-        String cacheName = engine.getApplicationName() + "." + CACHE_NAME;
+        final String cacheName = engine.getApplicationName() + "." + CACHE_NAME;
         if (m_cacheManager.cacheExists(cacheName)) {
             m_cache = m_cacheManager.getCache(cacheName);
         } else {
@@ -145,8 +145,12 @@ public class CachingProvider implements WikiPageProvider {
         //
         //  Find and initialize real provider.
         //
-        String classname = m_engine.getRequiredProperty( properties, PageManager.PROP_PAGEPROVIDER );
-
+        final String classname;
+        try {
+            classname = TextUtil.getRequiredProperty( properties, PageManager.PROP_PAGEPROVIDER );
+        } catch( final NoSuchElementException e ) {
+            throw new NoRequiredPropertyException( e.getMessage(), PageManager.PROP_PAGEPROVIDER );
+        }
 
         try
         {


[jspwiki] 08/14: move getRequiredProperty from WikiEngine to TextUtil

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 812bfbc470faafca96a766ad0c03bc5440c3e9d7
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 23:23:43 2019 +0100

    move getRequiredProperty from WikiEngine to TextUtil
---
 .../src/main/java/org/apache/wiki/WikiEngine.java  |  18 --
 .../test/java/org/apache/wiki/WikiEngineTest.java  |  21 --
 .../main/java/org/apache/wiki/util/TextUtil.java   |  19 ++
 .../java/org/apache/wiki/util/TextUtilTest.java    | 317 ++++++++-------------
 4 files changed, 134 insertions(+), 241 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 4ab6b73..c7fe788 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -1843,24 +1843,6 @@ public class WikiEngine
     }
 
     /**
-     *  Throws an exception if a property is not found.
-     *
-     *  @param props A set of properties to search the key in.
-     *  @param key   The key to look for.
-     *  @return The required property
-     *
-     *  @throws NoRequiredPropertyException If the search key is not in the property set.
-     *  @since 2.0.26 (on TextUtils, moved To WikiEngine on 2.11.0-M1)
-     */
-    public String getRequiredProperty( Properties props, String key ) throws NoRequiredPropertyException {
-        String value = TextUtil.getStringProperty( props, key, null );
-        if( value == null ) {
-            throw new NoRequiredPropertyException( "Required property not found", key );
-        }
-        return value;
-    }
-
-    /**
      *  Returns the current PageManager which is responsible for storing
      *  and managing WikiPages.
      *
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java b/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
index c5bde8c..6faa84f 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/WikiEngineTest.java
@@ -847,26 +847,5 @@ public class WikiEngineTest
 
         Assertions.assertEquals( TextUtil.normalizePostData( "" ), m_engine.getText( name ), "wrong content" );
     }
-    
-    @Test
-    public void testGetRequiredProperty() throws Exception
-    {
-        String[] vals = { "foo", " this is a property ", "bar", "60" };
-        Properties props = TextUtil.createProperties(vals);
-        Assertions.assertEquals( "60", m_engine.getRequiredProperty( props, "bar" ) );
-    }
-
-    @Test
-    public void testGetRequiredPropertyNRPE()
-    {
-        String[] vals = { "foo", " this is a property ", "bar", "60" };
-        Properties props = TextUtil.createProperties(vals);
-        try
-        {
-            m_engine.getRequiredProperty( props, "ber" );
-            Assertions.fail( "NoRequiredPropertyException should've been thrown!" );
-        }
-        catch (NoRequiredPropertyException nrpe) {}
-    }
 
 }
diff --git a/jspwiki-util/src/main/java/org/apache/wiki/util/TextUtil.java b/jspwiki-util/src/main/java/org/apache/wiki/util/TextUtil.java
index 26c109a..ba46853 100644
--- a/jspwiki-util/src/main/java/org/apache/wiki/util/TextUtil.java
+++ b/jspwiki-util/src/main/java/org/apache/wiki/util/TextUtil.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.security.SecureRandom;
+import java.util.NoSuchElementException;
 import java.util.Properties;
 import java.util.Random;
 
@@ -392,6 +393,24 @@ public final class TextUtil {
     }
 
     /**
+     *  Throws an exception if a property is not found.
+     *
+     *  @param props A set of properties to search the key in.
+     *  @param key   The key to look for.
+     *  @return The required property
+     *
+     *  @throws NoSuchElementException If the search key is not in the property set.
+     *  @since 2.0.26 (on TextUtils, moved To WikiEngine on 2.11.0-M1 and back to TextUtils on 2.11.0-M6)
+     */
+    public static String getRequiredProperty( Properties props, String key ) throws NoSuchElementException {
+        String value = getStringProperty( props, key, null );
+        if( value == null ) {
+            throw new NoSuchElementException( "Required property not found: " + key );
+        }
+        return value;
+    }
+
+    /**
      *  Fetches a file path property from the set of Properties.
      *
      *  Before inspecting the props, we first check if there is a Java System Property with the same name, if it exists
diff --git a/jspwiki-util/src/test/java/org/apache/wiki/util/TextUtilTest.java b/jspwiki-util/src/test/java/org/apache/wiki/util/TextUtilTest.java
index 265e943..f3d6375 100644
--- a/jspwiki-util/src/test/java/org/apache/wiki/util/TextUtilTest.java
+++ b/jspwiki-util/src/test/java/org/apache/wiki/util/TextUtilTest.java
@@ -18,215 +18,167 @@
  */
 package org.apache.wiki.util;
 
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
 import java.io.File;
+import java.util.NoSuchElementException;
 import java.util.Properties;
 
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
 
-public class TextUtilTest
-{
+public class TextUtilTest {
+
     @Test
-    public void testGenerateRandomPassword()
-    {
-        for (int i=0; i<1000; i++) {
+    public void testGenerateRandomPassword() {
+        for( int i = 0; i < 1000; i++ ) {
             Assertions.assertEquals( TextUtil.PASSWORD_LENGTH, TextUtil.generateRandomPassword().length(), "pw" );
         }
     }
 
     @Test
-    public void testEncodeName_1()
-    {
-        String name = "Hello/World";
-
+    public void testEncodeName_1() {
+        final String name = "Hello/World";
         Assertions.assertEquals( "Hello/World", TextUtil.urlEncode(name,"ISO-8859-1") );
     }
 
     @Test
-    public void testEncodeName_2()
-    {
-        String name = "Hello~World";
-
+    public void testEncodeName_2() {
+        final String name = "Hello~World";
         Assertions.assertEquals( "Hello%7EWorld", TextUtil.urlEncode(name,"ISO-8859-1") );
     }
 
     @Test
-    public void testEncodeName_3()
-    {
-        String name = "Hello/World ~";
-
+    public void testEncodeName_3() {
+        final String name = "Hello/World ~";
         Assertions.assertEquals( "Hello/World+%7E", TextUtil.urlEncode(name,"ISO-8859-1") );
     }
 
     @Test
-    public void testDecodeName_1()
-         throws Exception
-    {
-        String name = "Hello/World+%7E+%2F";
-
+    public void testDecodeName_1() {
+        final String name = "Hello/World+%7E+%2F";
         Assertions.assertEquals( "Hello/World ~ /", TextUtil.urlDecode(name,"ISO-8859-1") );
     }
 
     @Test
-    public void testEncodeNameUTF8_1()
-    {
-        String name = "\u0041\u2262\u0391\u002E";
-
+    public void testEncodeNameUTF8_1() {
+        final String name = "\u0041\u2262\u0391\u002E";
         Assertions.assertEquals( "A%E2%89%A2%CE%91.", TextUtil.urlEncodeUTF8(name) );
     }
 
     @Test
-    public void testEncodeNameUTF8_2()
-    {
-        String name = "\uD55C\uAD6D\uC5B4";
-
+    public void testEncodeNameUTF8_2() {
+        final String name = "\uD55C\uAD6D\uC5B4";
         Assertions.assertEquals( "%ED%95%9C%EA%B5%AD%EC%96%B4", TextUtil.urlEncodeUTF8(name) );
     }
 
     @Test
-    public void testEncodeNameUTF8_3()
-    {
-        String name = "\u65E5\u672C\u8A9E";
-
+    public void testEncodeNameUTF8_3() {
+        final String name = "\u65E5\u672C\u8A9E";
         Assertions.assertEquals( "%E6%97%A5%E6%9C%AC%E8%AA%9E", TextUtil.urlEncodeUTF8(name) );
     }
 
     @Test
-    public void testEncodeNameUTF8_4()
-    {
-        String name = "Hello World";
-
+    public void testEncodeNameUTF8_4() {
+        final String name = "Hello World";
         Assertions.assertEquals( "Hello+World", TextUtil.urlEncodeUTF8(name) );
     }
 
     @Test
-    public void testDecodeNameUTF8_1()
-    {
-        String name = "A%E2%89%A2%CE%91.";
-
+    public void testDecodeNameUTF8_1() {
+        final String name = "A%E2%89%A2%CE%91.";
         Assertions.assertEquals( "\u0041\u2262\u0391\u002E", TextUtil.urlDecodeUTF8(name) );
     }
 
     @Test
-    public void testDecodeNameUTF8_2()
-    {
-        String name = "%ED%95%9C%EA%B5%AD%EC%96%B4";
-
+    public void testDecodeNameUTF8_2() {
+        final String name = "%ED%95%9C%EA%B5%AD%EC%96%B4";
         Assertions.assertEquals( "\uD55C\uAD6D\uC5B4", TextUtil.urlDecodeUTF8(name) );
     }
 
     @Test
-    public void testDecodeNameUTF8_3()
-    {
-        String name = "%E6%97%A5%E6%9C%AC%E8%AA%9E";
-
+    public void testDecodeNameUTF8_3() {
+        final String name = "%E6%97%A5%E6%9C%AC%E8%AA%9E";
         Assertions.assertEquals( "\u65E5\u672C\u8A9E", TextUtil.urlDecodeUTF8(name) );
     }
 
     @Test
-    public void testReplaceString1()
-    {
-        String text = "aabacaa";
-
+    public void testReplaceString1() {
+        final String text = "aabacaa";
         Assertions.assertEquals( "ddbacdd", TextUtil.replaceString( text, "aa", "dd" ) );
     }
 
     @Test
-    public void testReplaceString4()
-    {
-        String text = "aabacaafaa";
-
+    public void testReplaceString4() {
+        final String text = "aabacaafaa";
         Assertions.assertEquals( "ddbacddfdd", TextUtil.replaceString( text, "aa", "dd" ) );
     }
 
     @Test
-    public void testReplaceString5()
-    {
-        String text = "aaabacaaafaa";
-
+    public void testReplaceString5() {
+        final String text = "aaabacaaafaa";
         Assertions.assertEquals( "dbacdfaa", TextUtil.replaceString( text, "aaa", "d" ) );
     }
 
     @Test
-    public void testReplaceString2()
-    {
-        String text = "abcde";
-
+    public void testReplaceString2() {
+        final String text = "abcde";
         Assertions.assertEquals( "fbcde", TextUtil.replaceString( text, "a", "f" ) );
     }
 
     @Test
-    public void testReplaceString3()
-    {
-        String text = "ababab";
-
+    public void testReplaceString3() {
+        final String text = "ababab";
         Assertions.assertEquals( "afafaf", TextUtil.replaceString( text, "b", "f" ) );
     }
 
     @Test
-    public void testReplaceStringCaseUnsensitive1()
-    {
-        String text = "aABcAa";
-
+    public void testReplaceStringCaseUnsensitive1() {
+        final String text = "aABcAa";
         Assertions.assertEquals( "ddBcdd", TextUtil.replaceStringCaseUnsensitive( text, "aa", "dd" ) );
     }
 
     @Test
-    public void testReplaceStringCaseUnsensitive2()
-    {
-        String text = "Abcde";
-
+    public void testReplaceStringCaseUnsensitive2() {
+        final String text = "Abcde";
         Assertions.assertEquals( "fbcde", TextUtil.replaceStringCaseUnsensitive( text, "a", "f" ) );
     }
 
     @Test
-    public void testReplaceStringCaseUnsensitive3()
-    {
-        String text = "aBAbab";
-
+    public void testReplaceStringCaseUnsensitive3() {
+        final String text = "aBAbab";
         Assertions.assertEquals( "afAfaf", TextUtil.replaceStringCaseUnsensitive( text, "b", "f" ) );
     }
 
     @Test
-    public void testReplaceStringCaseUnsensitive4()
-    {
-        String text = "AaBAcAAfaa";
-
+    public void testReplaceStringCaseUnsensitive4() {
+        final String text = "AaBAcAAfaa";
         Assertions.assertEquals( "ddBAcddfdd", TextUtil.replaceStringCaseUnsensitive( text, "aa", "dd" ) );
     }
 
     @Test
-    public void testReplaceStringCaseUnsensitive5()
-    {
-        String text = "aAaBaCAAafaa";
-
+    public void testReplaceStringCaseUnsensitive5() {
+        final String text = "aAaBaCAAafaa";
         Assertions.assertEquals( "dBaCdfaa", TextUtil.replaceStringCaseUnsensitive( text, "aaa", "d" ) );
     }
 
     // Pure UNIX.
     @Test
-    public void testNormalizePostdata1()
-    {
-        String text = "ab\ncd";
-
+    public void testNormalizePostdata1() {
+        final String text = "ab\ncd";
         Assertions.assertEquals( "ab\r\ncd\r\n", TextUtil.normalizePostData( text ) );
     }
 
     // Pure MSDOS.
     @Test
-    public void testNormalizePostdata2()
-    {
-        String text = "ab\r\ncd";
-
+    public void testNormalizePostdata2() {
+        final String text = "ab\r\ncd";
         Assertions.assertEquals( "ab\r\ncd\r\n", TextUtil.normalizePostData( text ) );
     }
 
     // Pure Mac
     @Test
-    public void testNormalizePostdata3()
-    {
-        String text = "ab\rcd";
-
+    public void testNormalizePostdata3() {
+        final String text = "ab\rcd";
         Assertions.assertEquals( "ab\r\ncd\r\n", TextUtil.normalizePostData( text ) );
     }
 
@@ -234,43 +186,34 @@ public class TextUtilTest
     @Test
     public void testNormalizePostdata4()
     {
-        String text = "ab\ncd\r\n\r\n\r";
-
+        final String text = "ab\ncd\r\n\r\n\r";
         Assertions.assertEquals( "ab\r\ncd\r\n\r\n\r\n", TextUtil.normalizePostData( text ) );
     }
 
     // Multiple newlines
     @Test
-    public void testNormalizePostdata5()
-    {
-        String text = "ab\ncd\n\n\n\n";
-
+    public void testNormalizePostdata5() {
+        final String text = "ab\ncd\n\n\n\n";
         Assertions.assertEquals( "ab\r\ncd\r\n\r\n\r\n\r\n", TextUtil.normalizePostData( text ) );
     }
 
     // Empty.
     @Test
-    public void testNormalizePostdata6()
-    {
-        String text = "";
-
+    public void testNormalizePostdata6() {
+        final String text = "";
         Assertions.assertEquals( "\r\n", TextUtil.normalizePostData( text ) );
     }
 
     // Just a newline.
     @Test
-    public void testNormalizePostdata7()
-    {
-        String text = "\n";
-
+    public void testNormalizePostdata7() {
+        final String text = "\n";
         Assertions.assertEquals( "\r\n", TextUtil.normalizePostData( text ) );
     }
 
     @Test
-    public void testGetBooleanProperty()
-    {
-        Properties props = new Properties();
-
+    public void testGetBooleanProperty() {
+        final Properties props = new Properties();
         props.setProperty("foobar.0", "YES");
         props.setProperty("foobar.1", "true");
         props.setProperty("foobar.2", "false");
@@ -281,140 +224,110 @@ public class TextUtilTest
 
         Assertions.assertTrue( TextUtil.getBooleanProperty( props, "foobar.0", false ), "foobar.0" );
         Assertions.assertTrue( TextUtil.getBooleanProperty( props, "foobar.1", false ), "foobar.1" );
-
         Assertions.assertFalse( TextUtil.getBooleanProperty( props, "foobar.2", true ), "foobar.2" );
         Assertions.assertFalse( TextUtil.getBooleanProperty( props, "foobar.3", true ), "foobar.3" );
         Assertions.assertTrue( TextUtil.getBooleanProperty( props, "foobar.4", false ), "foobar.4" );
-
         Assertions.assertFalse( TextUtil.getBooleanProperty( props, "foobar.5", true ), "foobar.5" );
-
         Assertions.assertFalse( TextUtil.getBooleanProperty( props, "foobar.6", true ), "foobar.6" );
     }
 
     @Test
-    public void testGetSection1()
-        throws Exception
-    {
-        String src = "Single page.";
+    public void testGetSection1() {
+        final String src = "Single page.";
 
         Assertions.assertEquals( src, TextUtil.getSection(src,1), "section 1" );
-
-        try
-        {
-            TextUtil.getSection( src, 5 );
-            Assertions.fail("Did not get exception for 2");
-        }
-        catch( IllegalArgumentException e ) {}
-
-        try
-        {
-            TextUtil.getSection( src, -1 );
-            Assertions.fail("Did not get exception for -1");
-        }
-        catch( IllegalArgumentException e ) {}
+        Assertions.assertThrows( IllegalArgumentException.class, () -> TextUtil.getSection( src, 5 ) );
+        Assertions.assertThrows( IllegalArgumentException.class, () -> TextUtil.getSection( src, -1 ) );
     }
 
     @Test
-    public void testGetSection2()
-        throws Exception
-    {
-        String src = "First section\n----\nSecond section\n\n----\n\nThird section";
+    public void testGetSection2() {
+        final String src = "First section\n----\nSecond section\n\n----\n\nThird section";
 
         Assertions.assertEquals( "First section\n", TextUtil.getSection(src,1), "section 1" );
         Assertions.assertEquals( "\nSecond section\n\n", TextUtil.getSection(src,2), "section 2" );
         Assertions.assertEquals( "\n\nThird section", TextUtil.getSection(src,3), "section 3" );
-
-        try
-        {
-            TextUtil.getSection( src, 4 );
-            Assertions.fail("Did not get exception for section 4");
-        }
-        catch( IllegalArgumentException e ) {}
+        Assertions.assertThrows( IllegalArgumentException.class, () -> TextUtil.getSection( src, 4 ) );
     }
 
     @Test
-    public void testGetSection3()
-        throws Exception
-    {
-        String src = "----\nSecond section\n----";
-
+    public void testGetSection3() {
+        final String src = "----\nSecond section\n----";
 
         Assertions.assertEquals( "", TextUtil.getSection(src,1), "section 1" );
         Assertions.assertEquals( "\nSecond section\n", TextUtil.getSection(src,2), "section 2" );
         Assertions.assertEquals( "", TextUtil.getSection(src,3), "section 3" );
-
-        try
-        {
-            TextUtil.getSection( src, 4 );
-            Assertions.fail("Did not get exception for section 4");
-        }
-        catch( IllegalArgumentException e ) {}
+        Assertions.assertThrows( IllegalArgumentException.class, () -> TextUtil.getSection( src, 4 ) );
     }
 
     @Test
-    public void testGetSectionWithMoreThanFourDashes() throws Exception
-    {
-        String src = "----------------\nSecond section\n----";
-
+    public void testGetSectionWithMoreThanFourDashes() {
+        final String src = "----------------\nSecond section\n----";
         Assertions.assertEquals( "\nSecond section\n", TextUtil.getSection(src, 2), "section 2" );
     }
 
     @Test
-    public void testBooleanParameter()
-       throws Exception
-    {
-        Assertions.assertEquals( true, TextUtil.isPositive(" true "), "1" );
-        Assertions.assertEquals( false, TextUtil.isPositive(" fewqkfow kfpokwe "), "2" );
-        Assertions.assertEquals( true, TextUtil.isPositive("on"), "3" );
-        Assertions.assertEquals( true, TextUtil.isPositive("\t\ton"), "4" );
+    public void testBooleanParameter() {
+        Assertions.assertTrue( TextUtil.isPositive(" true "), "1" );
+        Assertions.assertFalse( TextUtil.isPositive(" fewqkfow kfpokwe "), "2" );
+        Assertions.assertTrue( TextUtil.isPositive("on"), "3" );
+        Assertions.assertTrue( TextUtil.isPositive("\t\ton"), "4" );
     }
 
     @Test
-    public void testTrimmedProperty()
-    {
-        String[] vals = { "foo", " this is a property ", "bar", "60" };
-
-        Properties props = TextUtil.createProperties(vals);
+    public void testTrimmedProperty() {
+        final String[] vals = { "foo", " this is a property ", "bar", "60" };
+        final Properties props = TextUtil.createProperties(vals);
 
         Assertions.assertEquals( "this is a property", TextUtil.getStringProperty(props,"foo",""), "foo" );
         Assertions.assertEquals( 60, TextUtil.getIntegerProperty(props,"bar",0), "bar" );
     }
 
     @Test
-    public void testGetStringProperty()
-    {
-        String[] vals = { "foo", " this is a property " };
-        Properties props = TextUtil.createProperties(vals);
+    public void testGetStringProperty() {
+        final String[] vals = { "foo", " this is a property " };
+        final Properties props = TextUtil.createProperties(vals);
         Assertions.assertEquals( "this is a property", TextUtil.getStringProperty( props, "foo", "err" ) );
     }
 
     @Test
-    public void testGetStringPropertyDefaultValue()
-    {
-        String defaultValue = System.getProperty( "user.home" ) + File.separator + "jspwiki-files";
-        String[] vals = { "foo", " this is a property " };
-        Properties props = TextUtil.createProperties(vals);
+    public void testGetStringPropertyDefaultValue() {
+        final String defaultValue = System.getProperty( "user.home" ) + File.separator + "jspwiki-files";
+        final String[] vals = { "foo", " this is a property " };
+        final Properties props = TextUtil.createProperties(vals);
         Assertions.assertEquals( defaultValue, TextUtil.getStringProperty( props, "bar", defaultValue ) );
     }
 
     @Test
-    public void testGetCanonicalFilePathProperty()
-    {
-        String[] values = { "jspwiki.fileSystemProvider.pageDir", " ." + File.separator + "data" + File.separator + "private " };
-        Properties props = TextUtil.createProperties(values);
-        String path = TextUtil.getCanonicalFilePathProperty(props, "jspwiki.fileSystemProvider.pageDir", "NA");
+    public void testGetCanonicalFilePathProperty() {
+        final String[] values = { "jspwiki.fileSystemProvider.pageDir", " ." + File.separator + "data" + File.separator + "private " };
+        final Properties props = TextUtil.createProperties(values);
+        final String path = TextUtil.getCanonicalFilePathProperty(props, "jspwiki.fileSystemProvider.pageDir", "NA");
         Assertions.assertTrue( path.endsWith( File.separator + "data" + File.separator + "private" ) );
         Assertions.assertFalse( path.endsWith( "." + File.separator + "data" + File.separator + "private" ) );
     }
 
     @Test
-    public void testGetCanonicalFilePathPropertyDefaultValue()
-    {
-        String defaultValue = System.getProperty( "user.home" ) + File.separator + "jspwiki-files";
-        String[] values = {};
-        Properties props = TextUtil.createProperties(values);
-        String path = TextUtil.getCanonicalFilePathProperty(props, "jspwiki.fileSystemProvider.pageDir", defaultValue);
+    public void testGetCanonicalFilePathPropertyDefaultValue() {
+        final String defaultValue = System.getProperty( "user.home" ) + File.separator + "jspwiki-files";
+        final String[] values = {};
+        final Properties props = TextUtil.createProperties(values);
+        final String path = TextUtil.getCanonicalFilePathProperty(props, "jspwiki.fileSystemProvider.pageDir", defaultValue);
         Assertions.assertTrue(path.endsWith("jspwiki-files"));
     }
 
+    @Test
+    public void testGetRequiredProperty() {
+        final String[] vals = { "foo", " this is a property ", "bar", "60" };
+        final Properties props = TextUtil.createProperties( vals );
+        Assertions.assertEquals( "60", TextUtil.getRequiredProperty( props, "bar" ) );
+    }
+
+    @Test
+    public void testGetRequiredPropertyNSEE() {
+        final String[] vals = { "foo", " this is a property ", "bar", "60" };
+        final Properties props = TextUtil.createProperties(vals);
+        Assertions.assertThrows( NoSuchElementException.class, () -> TextUtil.getRequiredProperty( props, "ber" ) );
+    }
+
 }


[jspwiki] 14/14: 2.11.0-M6-git-05

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 4c517135f1cead730c74fe12250d1e55b2472a0f
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 23:39:50 2019 +0100

    2.11.0-M6-git-05
---
 ChangeLog.md                                         | 20 ++++++++++++++++++++
 .../src/main/java/org/apache/wiki/Release.java       |  2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/ChangeLog.md b/ChangeLog.md
index b8f853c..a040a6e 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -17,6 +17,26 @@ specific language governing permissions and limitations
 under the License.
 -->
 
+**2019-11-01  Juan Pablo Santos (juanpablo AT apache DOT org)**
+
+* _2.11.0-M6-git-05_
+
+* Couple of methods moved out of `WikiEngine`
+    * `safeGetQueryParameter`: moved as an static method on `HttpUtil`; it now requires content encoding as a parameter
+    * `getRequiredProperty`: moved back as an static method to `TextUtil` - it now throws a `NoSuchElementException` (unchecked) instead of `NoRequiredPropertyException` (checked)
+
+* Maven plugins changes
+    * Change javadocs' doclet to [UMLDoclet](https://github.com/talsma-ict/umldoclet), which can be used with JDK >= 9 (see associated note on [`mvn_cheat-sheet.md`](https://github.com/apache/jspwiki/blob/master/mvn_cheat-sheet.md#3-reports-specific) for details)
+    * Set `compilerVersion` to `jdk.version` on jspc-maven-plugin 
+  
+* Dependency updates
+    * Flexmark to 0.50.44
+    * Lucene to 8.3.1
+    * Selenide to 5.5.1
+    * SLF4J to 1.7.29
+    * Tika to 1.23
+    * Tomcat to 8.5.49
+
 **2019-11-05  Juan Pablo Santos (juanpablo AT apache DOT org)**
 
 * _2.11.0-M6-git-04_
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 c74aaad..c2f10c9 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-04";
+    public static final String     BUILD         = "git-05";
 
     /**
      *  This is the generic version string you should use when printing out the version.  It is of


[jspwiki] 03/14: refactor test so that testEngine doesn't get garbage collected - should fix ocassional test failures

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 03192b330f6b3a85dc28d259da5a1ba05d6c6dbc
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 18:34:09 2019 +0100

    refactor test so that testEngine doesn't get garbage collected - should fix ocassional test failures
---
 .../java/org/apache/wiki/ui/PageCommandTest.java   | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/ui/PageCommandTest.java b/jspwiki-main/src/test/java/org/apache/wiki/ui/PageCommandTest.java
index b1ed7d9..a5a7b83 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/ui/PageCommandTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/ui/PageCommandTest.java
@@ -25,27 +25,11 @@ package org.apache.wiki.ui;
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiPage;
 import org.apache.wiki.auth.permissions.PermissionFactory;
-import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 public class PageCommandTest {
 
-    TestEngine     testEngine = TestEngine.build();
-    WikiPage       testPage;
-
-    @BeforeEach
-    public void setUp() throws Exception {
-        testEngine.saveText( "TestPage", "This is a test." );
-        testPage = testEngine.getPage( "TestPage" );
-    }
-
-    @AfterEach
-    public void tearDown() throws Exception {
-        testEngine.deletePage( "TestPage" );
-    }
-
     @Test
     public void testStaticCommand() {
         Command a = PageCommand.VIEW;
@@ -77,7 +61,11 @@ public class PageCommandTest {
     }
 
     @Test
-    public void testTargetedCommand() {
+    public void testTargetedCommand() throws Exception {
+        final TestEngine testEngine = TestEngine.build();
+        testEngine.saveText( "TestPage", "This is a test." );
+        final WikiPage testPage = testEngine.getPage( "TestPage" );
+
         // Get view command
         Command a = PageCommand.VIEW;
 


[jspwiki] 04/14: Maven plugins changes + dependency updates

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 afa00357f68d337b21d81c32d52ce41bd1d48d84
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 18:38:30 2019 +0100

    Maven plugins changes + dependency updates
    
    * Change javadocs' doclet to UMLDoclet, which can be used with JDK >= 9
    * Set compilerVersion to jdk.version on jspc-maven-plugin
    * Flexmark updated to 0.50.44
    * Lucene updated to 8.3.1
    * Selenide updated to 5.5.1
    * SLF4J updated to 1.7.29
    * Tomcat updated to 8.5.49
---
 pom.xml | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7f6e968..d669f28 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,6 +40,7 @@
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <jdk.version>1.8</jdk.version>
+    <jdk.javadoc.doclet.version>1.1.4</jdk.javadoc.doclet.version>
     <maven.version>3.5</maven.version>
 
     <akismet-java.version>1.02</akismet-java.version>
@@ -50,7 +51,7 @@
     <commons-lang.version>3.9</commons-lang.version>
     <commons-text.version>1.8</commons-text.version>
     <ehcache.version>2.10.6</ehcache.version>
-    <flexmark.version>0.50.42</flexmark.version>
+    <flexmark.version>0.50.44</flexmark.version>
     <freshcookies-security.version>0.60</freshcookies-security.version>
     <gson.version>2.8.5</gson.version>
     <hsqldb.version>2.5.0</hsqldb.version>
@@ -64,15 +65,15 @@
     <jrcs-diff.version>0.4.2</jrcs-diff.version>
     <junit.version>5.5.2</junit.version>
     <log4j.version>1.2.17</log4j.version>
-    <lucene.version>8.2.0</lucene.version>
+    <lucene.version>8.3.1</lucene.version>
     <nekohtml.version>1.9.22</nekohtml.version>
     <oro.version>2.0.8</oro.version>
     <sandler.version>0.5</sandler.version>
-    <selenide.version>5.5.0</selenide.version>
-    <slf4j.version>1.7.28</slf4j.version>
+    <selenide.version>5.5.1</selenide.version>
+    <slf4j.version>1.7.29</slf4j.version>
     <stripes.version>1.7.0-async-beta</stripes.version>
     <tika.version>1.22</tika.version>
-    <tomcat.version>8.5.47</tomcat.version>
+    <tomcat.version>8.5.49</tomcat.version>
     <wro4j.version>1.8.0</wro4j.version>
     <xmlrpc.version>2.0.1</xmlrpc.version>
 
@@ -481,19 +482,16 @@
           <artifactId>maven-javadoc-plugin</artifactId>
           <version>${plugin.javadoc.version}</version>
           <configuration>
-            <additionalOptions>
-              <additionalOption>-sourceclasspath ${project.build.outputDirectory}</additionalOption>
-              <additionalOption>-Xdoclint:none</additionalOption>
-            </additionalOptions>
             <author>${project.organization.name}</author>
             <bottom>Copyright © {inceptionYear}-{currentYear} ${project.organization.name}. All rights reserved.</bottom>
             <breakiterator>true</breakiterator>
-            <doclet>org.jboss.apiviz.APIviz</doclet>
+            <doclet>nl.talsmasoftware.umldoclet.UMLDoclet</doclet>
             <docletArtifact>
-              <groupId>com.grahamedgecombe.apiviz</groupId>
-              <artifactId>apiviz</artifactId>
-              <version>1.3.4</version>
+              <groupId>nl.talsmasoftware</groupId>
+              <artifactId>umldoclet</artifactId>
+              <version>${jdk.javadoc.doclet.version}</version>
             </docletArtifact>
+            <doclint>none</doclint>
             <linksource>true</linksource>
             <sourcetab>4</sourcetab>
             <quiet>true</quiet>
@@ -604,6 +602,7 @@
           <artifactId>jspc-maven-plugin</artifactId>
           <version>${plugin.jspc.version}</version>
           <configuration>
+            <compilerVersion>${jdk.version}</compilerVersion>
             <generatedClasses>${project.build.directory}/ignore</generatedClasses> <!-- only check JSPs are well-formed -->
             <keepSources>true</keepSources>
             <stopAtFirstError>false</stopAtFirstError>


[jspwiki] 02/14: remove unnecessary log4j configuration on test

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 886a664d84e591e9390e408f16ed6bb3aca57b53
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 18:31:56 2019 +0100

    remove unnecessary log4j configuration on test
---
 .../test/java/org/apache/wiki/auth/user/UserProfileTest.java   | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/auth/user/UserProfileTest.java b/jspwiki-main/src/test/java/org/apache/wiki/auth/user/UserProfileTest.java
index 9bba029..f17c0ef 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/auth/user/UserProfileTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/auth/user/UserProfileTest.java
@@ -17,16 +17,14 @@
     under the License.
  */
 package org.apache.wiki.auth.user;
-import java.util.Date;
-import java.util.Properties;
-
-import org.apache.log4j.PropertyConfigurator;
 import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiEngine;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import java.util.Date;
+
 /**
  *  Tests the DefaultUserProfile class.
  */
@@ -38,9 +36,7 @@ public class UserProfileTest
     public void setUp()
         throws Exception
     {
-            Properties props = TestEngine.getTestProperties();
-            PropertyConfigurator.configure(props);
-            WikiEngine engine  = new TestEngine(props);
+            WikiEngine engine  = new TestEngine();
             m_db = engine.getUserManager().getUserDatabase();
     }
 


[jspwiki] 06/14: move safeGetQueryParameter from WikiEngine to HttpUtil

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 bb06b042a2bef7349d114fdc10a43d0166a1f5d6
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 22:04:00 2019 +0100

    move safeGetQueryParameter from WikiEngine to HttpUtil
---
 .../src/main/java/org/apache/wiki/WikiEngine.java  | 38 +-------------------
 .../main/java/org/apache/wiki/util/HttpUtil.java   | 40 ++++++++++++++++++++--
 2 files changed, 39 insertions(+), 39 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 b34386c..4ab6b73 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiEngine.java
@@ -864,48 +864,12 @@ public class WikiEngine
     }
 
     /**
-     *  Returns the query string (the portion after the question mark).
-     *
-     *  @param request The HTTP request to parse.
-     *  @return The query string.  If the query string is null,
-     *          returns an empty string.
-     *
-     *  @since 2.1.3
-     */
-    public String safeGetQueryString( final HttpServletRequest request ) {
-        if (request == null) {
-            return "";
-        }
-
-        String res = request.getQueryString();
-        if( res != null ) {
-            res = new String( res.getBytes( StandardCharsets.ISO_8859_1 ), getContentEncoding() );
-
-            //
-            // Ensure that the 'page=xyz' attribute is removed
-            // FIXME: Is it really the mandate of this routine to do that?
-            //
-            final int pos1 = res.indexOf("page=");
-            if( pos1 >= 0 ) {
-                String tmpRes = res.substring( 0, pos1 );
-                final int pos2 = res.indexOf( "&",pos1 ) + 1;
-                if ( ( pos2 > 0 ) && ( pos2 < res.length() ) ) {
-                    tmpRes = tmpRes + res.substring(pos2);
-                }
-                res = tmpRes;
-            }
-        }
-
-        return res;
-    }
-
-    /**
      *  Returns an URL to some other Wiki that we know.
      *
      *  @param  wikiName The name of the other wiki.
      *  @return null, if no such reference was found.
      */
-    public String getInterWikiURL( String wikiName )
+    public String getInterWikiURL( final String wikiName )
     {
         return TextUtil.getStringProperty(m_properties,PROP_INTERWIKIREF+wikiName,null);
     }
diff --git a/jspwiki-util/src/main/java/org/apache/wiki/util/HttpUtil.java b/jspwiki-util/src/main/java/org/apache/wiki/util/HttpUtil.java
index cead919..3cd7f5d 100644
--- a/jspwiki-util/src/main/java/org/apache/wiki/util/HttpUtil.java
+++ b/jspwiki-util/src/main/java/org/apache/wiki/util/HttpUtil.java
@@ -23,6 +23,8 @@ import org.apache.log4j.Logger;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -65,7 +67,6 @@ public final class HttpUtil {
      *  @param cookieName The name of the cookie to fetch.
      *  @return Value of the cookie, or null, if there is no such cookie.
      */
-
     public static String retrieveCookieValue( HttpServletRequest request, String cookieName ) {
         Cookie[] cookies = request.getCookies();
 
@@ -194,8 +195,43 @@ public final class HttpUtil {
         return uri;
     }
 
-	static boolean notBeginningWithHttpOrHttps( String uri ) {
+	static boolean notBeginningWithHttpOrHttps( final String uri ) {
 		return uri.length() > 0 && !( ( uri.startsWith("http://" ) || uri.startsWith( "https://" ) ) );
 	}
 
+    /**
+     *  Returns the query string (the portion after the question mark).
+     *
+     *  @param request The HTTP request to parse.
+     *  @return The query string. If the query string is null, returns an empty string.
+     *
+     *  @since 2.1.3 (method moved from WikiEngine on 2.11.0.M6)
+     */
+    public static String safeGetQueryString( final HttpServletRequest request, final Charset contentEncoding ) {
+        if( request == null ) {
+            return "";
+        }
+
+        String res = request.getQueryString();
+        if( res != null ) {
+            res = new String( res.getBytes( StandardCharsets.ISO_8859_1 ), contentEncoding );
+
+            //
+            // Ensure that the 'page=xyz' attribute is removed
+            // FIXME: Is it really the mandate of this routine to do that?
+            //
+            final int pos1 = res.indexOf("page=");
+            if( pos1 >= 0 ) {
+                String tmpRes = res.substring( 0, pos1 );
+                final int pos2 = res.indexOf( "&",pos1 ) + 1;
+                if ( ( pos2 > 0 ) && ( pos2 < res.length() ) ) {
+                    tmpRes = tmpRes + res.substring(pos2);
+                }
+                res = tmpRes;
+            }
+        }
+
+        return res;
+    }
+
 }


[jspwiki] 09/14: format interface

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 ef5fb049818b7d3fcd9ace54a67ec177b65ff554
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 23:25:08 2019 +0100

    format interface
---
 jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java
index ae3460c..d9e6f45 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiProvider.java
@@ -18,11 +18,11 @@
  */
 package org.apache.wiki;
 
-import java.util.Properties;
-import java.io.IOException;
-
 import org.apache.wiki.api.exceptions.NoRequiredPropertyException;
 
+import java.io.IOException;
+import java.util.Properties;
+
 
 /**
  *  A generic Wiki provider for all sorts of things that the Wiki can
@@ -45,9 +45,7 @@ public interface WikiProvider
      *  @throws NoRequiredPropertyException If the provider needs a property which is not found in the property set
      *  @throws IOException If there is an IO problem
      */
-    void initialize( WikiEngine engine, Properties properties )
-        throws NoRequiredPropertyException,
-               IOException;
+    void initialize( WikiEngine engine, Properties properties ) throws NoRequiredPropertyException, IOException;
 
     /**
      *  Return a valid HTML string for information.  May be anything.


[jspwiki] 07/14: use safeGetQueryParameter from HttpUtil, remove one superfluous if condition + remove other warnings noted by IntelliJ

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 5826e995c7d57680cb3fa71e163ffb4d0009316e
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 22:05:32 2019 +0100

    use safeGetQueryParameter from HttpUtil, remove one superfluous if condition + remove other warnings noted by IntelliJ
---
 .../java/org/apache/wiki/tags/CalendarTag.java     | 213 ++++++++-------------
 1 file changed, 83 insertions(+), 130 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/CalendarTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/CalendarTag.java
index cd09f14..f8f19ae 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/CalendarTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/CalendarTag.java
@@ -18,22 +18,21 @@
  */
 package org.apache.wiki.tags;
 
-import java.io.IOException;
-import java.util.Calendar;
-import java.util.Date;
-import java.text.SimpleDateFormat;
-import java.text.ParseException;
-
-import javax.servlet.jsp.JspWriter;
-import javax.servlet.http.HttpServletRequest;
-
 import org.apache.log4j.Logger;
+import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiPage;
-import org.apache.wiki.WikiContext;
-import org.apache.wiki.api.exceptions.ProviderException;
+import org.apache.wiki.util.HttpUtil;
 import org.apache.wiki.util.TextUtil;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspWriter;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
 
 /**
  *  Provides a nice calendar.  Responds to the following HTTP parameters:
@@ -48,7 +47,6 @@ import org.apache.wiki.util.TextUtil;
  *  If neither calendar.date nor weblog.startDate parameters exist,
  *  then the calendar will default to the current month.
  *
- *
  *  @since 2.0
  */
 
@@ -97,9 +95,9 @@ public class CalendarTag extends WikiTagBase {
      *  @see SimpleDateFormat
      *  @see org.apache.wiki.plugin.WeblogPlugin
      */
-    public void setPageformat( String format )
+    public void setPageformat( final String format )
     {
-        m_pageFormat = new SimpleDateFormat(format);
+        m_pageFormat = new SimpleDateFormat( format );
     }
 
     /**
@@ -110,9 +108,9 @@ public class CalendarTag extends WikiTagBase {
      *  @param format The URL format in the SimpleDateFormat fashion.
      *  @see SimpleDateFormat
      */
-    public void setUrlformat( String format )
+    public void setUrlformat( final String format )
     {
-        m_urlFormat = new SimpleDateFormat(format);
+        m_urlFormat = new SimpleDateFormat( format );
     }
 
     /**
@@ -122,17 +120,14 @@ public class CalendarTag extends WikiTagBase {
      *  
      *  @see SimpleDateFormat
      */
-    public void setMonthurlformat( String format )
+    public void setMonthurlformat( final String format )
     {
         m_monthUrlFormat = new SimpleDateFormat( format );
     }
 
-    private String format( String txt )
-    {
-        WikiPage p = m_wikiContext.getPage();
-
-        if( p != null )
-        {
+    private String format( final String txt ) {
+        final WikiPage p = m_wikiContext.getPage();
+        if( p != null ) {
             return TextUtil.replaceString( txt, "%p", p.getName() );
         }
 
@@ -142,167 +137,131 @@ public class CalendarTag extends WikiTagBase {
     /**
      *  Returns a link to the given day.
      */
-    private String getDayLink( Calendar day )
-    {
-        WikiEngine engine = m_wikiContext.getEngine();
-        String result = "";
+    private String getDayLink( final Calendar day ) {
+        final WikiEngine engine = m_wikiContext.getEngine();
+        final String result;
 
-        if( m_pageFormat != null )
-        {
-            String pagename = m_pageFormat.format( day.getTime() );
+        if( m_pageFormat != null ) {
+            final String pagename = m_pageFormat.format( day.getTime() );
             
-            if( engine.pageExists( pagename ) )
-            {
-                if( m_urlFormat != null )
-                {
-                    String url = m_urlFormat.format( day.getTime() );
-
+            if( engine.pageExists( pagename ) ) {
+                if( m_urlFormat != null ) {
+                    final String url = m_urlFormat.format( day.getTime() );
                     result = "<td class=\"link\"><a href=\""+url+"\">"+day.get( Calendar.DATE )+"</a></td>";
-                }
-                else
-                {
+                } else {
                     result = "<td class=\"link\"><a href=\""+m_wikiContext.getViewURL( pagename )+"\">"+
                              day.get( Calendar.DATE )+"</a></td>";
                 }
-            }
-            else
-            {
+            } else {
                 result = "<td class=\"days\">"+day.get(Calendar.DATE)+"</td>";
             }
-        }
-        else if( m_urlFormat != null )
-        {
-            String url = m_urlFormat.format( day.getTime() );
-
+        } else if( m_urlFormat != null ) {
+            final String url = m_urlFormat.format( day.getTime() );
             result = "<td><a href=\""+url+"\">"+day.get( Calendar.DATE )+"</a></td>";
-        }
-        else
-        {
+        } else {
             result = "<td class=\"days\">"+day.get(Calendar.DATE)+"</td>";
         }
 
-        return format(result);
+        return format( result );
     }
 
-    private String getMonthLink( Calendar day )
-    {
-        SimpleDateFormat monthfmt = new SimpleDateFormat( "MMMM yyyy" );
-        String result;
+    private String getMonthLink( final Calendar day ) {
+        final SimpleDateFormat monthfmt = new SimpleDateFormat( "MMMM yyyy" );
+        final String result;
 
-        if( m_monthUrlFormat == null )
-        {
+        if( m_monthUrlFormat == null ) {
             result = monthfmt.format( day.getTime() );
-        }
-        else
-        {
-            Calendar cal = (Calendar)day.clone();
-            int firstDay = cal.getActualMinimum( Calendar.DATE );
-            int lastDay  = cal.getActualMaximum( Calendar.DATE );
+        } else {
+            final Calendar cal = (Calendar)day.clone();
+            final int firstDay = cal.getActualMinimum( Calendar.DATE );
+            final int lastDay  = cal.getActualMaximum( Calendar.DATE );
 
             cal.set( Calendar.DATE, lastDay );
             String url = m_monthUrlFormat.format( cal.getTime() );
 
-            url = TextUtil.replaceString( url, "%d", Integer.toString( lastDay-firstDay+1 ) );
+            url = TextUtil.replaceString( url, "%d", Integer.toString( lastDay - firstDay + 1 ) );
 
             result = "<a href=\""+url+"\">"+monthfmt.format(cal.getTime())+"</a>";
         }
 
-        return format(result);
-        
+        return format( result );
     }
-    private String getMonthNaviLink( Calendar day, String txt, String queryString )
-    {
-        String result = "";
+
+    private String getMonthNaviLink( final Calendar day, final String txt, String queryString ) {
+        final String result;
         queryString = TextUtil.replaceEntities( queryString );
-        Calendar nextMonth = Calendar.getInstance();
+        final Calendar nextMonth = Calendar.getInstance();
         nextMonth.set( Calendar.DATE, 1 );  
         nextMonth.add( Calendar.DATE, -1);
         nextMonth.add( Calendar.MONTH, 1 ); // Now move to 1st day of next month
 
-        if ( day.before(nextMonth) )
-        {
-            WikiPage thePage = m_wikiContext.getPage();
-            String pageName = thePage.getName();
+        if ( day.before( nextMonth ) ) {
+            final WikiPage thePage = m_wikiContext.getPage();
+            final String pageName = thePage.getName();
 
-            String calendarDate = m_dateFormat.format(day.getTime());
-            String url = m_wikiContext.getURL( WikiContext.VIEW, pageName, 
-                                               "calendar.date="+calendarDate );
+            final String calendarDate = m_dateFormat.format( day.getTime() );
+            String url = m_wikiContext.getURL( WikiContext.VIEW, pageName,"calendar.date="+calendarDate );
 
-            if ( (queryString != null) && (queryString.length() > 0) )
-            {
+            if( queryString != null && queryString.length() > 0 ) {
                 //
-                // Ensure that the 'calendar.date=ddMMyy' has been removed 
-                // from the queryString
+                // Ensure that the 'calendar.date=ddMMyy' has been removed from the queryString
                 //
 
                 // FIXME: Might be useful to have an entire library of 
                 //        routines for this.  Will fail if it's not calendar.date 
                 //        but something else.
 
-                int pos1 = queryString.indexOf("calendar.date=");
-                if (pos1 >= 0)
-                {
-                    String tmp = queryString.substring(0,pos1);
+                final int pos1 = queryString.indexOf("calendar.date=");
+                if( pos1 >= 0 ) {
+                    String tmp = queryString.substring( 0, pos1 );
                     // FIXME: Will this fail when we use & instead of &amp?
                     // FIXME: should use some parsing routine
-                    int pos2 = queryString.indexOf("&",pos1) + 1;
-                    if ( (pos2 > 0) && (pos2 < queryString.length()) )
-                    {
+                    final int pos2 = queryString.indexOf("&", pos1 ) + 1;
+                    if ( ( pos2 > 0 ) && ( pos2 < queryString.length() ) ) {
                         tmp = tmp + queryString.substring(pos2);
                     }
                     queryString = tmp;
                 }
 
-                if( queryString != null && queryString.length() > 0 )
-                {
-                    url = url + "&amp;"+queryString;
+                if( queryString.length() > 0 ) {
+                    url = url + "&amp;" + queryString;
                 }
             }
             result = "<td><a href=\""+url+"\">"+txt+"</a></td>";
-        }
-        else
-        {
+        } else {
             result="<td> </td>";
         }    
 
-        return format(result);
+        return format( result );
     }
 
     /**
      *  {@inheritDoc}
      */
     @Override
-    public final int doWikiStartTag()
-        throws IOException,
-               ProviderException
-    {
-        WikiEngine       engine   = m_wikiContext.getEngine();
-        JspWriter        out      = pageContext.getOut();
-        Calendar         cal      = Calendar.getInstance();
-        Calendar         prevCal  = Calendar.getInstance();
-        Calendar         nextCal  = Calendar.getInstance();
+    public final int doWikiStartTag() throws IOException {
+        final WikiEngine engine = m_wikiContext.getEngine();
+        final JspWriter out = pageContext.getOut();
+        final Calendar cal = Calendar.getInstance();
+        final Calendar prevCal = Calendar.getInstance();
+        final Calendar nextCal = Calendar.getInstance();
 
         //
         //  Check if there is a parameter in the request to set the date.
         //
         String calendarDate = pageContext.getRequest().getParameter( "calendar.date" );
-        if( calendarDate == null )
-        {
+        if( calendarDate == null ) {
             calendarDate = pageContext.getRequest().getParameter( "weblog.startDate" );
         }
         
-        if( calendarDate != null )
-        {
-            try
-            {
-                Date d = m_dateFormat.parse( calendarDate );
+        if( calendarDate != null ) {
+            try {
+                final Date d = m_dateFormat.parse( calendarDate );
                 cal.setTime( d );
                 prevCal.setTime( d );
                 nextCal.setTime( d );
-            }
-            catch( ParseException e )
-            {
-                log.warn( "date format wrong: "+calendarDate );
+            } catch( final ParseException e ) {
+                log.warn( "date format wrong: " + calendarDate );
             }
         }
 
@@ -315,8 +274,8 @@ public class CalendarTag extends WikiTagBase {
 
         out.write( "<table class=\"calendar\">\n" );
 
-        HttpServletRequest httpServletRequest = m_wikiContext.getHttpRequest();
-        String queryString = engine.safeGetQueryString( httpServletRequest );
+        final HttpServletRequest httpServletRequest = m_wikiContext.getHttpRequest();
+        final String queryString = HttpUtil.safeGetQueryString( httpServletRequest, engine.getContentEncoding() );
         out.write( "<tr>"+
                    getMonthNaviLink(prevCal,"&lt;&lt;", queryString)+
                    "<td colspan=5 class=\"month\">"+
@@ -326,7 +285,7 @@ public class CalendarTag extends WikiTagBase {
                    "</tr>\n"
                  );
 
-        int month = cal.get( Calendar.MONTH );
+        final int month = cal.get( Calendar.MONTH );
         cal.set( Calendar.DAY_OF_WEEK, Calendar.MONDAY ); // Then, find the first day of the week.
 
         out.write( "<tr><td class=\"weekdays\">Mon</td>"+
@@ -338,28 +297,22 @@ public class CalendarTag extends WikiTagBase {
                    "<td class=\"weekdays\">Sun</td></tr>\n" );
 
         boolean noMoreDates = false;
-        while( !noMoreDates )
-        {
+        while( !noMoreDates ) {
             out.write( "<tr>" );
             
-            for( int i = 0; i < 7; i++ )
-            {
-                int mth = cal.get( Calendar.MONTH );
+            for( int i = 0; i < 7; i++ ) {
+                final int mth = cal.get( Calendar.MONTH );
 
-                if( mth != month )
-                {
+                if( mth != month ) {
                     out.write("<td class=\"othermonth\">"+cal.get(Calendar.DATE)+"</td>");
-                }
-                else
-                {
+                } else {
                     out.write( getDayLink(cal) );
                 }
 
                 cal.add( Calendar.DATE, 1 );
             }
 
-            if( cal.get( Calendar.MONTH ) != month )
-            {
+            if( cal.get( Calendar.MONTH ) != month ) {
                 noMoreDates = true;
             }
 


[jspwiki] 13/14: update Tika to 1.23

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 c087db69b470efc95a9a60e7391b3af4f906fe48
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 23:39:09 2019 +0100

    update Tika to 1.23
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index d669f28..5fc0143 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,7 +72,7 @@
     <selenide.version>5.5.1</selenide.version>
     <slf4j.version>1.7.29</slf4j.version>
     <stripes.version>1.7.0-async-beta</stripes.version>
-    <tika.version>1.22</tika.version>
+    <tika.version>1.23</tika.version>
     <tomcat.version>8.5.49</tomcat.version>
     <wro4j.version>1.8.0</wro4j.version>
     <xmlrpc.version>2.0.1</xmlrpc.version>


[jspwiki] 01/14: remove unneeded throws Exception from tests

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 8f8a98c21ca2015e00af4b0ac1ec0f8bfc9c3187
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 18:31:21 2019 +0100

    remove unneeded throws Exception from tests
---
 .../src/main/java/org/apache/wiki/its/AnonymousViewIT.java  | 13 ++++++-------
 .../src/main/java/org/apache/wiki/its/LoginIT.java          |  4 ++--
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/AnonymousViewIT.java b/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/AnonymousViewIT.java
index 5a7fcee..1188ed6 100644
--- a/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/AnonymousViewIT.java
+++ b/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/AnonymousViewIT.java
@@ -18,18 +18,17 @@
  */
 package org.apache.wiki.its;
 
-import static com.codeborne.selenide.Condition.exist;
-import static com.codeborne.selenide.Condition.not;
-
-import java.io.File;
-
+import com.codeborne.selenide.junit5.ScreenShooterExtension;
 import org.apache.wiki.pages.Page;
 import org.apache.wiki.pages.haddock.ReadWikiPage;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 
-import com.codeborne.selenide.junit5.ScreenShooterExtension;
+import java.io.File;
+
+import static com.codeborne.selenide.Condition.exist;
+import static com.codeborne.selenide.Condition.not;
 
 
 /**
@@ -39,7 +38,7 @@ import com.codeborne.selenide.junit5.ScreenShooterExtension;
 public class AnonymousViewIT {
     
     @Test
-    void anonymousView() throws Exception {
+    void anonymousView() {
         ReadWikiPage main = Page.withUrl( Page.baseUrl() + "/Wiki.jsp?page=Main" ).openAs( new ReadWikiPage() );
         Assertions.assertEquals( "JSPWiki: Main", main.title() );
         Assertions.assertEquals( "Main", main.wikiTitle() );
diff --git a/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/LoginIT.java b/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/LoginIT.java
index 24e9ba0..4ecb8ae 100644
--- a/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/LoginIT.java
+++ b/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/LoginIT.java
@@ -35,7 +35,7 @@ import com.codeborne.selenide.junit5.ScreenShooterExtension;
 public class LoginIT {
     
     @Test
-    void loginAndLogout() throws Exception {
+    void loginAndLogout() {
         ReadWikiPage main = Page.withUrl( Page.baseUrl() + "/Wiki.jsp?page=Main" ).openAs( new ReadWikiPage() );
         Assertions.assertEquals( "JSPWiki: Main", main.title() );
         Assertions.assertEquals( "Main", main.wikiTitle() );
@@ -54,7 +54,7 @@ public class LoginIT {
     }
     
     @Test
-    void loginKO() throws Exception {
+    void loginKO() {
         ReadWikiPage main = Page.withUrl( Page.baseUrl() + "/Wiki.jsp?page=Main" ).openAs( new ReadWikiPage() );
         Assertions.assertEquals( "JSPWiki: Main", main.title() );
         Assertions.assertEquals( "Main", main.wikiTitle() );


[jspwiki] 12/14: use method from TextUtil

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 950a64c24c356f5c1b1eefec63f0f22943b3702e
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 23:28:58 2019 +0100

    use method from TextUtil
---
 jspwiki-war/src/main/webapp/rss.jsp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/jspwiki-war/src/main/webapp/rss.jsp b/jspwiki-war/src/main/webapp/rss.jsp
index 19e0e3a..088f329 100644
--- a/jspwiki-war/src/main/webapp/rss.jsp
+++ b/jspwiki-war/src/main/webapp/rss.jsp
@@ -90,8 +90,8 @@
     SimpleDateFormat iso8601fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
 
     Properties properties = wiki.getWikiProperties();
-    String channelDescription = wiki.getRequiredProperty( properties, RSSGenerator.PROP_CHANNEL_DESCRIPTION );
-    String channelLanguage    = wiki.getRequiredProperty( properties, RSSGenerator.PROP_CHANNEL_LANGUAGE );
+    String channelDescription = TextUtil.getRequiredProperty( properties, RSSGenerator.PROP_CHANNEL_DESCRIPTION );
+    String channelLanguage    = TextUtil.getRequiredProperty( properties, RSSGenerator.PROP_CHANNEL_LANGUAGE );
 
     //
     //  Now, list items.


[jspwiki] 10/14: fix javadocs on DummyUserDatabase + add format + fix some warnings reported by IntelliJ

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 d169b5085f36ea0cc848ef8ea5b225395141468f
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 23:26:17 2019 +0100

    fix javadocs on DummyUserDatabase + add format + fix some warnings reported by IntelliJ
---
 .../java/org/apache/wiki/auth/UserManager.java     | 165 ++++++++-------------
 1 file changed, 58 insertions(+), 107 deletions(-)

diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/UserManager.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/UserManager.java
index 230094d..5d51ec4 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/auth/UserManager.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/UserManager.java
@@ -44,6 +44,7 @@ import org.apache.wiki.i18n.InternationalizationManager;
 import org.apache.wiki.preferences.Preferences;
 import org.apache.wiki.ui.InputValidator;
 import org.apache.wiki.util.ClassUtil;
+import org.apache.wiki.util.TextUtil;
 import org.apache.wiki.workflow.Decision;
 import org.apache.wiki.workflow.DecisionRequiredException;
 import org.apache.wiki.workflow.Fact;
@@ -61,6 +62,7 @@ import java.security.Principal;
 import java.text.MessageFormat;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Properties;
 import java.util.ResourceBundle;
 import java.util.WeakHashMap;
@@ -102,8 +104,7 @@ public class UserManager {
      * @param engine the current wiki engine
      * @param props the wiki engine initialization properties
      */
-    public void initialize( WikiEngine engine, Properties props )
-    {
+    public void initialize( final WikiEngine engine, final Properties props ) {
         m_engine = engine;
 
         // Attach the PageManager as a listener
@@ -115,57 +116,40 @@ public class UserManager {
     }
 
     /**
-     * Returns the UserDatabase employed by this WikiEngine. The UserDatabase is
-     * lazily initialized by this method, if it does not exist yet. If the
-     * initialization fails, this method will use the inner class
-     * DummyUserDatabase as a default (which is enough to get JSPWiki running).
+     * Returns the UserDatabase employed by this WikiEngine. The UserDatabase is lazily initialized by this method, if it does
+     * not exist yet. If the initialization fails, this method will use the inner class DummyUserDatabase as a default (which
+     * is enough to get JSPWiki running).
+     *
      * @return the dummy user database
      * @since 2.3
      */
-    public UserDatabase getUserDatabase()
-    {
-        // FIXME: Must not throw RuntimeException, but something else.
-        if( m_database != null )
-        {
+    public UserDatabase getUserDatabase() {
+        if( m_database != null ) {
             return m_database;
         }
 
         String dbClassName = UNKNOWN_CLASS;
 
-        try
-        {
-            dbClassName = m_engine.getRequiredProperty( m_engine.getWikiProperties(), PROP_DATABASE );
+        try {
+            dbClassName = TextUtil.getRequiredProperty( m_engine.getWikiProperties(), PROP_DATABASE );
 
-            log.info("Attempting to load user database class "+dbClassName);
+            log.info( "Attempting to load user database class " + dbClassName );
             final Class<?> dbClass = ClassUtil.findClass( USERDATABASE_PACKAGE, dbClassName );
             m_database = (UserDatabase) dbClass.newInstance();
             m_database.initialize( m_engine, m_engine.getWikiProperties() );
             log.info("UserDatabase initialized.");
-        }
-        catch( final NoRequiredPropertyException e )
-        {
+        } catch( final NoSuchElementException | NoRequiredPropertyException e ) {
             log.error( "You have not set the '"+PROP_DATABASE+"'. You need to do this if you want to enable user management by JSPWiki.", e );
-        }
-        catch( final ClassNotFoundException e )
-        {
+        } catch( final ClassNotFoundException e ) {
             log.error( "UserDatabase class " + dbClassName + " cannot be found", e );
-        }
-        catch( final InstantiationException e )
-        {
+        } catch( final InstantiationException e ) {
             log.error( "UserDatabase class " + dbClassName + " cannot be created", e );
-        }
-        catch( final IllegalAccessException e )
-        {
+        } catch( final IllegalAccessException e ) {
             log.error( "You are not allowed to access this user database class", e );
-        }
-        catch( final WikiSecurityException e )
-        {
+        } catch( final WikiSecurityException e ) {
             log.error( "Exception initializing user database: " + e.getMessage(), e );
-        }
-        finally
-        {
-            if( m_database == null )
-            {
+        } finally {
+            if( m_database == null ) {
                 log.info("I could not create a database object you specified (or didn't specify), so I am falling back to a default.");
                 m_database = new DummyUserDatabase();
             }
@@ -197,38 +181,28 @@ public class UserManager {
      * is anonymous or asserted, or if the user cannot be found in the user
      * database
      */
-    public UserProfile getUserProfile( WikiSession session )
-    {
+    public UserProfile getUserProfile( final WikiSession session ) {
         // Look up cached user profile
         UserProfile profile = m_profiles.get( session );
         boolean newProfile = profile == null;
         Principal user = null;
 
         // If user is authenticated, figure out if this is an existing profile
-        if ( session.isAuthenticated() )
-        {
+        if ( session.isAuthenticated() ) {
             user = session.getUserPrincipal();
-            try
-            {
+            try {
                 profile = getUserDatabase().find( user.getName() );
                 newProfile = false;
-            }
-            catch( final NoSuchPrincipalException e )
-            {
-            }
+            } catch( final NoSuchPrincipalException e ) { }
         }
 
-        if ( newProfile )
-        {
+        if ( newProfile ) {
             profile = getUserDatabase().newProfile();
-            if ( user != null )
-            {
+            if ( user != null ) {
                 profile.setLoginName( user.getName() );
             }
-            if ( !profile.isNew() )
-            {
-                throw new IllegalStateException(
-                        "New profile should be marked 'new'. Check your UserProfile implementation." );
+            if ( !profile.isNew() ) {
+                throw new IllegalStateException( "New profile should be marked 'new'. Check your UserProfile implementation." );
             }
         }
 
@@ -287,10 +261,9 @@ public class UserManager {
 
         // Check if another user profile already has the fullname or loginname
         final UserProfile oldProfile = getUserProfile( session );
-        final boolean nameChanged = ( oldProfile == null  || oldProfile.getFullname() == null )
-            ? false
-            : !( oldProfile.getFullname().equals( profile.getFullname() ) &&
-                 oldProfile.getLoginName().equals( profile.getLoginName() ) );
+        final boolean nameChanged = ( oldProfile != null && oldProfile.getFullname() != null ) &&
+                                    !( oldProfile.getFullname().equals( profile.getFullname() ) &&
+                                    oldProfile.getLoginName().equals( profile.getLoginName() ) );
         UserProfile otherProfile;
         try
         {
@@ -585,21 +558,17 @@ public class UserManager {
     }
 
     /**
-     * This is a database that gets used if nothing else is available. It does
-     * nothing of note - it just mostly throws NoSuchPrincipalExceptions if
-     * someone tries to log in.
+     * This is a database that gets used if nothing else is available. It does nothing of note - it just mostly throws
+     * NoSuchPrincipalExceptions if someone tries to log in.
      */
-    public static class DummyUserDatabase extends AbstractUserDatabase
-    {
+    public static class DummyUserDatabase extends AbstractUserDatabase {
 
         /**
          * No-op.
          * @param loginName the login name to delete
-         * @throws WikiSecurityException never...
          */
         @Override
-        public void deleteByLoginName( String loginName ) throws WikiSecurityException
-        {
+        public void deleteByLoginName( String loginName ) {
             // No operation
         }
 
@@ -607,11 +576,10 @@ public class UserManager {
          * No-op; always throws <code>NoSuchPrincipalException</code>.
          * @param index the name to search for
          * @return the user profile
-         * @throws NoSuchPrincipalException never...
+         * @throws NoSuchPrincipalException always...
          */
         @Override
-        public UserProfile findByEmail(String index) throws NoSuchPrincipalException
-        {
+        public UserProfile findByEmail(final String index) throws NoSuchPrincipalException {
             throw new NoSuchPrincipalException("No user profiles available");
         }
 
@@ -619,11 +587,10 @@ public class UserManager {
          * No-op; always throws <code>NoSuchPrincipalException</code>.
          * @param index the name to search for
          * @return the user profile
-         * @throws NoSuchPrincipalException never...
+         * @throws NoSuchPrincipalException always...
          */
         @Override
-        public UserProfile findByFullName(String index) throws NoSuchPrincipalException
-        {
+        public UserProfile findByFullName(final String index) throws NoSuchPrincipalException {
             throw new NoSuchPrincipalException("No user profiles available");
         }
 
@@ -631,11 +598,10 @@ public class UserManager {
          * No-op; always throws <code>NoSuchPrincipalException</code>.
          * @param index the name to search for
          * @return the user profile
-         * @throws NoSuchPrincipalException never...
+         * @throws NoSuchPrincipalException always...
          */
         @Override
-        public UserProfile findByLoginName(String index) throws NoSuchPrincipalException
-        {
+        public UserProfile findByLoginName(final String index) throws NoSuchPrincipalException {
             throw new NoSuchPrincipalException("No user profiles available");
         }
 
@@ -643,33 +609,29 @@ public class UserManager {
          * No-op; always throws <code>NoSuchPrincipalException</code>.
          * @param uid the unique identifier to search for
          * @return the user profile
-         * @throws NoSuchPrincipalException never...
+         * @throws NoSuchPrincipalException always...
          */
         @Override
-        public UserProfile findByUid( String uid ) throws NoSuchPrincipalException
-        {
+        public UserProfile findByUid( final String uid ) throws NoSuchPrincipalException {
             throw new NoSuchPrincipalException("No user profiles available");
         }
         /**
          * No-op; always throws <code>NoSuchPrincipalException</code>.
          * @param index the name to search for
          * @return the user profile
-         * @throws NoSuchPrincipalException never...
+         * @throws NoSuchPrincipalException always...
          */
         @Override
-        public UserProfile findByWikiName(String index) throws NoSuchPrincipalException
-        {
+        public UserProfile findByWikiName(final String index) throws NoSuchPrincipalException {
             throw new NoSuchPrincipalException("No user profiles available");
         }
 
         /**
          * No-op.
          * @return a zero-length array
-         * @throws WikiSecurityException never...
          */
         @Override
-        public Principal[] getWikiNames() throws WikiSecurityException
-        {
+        public Principal[] getWikiNames() {
             return new Principal[0];
         }
 
@@ -678,34 +640,28 @@ public class UserManager {
          *
          * @param engine the wiki engine
          * @param props the properties used to initialize the wiki engine
-         * @throws NoRequiredPropertyException never...
          */
         @Override
-        public void initialize(WikiEngine engine, Properties props) throws NoRequiredPropertyException
-        {
+        public void initialize(final WikiEngine engine, final Properties props) {
         }
 
         /**
          * No-op; always throws <code>NoSuchPrincipalException</code>.
          * @param loginName the login name
          * @param newName the proposed new login name
-         * @throws DuplicateUserException never...
-         * @throws WikiSecurityException never...
+         * @throws NoSuchPrincipalException always...
          */
         @Override
-        public void rename( String loginName, String newName ) throws DuplicateUserException, WikiSecurityException
-        {
+        public void rename( final String loginName, final String newName ) throws NoSuchPrincipalException {
             throw new NoSuchPrincipalException("No user profiles available");
         }
 
         /**
          * No-op.
          * @param profile the user profile
-         * @throws WikiSecurityException never...
          */
         @Override
-        public void save( UserProfile profile ) throws WikiSecurityException
-        {
+        public void save( final UserProfile profile ) {
         }
 
     }
@@ -752,12 +708,11 @@ public class UserManager {
     /**
      *  Implements the JSON API for usermanager.
      *  <p>
-     *  Even though this gets serialized whenever container shuts down/restarts,
-     *  this gets reinstalled to the session when JSPWiki starts.  This means
-     *  that it's not actually necessary to save anything.
+     *  Even though this gets serialized whenever container shuts down/restarts, this gets reinstalled to the session when JSPWiki starts.
+     *  This means that it's not actually necessary to save anything.
      */
-    public static final class JSONUserModule implements WikiAjaxServlet
-    {
+    public static final class JSONUserModule implements WikiAjaxServlet {
+
 		private volatile UserManager m_manager;
 
         /**
@@ -777,11 +732,10 @@ public class UserManager {
         @Override
         public void service(HttpServletRequest req, HttpServletResponse resp, String actionName, List<String> params) throws ServletException, IOException {
         	try {
-        		String uid = null;
-            	if (params.size()<1) {
+            	if( params.size() < 1 ) {
             		return;
             	}
-        		uid = params.get(0);
+        		final String uid = params.get(0);
 	        	log.debug("uid="+uid);
 	        	if (StringUtils.isNotBlank(uid)) {
 		            final UserProfile prof = getUserInfo(uid);
@@ -799,17 +753,14 @@ public class UserManager {
          *  @return A UserProfile object
          *  @throws NoSuchPrincipalException If such a name does not exist.
          */
-        public UserProfile getUserInfo( String uid )
-            throws NoSuchPrincipalException
-        {
-            if( m_manager != null )
-            {
+        public UserProfile getUserInfo( String uid ) throws NoSuchPrincipalException {
+            if( m_manager != null ) {
                 final UserProfile prof = m_manager.getUserDatabase().find( uid );
-
                 return prof;
             }
 
             throw new IllegalStateException("The manager is offline.");
         }
     }
+
 }


[jspwiki] 05/14: added note on generating javadocs with JDK >=9

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 b705a6d6c75ff169a3ec7d6357f7516ab0e6f6a5
Author: juanpablo <ju...@apache.org>
AuthorDate: Fri Dec 6 22:02:58 2019 +0100

    added note on generating javadocs with JDK >=9
---
 mvn_cheat-sheet.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mvn_cheat-sheet.md b/mvn_cheat-sheet.md
index 9a0c8cd..b2320a0 100644
--- a/mvn_cheat-sheet.md
+++ b/mvn_cheat-sheet.md
@@ -38,7 +38,7 @@ under the License.
 | mvn org.codehaus.cargo:cargo-maven2-plugin:run                    | (from main war module) starts JSPWiki on a Tomcat8 instance at http://localhost:8080/JSPWiki with an attached debugger    |
 |                                                                   | on port 5005                                                                                                              |
 | mvn clean deploy -Papache-release -Dgpg.passphrase=<passphrase>   | deploys generated artifact to a repository. If -Dgpg.passphrase is not given, expects a gpg-agent running                 |
-| mvn clean install -Pintegration-tests                             | performs a build, enabling functional tests execution (best run from the jspwiki-it-tests folder)                           |
+| mvn clean install -Pintegration-tests                             | performs a build, enabling functional tests execution (best run from the jspwiki-it-tests folder)                         |
 | mvn wro4j:run -Dminimize=true                                     | merge & compress js & css files                                                                                           |
 | mvn wro4j:run -Dminimize=false                                    | only merge the js & css files  (no compression)                                                                           |
 | mvn clean install -Dmaven.test.skip -Dminimize=false              | performs a build, skipping the tests and skip compression                                                                 |
@@ -52,4 +52,5 @@ under the License.
 | mvn cobertura:cobertura                                           | generates a cobertura maven report. See: http://mojo.codehaus.org/cobertura-maven-plugin/usage.html                       |
 | mvn javadoc:javadoc                                               | creates javadocs; if graphviz binaries (www.graphviz.org) are found on $PATH, the javadocs will display                   |
 |                                                                   | some UML class/package level diagrams                                                                                     |
+| mvn javadoc:javadoc -Djdk.javadoc.doclet.version=2.0.6            | same as above, but with JDK >= 9                                                                                          |
 | mvn sonar:sonar                                                   | generates a Sonar report. Expects a Sonar server running at http://localhost:9000/                                        |