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 5ca1119048421682a1406342d61f4e888c291a9a
Author: Juan Pablo Santos Rodríguez <[email protected]>
AuthorDate: Thu Dec 2 22:50:49 2021 +0100

    Introduce TextUtil#getRequiredProperty(Properties, String, String)
---
 .../main/java/org/apache/wiki/util/TextUtil.java   | 23 ++++++++++++++++++++--
 .../java/org/apache/wiki/util/TextUtilTest.java    |  9 +++++++++
 .../src/test/resources/ini/jspwiki.properties      |  2 +-
 3 files changed, 31 insertions(+), 3 deletions(-)

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 49115aa..f6c4809 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
@@ -409,8 +409,8 @@ public final class TextUtil {
     public static String getStringProperty( final Properties props, final 
String key, final String deprecatedKey, final String defval ) {
         final String val = getStringProperty( props, deprecatedKey, null );
         if( val != null ) {
-            LOG.warn( "{} is being deprecated and will be removed on a future 
version, please consider using {} instead" +
-                      "in your jspwiki[-custom].properties file", key, key );
+            LOG.warn( "{} is being deprecated and will be removed on a future 
version, please consider using {} instead " +
+                      "in your jspwiki[-custom].properties file", 
deprecatedKey, key );
             return val;
         }
         return getStringProperty( props, key, defval );
@@ -435,6 +435,25 @@ public final class TextUtil {
     }
 
     /**
+     * {@link #getRequiredProperty(Properties, String)} overload that handles 
deprecated keys, so that a key and its
+     * deprecated counterpart can coexist in a given version of JSPWiki.
+     *
+     * @param props The Properties to search through
+     * @param key The property key
+     * @param deprecatedKey the property key being superseeded by key
+     * @return The property value.
+     */
+    public static String getRequiredProperty( final Properties props, final 
String key, final String deprecatedKey ) throws NoSuchElementException {
+        final String value = getStringProperty( props, deprecatedKey, null );
+        if( value == null ) {
+            return getRequiredProperty( props, key );
+        }
+        LOG.warn( "{} is being deprecated and will be removed on a future 
version, please consider using {} instead " +
+                  "in your jspwiki[-custom].properties file", deprecatedKey, 
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 we use that value,
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 812bca7..2ad60b6 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
@@ -341,6 +341,15 @@ public class TextUtilTest {
     }
 
     @Test
+    public void testGetRequiredPropertyDeprecated() {
+        final String[] vals = { "foo", " this is a property ", "foo-dep", 
"deprecated" };
+        final Properties props = TextUtil.createProperties( vals );
+        Assertions.assertEquals( "deprecated", TextUtil.getRequiredProperty( 
props, "foo", "foo-dep" ) );
+        Assertions.assertEquals( "this is a property", 
TextUtil.getRequiredProperty( props, "foo", "bar-dep" ) );
+        Assertions.assertThrows( NoSuchElementException.class, () -> 
TextUtil.getRequiredProperty( props, "fooo", "bar-dep" ) );
+    }
+
+    @Test
     public void testCleanString() {
         Assertions.assertNull( TextUtil.cleanString( null, 
TextUtil.PUNCTUATION_CHARS_ALLOWED ) );
         Assertions.assertEquals( " This is a link ", TextUtil.cleanString( " [ 
This is a link ] ", TextUtil.PUNCTUATION_CHARS_ALLOWED ) );
diff --git a/jspwiki-util/src/test/resources/ini/jspwiki.properties 
b/jspwiki-util/src/test/resources/ini/jspwiki.properties
index 93a5adc..9818be0 100644
--- a/jspwiki-util/src/test/resources/ini/jspwiki.properties
+++ b/jspwiki-util/src/test/resources/ini/jspwiki.properties
@@ -18,7 +18,7 @@
 jspwiki.applicationName = JSPWiki
 jspwiki.pageProvider = FileSystemProvider
 jspwiki.cache.enable = true
-jspwiki.attachmentProvider = BasicAttachmentProvider
+jspwiki.attachment.provider = BasicAttachmentProvider
 jspwiki.diffProvider = TraditionalDiffProvider
 jspwiki.encoding = UTF-8
 jspwiki.translatorReader.allowHTML = false

Reply via email to