public class StringUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtil.ScriptCheckResult
Script check errors.
|
Modifier and Type | Field and Description |
---|---|
static int |
DAYS_UNITS |
static int |
HOURS_UNITS |
static int |
MINUTES_UNITS |
static int |
MONTHS_UNITS |
static int |
SECONDS_UNITS
time-interval formatting selectors
|
static int |
WEEKS_UNITS |
static int |
YEARS_UNITS |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addPath(java.lang.String originalPath,
java.lang.String toAdd)
Add a path onto another path.
|
static java.lang.String |
beanify(java.lang.String strIn)
Convert the passed in string to a valid java method name.
|
static java.lang.String |
categorizeTime(long target,
int maxUnit)
Takes a target time (in msecs) and a time-unit-of-interest and returns an
I18N string in "x {units} {ago:from now}" format.
|
static java.lang.String |
categorizeTime(long target,
int maxUnit,
int minUnit)
Takes a target time (in msecs) and a maximum and minimum
time-unit-of-interest and returns an I18N string in
"x [maxUnits] y [units] ...
|
static java.lang.String |
classify(java.lang.String strIn)
Converts the passed in string to a valid java Class name.
|
static java.lang.Boolean |
containsInvalidXmlChars2(java.lang.String string)
Checks, whether string contains invalid xml chars
|
static java.lang.String |
convertMapToString(java.util.Map<java.lang.String,java.lang.Object> map,
java.lang.String seperator)
Convert a map of kernel options into a string: name1=value1 name2=value2
name3=value
|
static java.util.Map<java.lang.String,java.lang.String> |
convertOptionsToMap(java.lang.String options,
java.lang.String errorKey,
java.lang.String separator)
Convert a string of options (name value pairs separated by '=', where the
pairs are seperated by 'separator'), into a map.
|
static java.lang.String |
debeanify(java.lang.String strIn)
Convert the passed in bean style string to a underscore separated string.
|
static java.lang.String |
displayFileSize(long bytes)
Converts the number of bytes to the appropriate unit (B, KB, or MB)
depending on how many bytes there actually are.
|
static java.lang.String |
displayFileSize(long bytes,
boolean wholeNum)
Converts the number of bytes to the appropriate unit (B, KB, or MB)
depending on how many bytes there actually are.
|
static java.lang.String |
getBytesTruncatedString(java.lang.String str,
int length)
Tests String byte-length and eventually truncates
|
static java.lang.String |
getClassNameNoPackage(java.lang.Class clazz)
Convert a class's name into the name without the package For example
StringUtils.getClassNameNoPackage(StringUtils.class) outputs: StringUtils
|
static java.lang.String |
getHexString(byte[] b) |
static java.lang.String |
htmlifyText(java.lang.String convertIn)
Returns a String for html parsing escapes html converts \n to a break tag
(<BR/<) converts urls beginning with http:// and https:// to links
Example: given http://foo.bar/example return http://foo.bar/example
|
static java.lang.String |
join(java.lang.String separator,
java.util.Collection<java.lang.String> inputList)
Join the strings contained in inputList with the separator.
|
static java.lang.String |
join(java.lang.String separator,
java.util.Iterator<java.lang.String> itty)
Join the strings contained in an iterator with a separator.
|
static java.lang.Object |
jsonToObject(java.lang.String json)
Converts a jsoned representation back to the object
|
static java.lang.String |
makeRandomPassword(int lengthIn)
Create a random password of the specified length
|
static java.lang.String |
nullIfEmpty(java.lang.String str)
Returns null, if string is empty
|
static java.lang.String |
nullOrValue(java.lang.String str)
Returns null, if string is empty, is already null or contains tabs, whitespace,
line breaks or other non-valuable content.
|
static java.lang.String |
replaceTags(java.lang.String source,
java.util.Map<java.lang.String,java.lang.String> params)
given a string and a map, all instances of {key} will be replaced with
the value of 'key' in the map.
|
static StringUtil.ScriptCheckResult |
scriptPrematureCheck(java.lang.String script)
Check if the script seems to be valid.
|
static int |
smartStringToInt(java.lang.String s)
given a string, return the int of it; any parse error results in 0 being
returned
|
static int |
smartStringToInt(java.lang.String s,
int defaultValue)
given a string, return the int of it; any parse error results in default
being returned
|
static java.util.List<java.lang.String> |
stringToList(java.lang.String convertIn)
Using
StringTokenizer , stringToList will convert the
string to a list of individual strings based on the standard default
StringTokenizer behavior. |
static java.lang.String |
toJson(java.lang.Object obj)
Converts an object to json representation
|
static java.lang.String |
toPlainText(java.lang.String html)
Basically turns an html or xml snippet to plain text Meant to be used
along with string resources xml file messages.
|
static java.lang.String |
urlEncode(java.lang.String source)
Encode a string for use in a URL.
|
static java.lang.String |
webToLinux(java.lang.String inWebStr)
Convert an incoming web-string (with \r\n EOL) to a Linux string (with \n
as EOL)
|
public static final int SECONDS_UNITS
public static final int MINUTES_UNITS
public static final int HOURS_UNITS
public static final int DAYS_UNITS
public static final int WEEKS_UNITS
public static final int MONTHS_UNITS
public static final int YEARS_UNITS
public static java.lang.String beanify(java.lang.String strIn)
strIn
- The string to convertpublic static java.lang.String debeanify(java.lang.String strIn)
strIn
- The string to convertpublic static java.lang.String classify(java.lang.String strIn)
strIn
- The string to convert.public static int smartStringToInt(java.lang.String s)
s
- the String to convertpublic static int smartStringToInt(java.lang.String s, int defaultValue)
s
- the String to convertdefaultValue
- the default value to assign to the return value if
the String didn't parse correctlypublic static java.lang.String replaceTags(java.lang.String source, java.util.Map<java.lang.String,java.lang.String> params)
source
- the source string to be replacedparams
- the parameters to fill out the source string withpublic static java.util.List<java.lang.String> stringToList(java.lang.String convertIn)
StringTokenizer
, stringToList will convert the
string to a list of individual strings based on the standard default
StringTokenizer behavior. StringTokenizer
convertIn
- convert this string to a listpublic static java.lang.String makeRandomPassword(int lengthIn)
lengthIn
- length of random passwordpublic static java.lang.String getClassNameNoPackage(java.lang.Class clazz)
clazz
- The Class we want to get the name ofpublic static java.lang.String htmlifyText(java.lang.String convertIn)
convertIn
- the String we want to convertStringEscapeUtils
public static java.lang.String join(java.lang.String separator, java.util.Collection<java.lang.String> inputList)
separator
- The String to glue the strings in inputList together
withinputList
- The List of Strings to joinpublic static java.lang.String join(java.lang.String separator, java.util.Iterator<java.lang.String> itty)
separator
- The String separator, use
Localization.getInstance().getMessage("list delimiter")
for
the appropriate display separator.itty
- The iterator containing display items.public static java.lang.String displayFileSize(long bytes)
bytes
- the number of bytes used by a filepublic static java.lang.String displayFileSize(long bytes, boolean wholeNum)
bytes
- the number of bytes used by a filewholeNum
- should the result be returned as a whole number?public static java.lang.String categorizeTime(long target, int maxUnit, int minUnit)
target
- timestamp in msecs-since-epoch of the eventmaxUnit
- constant representing the maximum unit you want to
display.minUnit
- constant representing the minimum unit you want to
display.java.lang.IllegalArgumentException
- if maxUnit or minUnit not recognized, or
if maxUnit < minUnitpublic static java.lang.String categorizeTime(long target, int maxUnit)
target
- timestamp in msecs-since-epoch of the eventmaxUnit
- constant representing the unit you want to display. The
code will "back off" from that to show the largest non-zero unit needed
to represent the time-differencejava.lang.IllegalArgumentException
- if maxUnit not recognizedpublic static java.lang.String webToLinux(java.lang.String inWebStr)
inWebStr
- string from a web formpublic static java.lang.String urlEncode(java.lang.String source)
source
- Source string to encode.public static java.lang.String toPlainText(java.lang.String html)
<p>You donot have enough entitlements for <strong> xyz system </strong></p>will get converted to You donot have enough entitlements for xyz system It just returns the original snippet back in the case of an xml error (however it throws a warning)...
html
- html the html/xml String resources snippet to convertpublic static java.lang.String toJson(java.lang.Object obj)
obj
- any objectpublic static java.lang.Object jsonToObject(java.lang.String json)
json
- json stringpublic static java.util.Map<java.lang.String,java.lang.String> convertOptionsToMap(java.lang.String options, java.lang.String errorKey, java.lang.String separator) throws ValidatorException
options
- the string of optionserrorKey
- the localization key of the error message to throw if we
can't parse it correctlyseparator
- the separator the separates different name value pairsValidatorException
- if there isn't an '=' sign seperating the
pairspublic static java.lang.String convertMapToString(java.util.Map<java.lang.String,java.lang.Object> map, java.lang.String seperator)
map
- the map of optionsseperator
- the seperator to seperate the pairs withpublic static java.lang.String addPath(java.lang.String originalPath, java.lang.String toAdd)
originalPath
- The start of the pathtoAdd
- what to addpublic static java.lang.String getHexString(byte[] b)
b
- The byteArray of the compressedDigest streampublic static java.lang.Boolean containsInvalidXmlChars2(java.lang.String string)
string
- to checkpublic static java.lang.String getBytesTruncatedString(java.lang.String str, int length)
str
- input Stringlength
- target lengthpublic static java.lang.String nullOrValue(java.lang.String str)
str
- stringpublic static java.lang.String nullIfEmpty(java.lang.String str)
str
- stringpublic static StringUtil.ScriptCheckResult scriptPrematureCheck(java.lang.String script)
script
- Script body