|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ecyrd.jspwiki.TextUtil
public final class TextUtil
Contains a number of static utility methods.
| Field Summary | |
|---|---|
static int |
PASSWORD_LENGTH
Length of password. |
| Method Summary | |
|---|---|
static String |
beautifyString(String s)
Adds spaces in suitable locations of the input string. |
static String |
beautifyString(String s,
String space)
Adds spaces in suitable locations of the input string. |
static int |
countSections(String pagedata)
Counts the number of sections (separated with "----") from the page. |
static Properties |
createProperties(String[] values)
Creates a Properties object based on an array which contains alternatively a key and a value. |
static String |
generateRandomPassword()
Generate a random String suitable for use as a temporary password. |
static boolean |
getBooleanProperty(Properties props,
String key,
boolean defval)
Gets a boolean property from a standard Properties list. |
static int |
getIntegerProperty(Properties props,
String key,
int defVal)
Gets an integer-valued property from a standard Properties list. |
static String |
getSection(String pagedata,
int section)
Gets the given section (separated with "----") from the page text. |
static String |
getStringProperty(Properties props,
String key,
String defval)
Fetches a String property from the set of Properties. |
static boolean |
isNumber(String s)
Returns true, if the argument contains a number, otherwise false. |
static boolean |
isPositive(String val)
Returns true, if the string "val" denotes a positive string. |
static String |
native2Ascii(String s)
Converts a string from the Unicode representation into something that can be embedded in a java properties file. |
static String |
normalizePostData(String postData)
Makes sure that the POSTed data is conforms to certain rules. |
static int |
parseIntParameter(String value,
int defvalue)
Parses an integer parameter, returning a default value if the value is null or a non-number. |
static String |
repeatString(String what,
int times)
A simple routine which just repeates the arguments. |
static String |
replaceEntities(String src)
Replaces the relevant entities inside the String. |
static String |
replaceString(String orig,
int start,
int end,
String text)
Replaces a part of a string with a new String. |
static String |
replaceString(String orig,
String src,
String dest)
Replaces a string with an other string. |
static String |
replaceStringCaseUnsensitive(String orig,
String src,
String dest)
Replaces a string with an other string. |
static String |
toHexString(byte[] bytes)
Generates a hexadecimal string from an array of bytes. |
protected static String |
urlDecode(byte[] bytes,
String encoding)
URL encoder does not handle all characters correctly. |
static String |
urlDecode(String data,
String encoding)
Provides decoded version of string depending on encoding. |
static String |
urlDecodeUTF8(String utf8)
As java.net.URLDecoder class, but for UTF-8 strings. |
protected static String |
urlEncode(byte[] rs)
java.net.URLEncoder.encode() method in JDK < 1.4 is buggy. |
static String |
urlEncode(String data,
String encoding)
Provides encoded version of string depending on encoding. |
static String |
urlEncodeUTF8(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 |
| Field Detail |
|---|
public static final int PASSWORD_LENGTH
| Method Detail |
|---|
protected static String urlEncode(byte[] rs)
rs - the string to encode
protected static String urlDecode(byte[] bytes,
String encoding)
throws UnsupportedEncodingException,
IllegalArgumentException
Thanks to CJB for this fix.
bytes - The byte array containing the bytes of the stringencoding - The encoding in which the string should be interpreted
UnsupportedEncodingException - If the encoding is unknown.
IllegalArgumentException - If the byte array is not a valid string.public static String urlEncodeUTF8(String text)
text - The text to decode
public static String urlDecodeUTF8(String utf8)
utf8 - The UTF-8 encoded string
public static String urlEncode(String data,
String encoding)
This implementation is the same as in FileSystemProvider.mangleName().
data - A string to encodeencoding - The encoding in which to encode
public static String urlDecode(String data,
String encoding)
throws UnsupportedEncodingException,
IllegalArgumentException
This implementation is the same as in FileSystemProvider.unmangleName().
data - The URL-encoded string to decodeencoding - The encoding to use
UnsupportedEncodingException - If the encoding is unknown
IllegalArgumentException - If the data cannot be decoded.public static String replaceEntities(String src)
src - The source string.
public static final String replaceString(String orig,
String src,
String dest)
orig - Original string. Null is safe.src - The string to find.dest - The string to replace src with.
public static String replaceString(String orig,
int start,
int end,
String text)
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.
public static String replaceStringCaseUnsensitive(String orig,
String src,
String dest)
orig - Original string. Null is safe.src - The string to find.dest - The string to replace src with.
public static int parseIntParameter(String value,
int defvalue)
value - The value to parsedefvalue - A default value in case the value is not a number
public static int getIntegerProperty(Properties props,
String key,
int defVal)
props - The property set to look throughkey - The key to look fordefVal - If the property is not found or is a non-integer, returns this value.
public static boolean getBooleanProperty(Properties props,
String key,
boolean defval)
The possible values for the property are "true"/"false", "yes"/"no", or "on"/"off". Any value not recognized is always defined as "false".
props - A list of properties to search.key - The property key.defval - The default value to return.
public static String getStringProperty(Properties props,
String key,
String defval)
props - The Properties to search throughkey - The property keydefval - A default value to return, if the property does not exist.
public static boolean isPositive(String val)
val - Value to check.
public static String normalizePostData(String postData)
postData - The data to normalize
public static String beautifyString(String s)
s - String to be beautified.
public static String beautifyString(String s,
String space)
s - String to be beautified.space - Use this string for the space character.
public static Properties createProperties(String[] values)
throws IllegalArgumentException
String[] properties = { "jspwiki.property1", "value1",
"jspwiki.property2", "value2 };
Properties props = TextUtil.createPropertes( values );
System.out.println( props.getProperty("jspwiki.property1") );
would output "value1".
values - Alternating key and value pairs.
IllegalArgumentException - if the property array is missing
a value for a key.Propertiespublic static int countSections(String pagedata)
pagedata - The WikiText to parse.
public static String getSection(String pagedata,
int section)
throws IllegalArgumentException
pagedata - WikiText to parse.section - Which section to get.
IllegalArgumentException - If the page does not contain this many sections.
public static String repeatString(String what,
int times)
what - String to repeattimes - How many times to repeat the string.
public static String native2Ascii(String s)
s - The string to convert
public static String toHexString(byte[] bytes)
bytes - A Byte array
public static boolean isNumber(String s)
s - String to check
public static String generateRandomPassword()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||