| java.lang.Object com.ecyrd.jspwiki.TextUtil
TextUtil | final public class TextUtil (Code) | | Contains a number of static utility methods.
|
Method Summary | |
public static String | beautifyString(String s) Adds spaces in suitable locations of the input string. | public static String | beautifyString(String s, String space) Adds spaces in suitable locations of the input string. | public static int | countSections(String pagedata) Counts the number of sections (separated with "----") from the page.
Parameters: pagedata - The WikiText to parse. | public static Properties | createProperties(String[] values) Creates a Properties object based on an array which contains alternatively
a key and a value. | public static String | generateRandomPassword() Generate a random String suitable for use as a temporary password. | public static boolean | getBooleanProperty(Properties props, 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". | public static int | getIntegerProperty(Properties props, String key, int defVal) Gets an integer-valued property from a standard Properties
list. | public static String | getSection(String pagedata, int section) Gets the given section (separated with "----") from the page text.
Note that the first section is always #1. | public static String | getStringProperty(Properties props, String key, String defval) Fetches a String property from the set of Properties. | public static boolean | isNumber(String s) Returns true, if the argument contains a number, otherwise false.
In a quick test this is roughly the same speed as Integer.parseInt()
if the argument is a number, and roughly ten times the speed, if
the argument is NOT a number.
since: 2.4 Parameters: s - String to check True, if s represents a number. | public static boolean | isPositive(String val) Returns true, if the string "val" denotes a positive string. | public static String | native2Ascii(String s) Converts a string from the Unicode representation into something that can be
embedded in a java properties file. | public static String | normalizePostData(String postData) Makes sure that the POSTed data is conforms to certain rules. | public static int | parseIntParameter(String value, int defvalue) Parses an integer parameter, returning a default value
if the value is null or a non-number. | public static String | repeatString(String what, int times) A simple routine which just repeates the arguments. | public static String | replaceEntities(String src) Replaces the relevant entities inside the String.
All & >, <, and " are replaced by their
respective names.
since: 1.6.1 Parameters: src - The source string. | final public static String | replaceString(String orig, String src, String dest) Replaces a string with an other string.
Parameters: orig - Original string. | public static String | replaceString(String orig, int start, int end, String text) Replaces a part of a string with a new String.
Parameters: start - Where in the original string the replacing should start. Parameters: end - Where the replacing should end. Parameters: orig - Original string. | public 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. | public static String | urlDecode(String data, String encoding) Provides decoded version of string depending on encoding. | public 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. | public static String | urlEncode(String data, String encoding) Provides encoded version of string depending on encoding. | public static String | urlEncodeUTF8(String text) As java.net.URLEncoder class, but this does it in UTF8 character set. |
PASSWORD_LENGTH | final public static int PASSWORD_LENGTH(Code) | | Length of password. @see #generateRandomPassword()
|
beautifyString | public static String beautifyString(String s)(Code) | | 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. A beautified string. |
beautifyString | public static String beautifyString(String s, String space)(Code) | | 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. Parameters: space - Use this string for the space character. A beautified string. since: 2.1.127 |
countSections | public static int countSections(String pagedata)(Code) | | Counts the number of sections (separated with "----") from the page.
Parameters: pagedata - The WikiText to parse. int Number of counted sections. since: 2.1.86. |
createProperties | public static Properties createProperties(String[] values) throws IllegalArgumentException(Code) | | Creates a Properties object based on an array which contains alternatively
a key and a value. It is useful for generating default mappings.
For example:
String[] properties = { "jspwiki.property1", "value1",
"jspwiki.property2", "value2 };
Properties props = TextUtil.createPropertes( values );
System.out.println( props.getProperty("jspwiki.property1") );
would output "value1".
Parameters: values - Alternating key and value pairs. Property object See Also: java.util.Properties throws: IllegalArgumentException - if the property array is missinga value for a key. since: 2.2. |
generateRandomPassword | public static String generateRandomPassword()(Code) | | Generate a random String suitable for use as a temporary password.
String suitable for use as a temporary password since: 2.4 |
getBooleanProperty | public static boolean getBooleanProperty(Properties props, String key, boolean defval)(Code) | | 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. Parameters: key - The property key. Parameters: defval - The default value to return. True, if the property "key" was set to "true", "on", or "yes". since: 2.0.11 |
getIntegerProperty | public static int getIntegerProperty(Properties props, String key, int defVal)(Code) | | Gets an integer-valued property from a standard Properties
list. If the value does not exist, or is a non-integer, returns defVal.
since: 2.1.48. Parameters: props - The property set to look through Parameters: key - The key to look for Parameters: defVal - If the property is not found or is a non-integer, returns this value. The property value as an integer (or defVal). |
getSection | public static String getSection(String pagedata, int section) throws IllegalArgumentException(Code) | | Gets the given section (separated with "----") from the page text.
Note that the first section is always #1. If a page has no section markers,
them there is only a single section, #1.
Parameters: pagedata - WikiText to parse. Parameters: section - Which section to get. String The section. throws: IllegalArgumentException - If the page does not contain this many sections. since: 2.1.86. |
getStringProperty | public static String getStringProperty(Properties props, String key, String defval)(Code) | | Fetches a String property from the set of Properties. This differs from
Properties.getProperty() in a couple of key respects: First, property value
is trim()med (so no extra whitespace back and front), and well, that's it.
Parameters: props - The Properties to search through Parameters: key - The property key Parameters: defval - A default value to return, if the property does not exist. The property value. since: 2.1.151 |
isNumber | public static boolean isNumber(String s)(Code) | | Returns true, if the argument contains a number, otherwise false.
In a quick test this is roughly the same speed as Integer.parseInt()
if the argument is a number, and roughly ten times the speed, if
the argument is NOT a number.
since: 2.4 Parameters: s - String to check True, if s represents a number. False otherwise. |
isPositive | public static boolean isPositive(String val)(Code) | | 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. True, if val is "true", "on", or "yes"; otherwise false. since: 2.0.26 |
native2Ascii | public static String native2Ascii(String s)(Code) | | Converts a string from the Unicode representation into something that can be
embedded in a java properties file. All references outside the ASCII range
are replaced with \\uXXXX.
Parameters: s - The string to convert the ASCII string |
normalizePostData | public static String normalizePostData(String postData)(Code) | | Makes sure that the POSTed data is conforms to certain rules. These
rules are:
- The data always ends with a newline (some browsers, such
as NS4.x series, does not send a newline at the end, which makes
the diffs a bit strange sometimes.
- The CR/LF/CRLF mess is normalized to plain CRLF.
The reason why we're using CRLF is that most browser already
return CRLF since that is the closest thing to a HTTP standard.
Parameters: postData - The data to normalize Normalized data |
parseIntParameter | public static int parseIntParameter(String value, int defvalue)(Code) | | Parses an integer parameter, returning a default value
if the value is null or a non-number.
Parameters: value - The value to parse Parameters: defvalue - A default value in case the value is not a number The parsed value (or defvalue). |
repeatString | public static String repeatString(String what, int times)(Code) | | A simple routine which just repeates the arguments. This is useful
for creating something like a line or something.
Parameters: what - String to repeat Parameters: times - How many times to repeat the string. Guess what? since: 2.1.98. |
replaceEntities | public static String replaceEntities(String src)(Code) | | Replaces the relevant entities inside the String.
All & >, <, and " are replaced by their
respective names.
since: 1.6.1 Parameters: src - The source string. The encoded string. |
replaceString | final public static String replaceString(String orig, String src, String dest)(Code) | | Replaces a string with an other string.
Parameters: orig - Original string. Null is safe. Parameters: src - The string to find. Parameters: dest - The string to replace src with. A string with the replacement done. |
replaceString | public static String replaceString(String orig, int start, int end, String text)(Code) | | Replaces a part of a string with a new String.
Parameters: start - Where in the original string the replacing should start. Parameters: end - Where the replacing should end. Parameters: orig - Original string. Null is safe. Parameters: text - The new text to insert into the string. The string with the orig replaced with text. |
toHexString | public static String toHexString(byte[] bytes)(Code) | | Generates a hexadecimal string from an array of bytes. For
example, if the array contains { 0x01, 0x02, 0x3E }, the resulting
string will be "01023E".
Parameters: bytes - A Byte array A String representation since: 2.3.87 |
urlDecodeUTF8 | public static String urlDecodeUTF8(String utf8)(Code) | | As java.net.URLDecoder class, but for UTF-8 strings. null is a safe
value and returns null.
Parameters: utf8 - The UTF-8 encoded string A plain, normal string. |
urlEncode | protected static String urlEncode(byte[] rs)(Code) | | java.net.URLEncoder.encode() method in JDK < 1.4 is buggy. This duplicates
its functionality.
Parameters: rs - the string to encode the URL-encoded string |
urlEncode | public static String urlEncode(String data, String encoding)(Code) | | 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().
Parameters: data - A string to encode Parameters: encoding - The encoding in which to encode An URL encoded string. |
urlEncodeUTF8 | public static String urlEncodeUTF8(String text)(Code) | | As java.net.URLEncoder class, but this does it in UTF8 character set.
Parameters: text - The text to decode An URLEncoded string. |
|
|