Author: juanpablo
Date: Wed Jan 9 19:33:40 2013
New Revision: 1431022
URL: http://svn.apache.org/viewvc?rev=1431022&view=rev
Log:
* deprecated WikiEngine.getRequiredProperty( props, key ) in favour of
TextUtil.getRequiredProperty( props, key ). The former will be deleted in
2.10 scope
Modified:
incubator/jspwiki/trunk/src/org/apache/wiki/TextUtil.java
incubator/jspwiki/trunk/src/org/apache/wiki/providers/BasicAttachmentProvider.java
incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingAttachmentProvider.java
incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingProvider.java
incubator/jspwiki/trunk/tests/org/apache/wiki/TextUtilTest.java
Modified: incubator/jspwiki/trunk/src/org/apache/wiki/TextUtil.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/TextUtil.java?rev=1431022&r1=1431021&r2=1431022&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/org/apache/wiki/TextUtil.java (original)
+++ incubator/jspwiki/trunk/src/org/apache/wiki/TextUtil.java Wed Jan 9
19:33:40 2013
@@ -465,6 +465,30 @@ public final class TextUtil
return val.trim();
}
+
+ /**
+ * 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.
+ */
+ public static String getRequiredProperty( Properties props, String key )
+ throws NoRequiredPropertyException
+ {
+ String value = getStringProperty( props, key, null );
+
+ if( value == null )
+ {
+ throw new NoRequiredPropertyException( "Required property not
found",
+ key );
+ }
+
+ return value;
+ }
/**
* Returns true, if the string "val" denotes a positive string. Allowed
Modified:
incubator/jspwiki/trunk/src/org/apache/wiki/providers/BasicAttachmentProvider.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/providers/BasicAttachmentProvider.java?rev=1431022&r1=1431021&r2=1431022&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/org/apache/wiki/providers/BasicAttachmentProvider.java
(original)
+++
incubator/jspwiki/trunk/src/org/apache/wiki/providers/BasicAttachmentProvider.java
Wed Jan 9 19:33:40 2013
@@ -109,7 +109,7 @@ public class BasicAttachmentProvider
IOException
{
m_engine = engine;
- m_storageDir = WikiEngine.getRequiredProperty( properties,
PROP_STORAGEDIR );
+ m_storageDir = TextUtil.getRequiredProperty( properties,
PROP_STORAGEDIR );
String patternString = engine.getWikiProperties().getProperty(
PROP_DISABLECACHE );
if ( patternString != null )
Modified:
incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingAttachmentProvider.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingAttachmentProvider.java?rev=1431022&r1=1431021&r2=1431022&view=diff
==============================================================================
---
incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingAttachmentProvider.java
(original)
+++
incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingAttachmentProvider.java
Wed Jan 9 19:33:40 2013
@@ -105,8 +105,7 @@ public class CachingAttachmentProvider
//
// Find and initialize real provider.
//
- String classname = WikiEngine.getRequiredProperty( properties,
-
AttachmentManager.PROP_PROVIDER );
+ String classname = TextUtil.getRequiredProperty( properties,
AttachmentManager.PROP_PROVIDER );
try
{
Modified:
incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingProvider.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingProvider.java?rev=1431022&r1=1431021&r2=1431022&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingProvider.java
(original)
+++ incubator/jspwiki/trunk/src/org/apache/wiki/providers/CachingProvider.java
Wed Jan 9 19:33:40 2013
@@ -163,8 +163,7 @@ public class CachingProvider
//
// Find and initialize real provider.
//
- String classname = WikiEngine.getRequiredProperty( properties,
-
PageManager.PROP_PAGEPROVIDER );
+ String classname = TextUtil.getRequiredProperty( properties,
PageManager.PROP_PAGEPROVIDER );
try
Modified: incubator/jspwiki/trunk/tests/org/apache/wiki/TextUtilTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/org/apache/wiki/TextUtilTest.java?rev=1431022&r1=1431021&r2=1431022&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/org/apache/wiki/TextUtilTest.java (original)
+++ incubator/jspwiki/trunk/tests/org/apache/wiki/TextUtilTest.java Wed Jan 9
19:33:40 2013
@@ -20,6 +20,8 @@
package org.apache.wiki;
import junit.framework.*;
+
+import java.io.File;
import java.util.*;
public class TextUtilTest extends TestCase
@@ -370,6 +372,40 @@ public class TextUtilTest extends TestCa
assertEquals( "bar", 60, TextUtil.getIntegerProperty(props,"bar",0) );
}
+ public void testGetRequiredProperty() throws Exception
+ {
+ String[] vals = { "foo", " this is a property ", "bar", "60" };
+ Properties props = TextUtil.createProperties(vals);
+ assertEquals( "60", TextUtil.getRequiredProperty( props, "bar" ) );
+ }
+
+ public void testGetRequiredPropertyNRPE()
+ {
+ String[] vals = { "foo", " this is a property ", "bar", "60" };
+ Properties props = TextUtil.createProperties(vals);
+ try
+ {
+ TextUtil.getRequiredProperty( props, "ber" );
+ fail( "NoRequiredPropertyException should've been thrown!" );
+ }
+ catch (NoRequiredPropertyException nrpe) {}
+ }
+
+ public void testGetStringProperty()
+ {
+ String[] vals = { "foo", " this is a property " };
+ Properties props = TextUtil.createProperties(vals);
+ assertEquals( "this is a property", TextUtil.getStringProperty( props,
"foo", "err" ) );
+ }
+
+ 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);
+ assertEquals( defaultValue, TextUtil.getStringProperty( props, "bar",
defaultValue ) );
+ }
+
public static Test suite()
{
return new TestSuite( TextUtilTest.class );