public final class TextUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
PASSWORD_LENGTH
Length of password.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
beautifyString(java.lang.String s)
Adds spaces in suitable locations of the input string.
|
static java.lang.String |
beautifyString(java.lang.String s,
java.lang.String space)
Adds spaces in suitable locations of the input string.
|
static int |
countSections(java.lang.String pagedata)
Counts the number of sections (separated with "----") from the page.
|
static java.util.Properties |
createProperties(java.lang.String[] values)
Creates a Properties object based on an array which contains alternatively
a key and a value.
|
static java.lang.String |
generateRandomPassword()
Generate a random String suitable for use as a temporary password.
|
static boolean |
getBooleanProperty(java.util.Properties props,
java.lang.String key,
boolean defval)
Gets a boolean property from a standard Properties list.
|
static int |
getIntegerProperty(java.util.Properties props,
java.lang.String key,
int defVal)
Gets an integer-valued property from a standard Properties
list.
|
static java.lang.String |
getSection(java.lang.String pagedata,
int section)
Gets the given section (separated with "----") from the page text.
|
static java.lang.String |
getStringProperty(java.util.Properties props,
java.lang.String key,
java.lang.String defval)
Fetches a String property from the set of Properties.
|
static boolean |
isNumber(java.lang.String s)
Returns true, if the argument contains a number, otherwise false.
|
static boolean |
isPositive(java.lang.String val)
Returns true, if the string "val" denotes a positive string.
|
static java.lang.String |
native2Ascii(java.lang.String s)
Converts a string from the Unicode representation into something that can be
embedded in a java properties file.
|
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 |
repeatString(java.lang.String what,
int times)
A simple routine which just repeates the arguments.
|
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.
|
static java.lang.String |
replaceStringCaseUnsensitive(java.lang.String orig,
java.lang.String src,
java.lang.String dest)
Replaces a string with an other string.
|
static java.lang.String |
toHexString(byte[] bytes)
Generates a hexadecimal string from an array of bytes.
|
protected static java.lang.String |
urlDecode(byte[] bytes,
java.lang.String encoding)
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.
|
public static final int PASSWORD_LENGTH
protected static java.lang.String urlEncode(byte[] rs)
rs
- the string to encodeprotected static java.lang.String urlDecode(byte[] bytes, java.lang.String encoding) throws java.io.UnsupportedEncodingException, java.lang.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 interpretedjava.io.UnsupportedEncodingException
- If the encoding is unknown.java.lang.IllegalArgumentException
- If the byte array is not a valid string.public static java.lang.String urlEncodeUTF8(java.lang.String text)
text
- The text to decodepublic static java.lang.String urlDecodeUTF8(java.lang.String utf8)
utf8
- The UTF-8 encoded stringpublic static java.lang.String urlEncode(java.lang.String data, java.lang.String encoding)
This implementation is the same as in FileSystemProvider.mangleName().
data
- A string to encodeencoding
- The encoding in which to encodepublic static java.lang.String urlDecode(java.lang.String data, java.lang.String encoding) throws java.io.UnsupportedEncodingException, java.lang.IllegalArgumentException
This implementation is the same as in FileSystemProvider.unmangleName().
data
- The URL-encoded string to decodeencoding
- The encoding to usejava.io.UnsupportedEncodingException
- If the encoding is unknownjava.lang.IllegalArgumentException
- If the data cannot be decoded.public static java.lang.String replaceEntities(java.lang.String src)
src
- The source string.public static final java.lang.String replaceString(java.lang.String orig, java.lang.String src, java.lang.String dest)
orig
- Original string. Null is safe.src
- The string to find.dest
- The string to replace src with.public static java.lang.String replaceString(java.lang.String orig, int start, int end, java.lang.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 java.lang.String replaceStringCaseUnsensitive(java.lang.String orig, java.lang.String src, java.lang.String dest)
orig
- Original string. Null is safe.src
- The string to find.dest
- The string to replace src with.public static int parseIntParameter(java.lang.String value, int defvalue)
value
- The value to parsedefvalue
- A default value in case the value is not a numberpublic static int getIntegerProperty(java.util.Properties props, java.lang.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(java.util.Properties props, java.lang.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 java.lang.String getStringProperty(java.util.Properties props, java.lang.String key, java.lang.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(java.lang.String val)
val
- Value to check.public static java.lang.String normalizePostData(java.lang.String postData)
postData
- The data to normalizepublic static java.lang.String beautifyString(java.lang.String s)
s
- String to be beautified.public static java.lang.String beautifyString(java.lang.String s, java.lang.String space)
s
- String to be beautified.space
- Use this string for the space character.public static java.util.Properties createProperties(java.lang.String[] values) throws java.lang.IllegalArgumentException
String[] properties = { "jspwiki.property1", "value1", "jspwiki.property2", "value2 }; Properties props = TextUtil.createPropertes( values ); LOGGER.info( props.getProperty("jspwiki.property1") );would output "value1".
values
- Alternating key and value pairs.java.lang.IllegalArgumentException
- if the property array is missing
a value for a key.Properties
public static int countSections(java.lang.String pagedata)
pagedata
- The WikiText to parse.public static java.lang.String getSection(java.lang.String pagedata, int section) throws java.lang.IllegalArgumentException
pagedata
- WikiText to parse.section
- Which section to get.java.lang.IllegalArgumentException
- If the page does not contain this many sections.public static java.lang.String repeatString(java.lang.String what, int times)
what
- String to repeattimes
- How many times to repeat the string.public static java.lang.String native2Ascii(java.lang.String s)
s
- The string to convertpublic static java.lang.String toHexString(byte[] bytes)
bytes
- A Byte arraypublic static boolean isNumber(java.lang.String s)
s
- String to checkpublic static java.lang.String generateRandomPassword()
stSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.