com.ecyrd.jspwiki
Class TextUtil

java.lang.Object
  |
  +--com.ecyrd.jspwiki.TextUtil

public class TextUtil
extends java.lang.Object

Contains a number of static utility methods.


Constructor Summary
TextUtil()
           
 
Method Summary
static java.lang.String beautifyString(java.lang.String s)
          Adds spaces in suitable locations of the input string.
static boolean getBooleanProperty(java.util.Properties props, java.lang.String key, boolean defval)
          Gets a boolean property from a standard Properties list.
static boolean isPositive(java.lang.String val)
          Returns true, if the string "val" denotes a positive string.
static java.lang.String normalizePostData(java.lang.String postData)
          Makes sure that the POSTed data is conforms to certain rules.
static int parseIntParameter(java.lang.String value, int defvalue)
          Parses an integer parameter, returning a default value if the value is null or a non-number.
static java.lang.String replaceEntities(java.lang.String src)
          Replaces the relevant entities inside the String.
static java.lang.String replaceString(java.lang.String orig, int start, int end, java.lang.String text)
          Replaces a part of a string with a new String.
static java.lang.String replaceString(java.lang.String orig, java.lang.String src, java.lang.String dest)
          Replaces a string with an other string.
protected static java.lang.String urlDecode(byte[] bytes)
          URL encoder does not handle all characters correctly.
static java.lang.String urlDecode(java.lang.String data, java.lang.String encoding)
          Provides decoded version of string depending on encoding.
static java.lang.String urlDecodeUTF8(java.lang.String utf8)
          As java.net.URLDecoder class, but for UTF-8 strings.
protected static java.lang.String urlEncode(byte[] rs)
          java.net.URLEncoder.encode() method in JDK < 1.4 is buggy.
static java.lang.String urlEncode(java.lang.String data, java.lang.String encoding)
          Provides encoded version of string depending on encoding.
static java.lang.String urlEncodeUTF8(java.lang.String text)
          As java.net.URLEncoder class, but this does it in UTF8 character set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtil

public TextUtil()
Method Detail

urlEncode

protected static java.lang.String urlEncode(byte[] rs)
java.net.URLEncoder.encode() method in JDK < 1.4 is buggy. This duplicates its functionality.


urlDecode

protected static java.lang.String urlDecode(byte[] bytes)
                                     throws java.io.UnsupportedEncodingException,
                                            java.lang.IllegalArgumentException
URL encoder does not handle all characters correctly. See Bug parade, bug #4257115 for more information.

Thanks to CJB for this fix.

java.io.UnsupportedEncodingException
java.lang.IllegalArgumentException

urlEncodeUTF8

public static java.lang.String urlEncodeUTF8(java.lang.String text)
As java.net.URLEncoder class, but this does it in UTF8 character set.


urlDecodeUTF8

public static java.lang.String urlDecodeUTF8(java.lang.String utf8)
As java.net.URLDecoder class, but for UTF-8 strings.


urlEncode

public static java.lang.String urlEncode(java.lang.String data,
                                         java.lang.String encoding)
Provides encoded version of string depending on encoding. Encoding may be UTF-8 or ISO-8859-1 (default).

This implementation is the same as in FileSystemProvider.mangleName().


urlDecode

public static java.lang.String urlDecode(java.lang.String data,
                                         java.lang.String encoding)
                                  throws java.io.UnsupportedEncodingException,
                                         java.lang.IllegalArgumentException
Provides decoded version of string depending on encoding. Encoding may be UTF-8 or ISO-8859-1 (default).

This implementation is the same as in FileSystemProvider.unmangleName().

java.io.UnsupportedEncodingException
java.lang.IllegalArgumentException

replaceEntities

public static java.lang.String replaceEntities(java.lang.String src)
Replaces the relevant entities inside the String. All >, < and " are replaced by their respective names.

Since:
1.6.1

replaceString

public static java.lang.String replaceString(java.lang.String orig,
                                             java.lang.String src,
                                             java.lang.String dest)
Replaces a string with an other string.

Parameters:
orig - Original string. Null is safe.
src - The string to find.
dest - The string to replace src with.

replaceString

public static java.lang.String replaceString(java.lang.String orig,
                                             int start,
                                             int end,
                                             java.lang.String text)
Replaces a part of a string with a new String.

Parameters:
start - Where in the original string the replacing should start.
end - Where the replacing should end.
orig - Original string. Null is safe.
text - The new text to insert into the string.

parseIntParameter

public static int parseIntParameter(java.lang.String value,
                                    int defvalue)
Parses an integer parameter, returning a default value if the value is null or a non-number.


getBooleanProperty

public static boolean getBooleanProperty(java.util.Properties props,
                                         java.lang.String key,
                                         boolean defval)
Gets a boolean property from a standard Properties list. Returns the default value, in case the key has not been set.

The possible values for the property are "true"/"false", "yes"/"no", or "on"/"off". Any value not recognized is always defined as "false".

Parameters:
props - A list of properties to search.
key - The property key.
defval - The default value to return.
Returns:
True, if the property "key" was set to "true", "on", or "yes".
Since:
2.0.11

isPositive

public static boolean isPositive(java.lang.String val)
Returns true, if the string "val" denotes a positive string. Allowed values are "yes", "on", and "true". Comparison is case-insignificant. Null values are safe.

Parameters:
val - Value to check.
Returns:
True, if val is "true", "on", or "yes"; otherwise false.
Since:
2.0.26

normalizePostData

public static java.lang.String normalizePostData(java.lang.String postData)
Makes sure that the POSTed data is conforms to certain rules. These rules are: The reason why we're using CRLF is that most browser already return CRLF since that is the closest thing to a HTTP standard.


beautifyString

public static java.lang.String beautifyString(java.lang.String s)
Adds spaces in suitable locations of the input string. This is used to transform a WikiName into a more readable format.

Parameters:
s - String to be beautified.
Returns:
A beautified string.