|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.riotfamily.common.util.FormatUtils
public final class FormatUtils
Utility class that provides some simple text formatting methods.
Method Summary | |
---|---|
static String |
camelToTitleCase(String s)
camelCase -> Camel Case CamelCASE -> Camel CASE Cam31Case -> Cam 31 Case |
static String |
camelToXmlCase(String s)
CamelCase -> camel-case camelCASE -> camel-case |
static String |
combine(String... s)
"a", "b", "c" -> "a b c a-b a-b-c" "a", "b", null -> "a b a-b" |
static String |
escapeChars(String s,
String chars,
char escape)
|
static int |
extractInt(String s,
String regex)
Extracts an integer from a String using the first capture group of the given regular expression. |
static String |
fileNameToTitleCase(String s)
foo.bar -> Foo Bar foo-foo_bar -> Foo Foo Bar foo.barBar -> Foo Bar Bar |
static String |
formatByteSize(long bytes)
Returns a formatted string using an appropriate unit (Bytes, KB or MB). |
static String |
formatDate(Date date,
String pattern,
Locale locale)
|
static String |
formatIsoDate(Date date)
|
static String |
formatMediumDate(Date date,
Locale locale)
|
static String |
formatMillis(long millis)
Returns a formatted string using the pattern hh:mm:ss. |
static String |
formatNumber(Number number,
String pattern,
Locale locale)
|
static String |
getDateDelimiter(String dateFormat)
Returns the date delimiter for the given date format Examples: "MM/DD/YYYY" - "/" "DD.MM.YYYY" - ". |
static String |
getDateFormat(Locale locale)
Returns the date format for the given locale. |
static String |
getExtension(String filename)
Returns the extension of the given filename. |
static Object[] |
htmlEscapeArgs(Object[] args)
Escapes all XML special characters in the given array. |
static String |
join(String delimiter,
String... parts)
|
static Date |
parseDate(String s)
Parses a formatted String and returns the date. |
static long |
parseMillis(String s)
Parses a formatted String and returns the value in milliseconds. |
static String |
propertyToTitleCase(String s)
foo.bar -> Foo Bar foo.barBar -> Foo Bar Bar |
static String |
repeat(String s,
int times)
Repeats a String the given number of times. |
static String |
sanitizePath(String s)
Calls StringUtils.cleanPath(String) and removes all occurrences
of "../". |
static String |
stripExtension(String filename)
Returns the the filename without it's extension. |
static String |
stripLeadingSlash(String path)
Returns the the path without a leading slash. |
static String |
stripTags(String s)
Removes all markup from the given String using the pattern "</? |
static String |
stripTagsAndSpaces(String s)
Convenience method that strips tags and whitespaces. |
static String |
stripTrailingSlash(String path)
Returns the the path without a trailing slash. |
static String |
stripWhitespaces(String s)
Strips whitespaces without preserving line breaks. |
static String |
stripWhitespaces(String s,
boolean preserveBreaks)
Replaces consecutive whitespaces by a single space character. |
static String |
toCssClass(String s)
Converts the given String into a valid CSS class name. |
static String |
toFilename(String s)
Invokes toLowerCase(), converts all whitespaces to underscores and removes all characters other than a-z, 0-9, dot, underscore or minus. |
static String |
truncate(String s,
int length)
Truncates the given String if its length exceeds the specified value. |
static String |
uriEscape(String input)
Translates the given string into application/x-www-form-urlencoded format using UTF-8 as encoding scheme. |
static String |
uriEscapePath(String input)
Translates the given path into application/x-www-form-urlencoded format using UTF-8 as encoding scheme. |
static String |
uriUnescape(String input)
Decodes the given application/x-www-form-urlencoded string using UTF-8 as encoding scheme. |
static String |
xmlEscape(String input)
Turn special characters into escaped characters conforming to XML. |
static String |
xmlEscapeDanglingAmps(String s)
XML-escapes dangling ampersands that are no entities. |
static String |
xmlToCamelCase(String s)
foo-bar -> fooBar Foo-bAR -> FooBAR |
static String |
xmlToTitleCase(String s)
foo-bar -> Foo Bar fooBar -> Foo Bar |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static String formatNumber(Number number, String pattern, Locale locale)
public static String formatByteSize(long bytes)
public static String camelToTitleCase(String s)
camelCase -> Camel Case CamelCASE -> Camel CASE Cam31Case -> Cam 31 Case
public static String xmlToCamelCase(String s)
foo-bar -> fooBar Foo-bAR -> FooBAR
public static String xmlToTitleCase(String s)
foo-bar -> Foo Bar fooBar -> Foo Bar
public static String propertyToTitleCase(String s)
foo.bar -> Foo Bar foo.barBar -> Foo Bar Bar
public static String fileNameToTitleCase(String s)
foo.bar -> Foo Bar foo-foo_bar -> Foo Foo Bar foo.barBar -> Foo Bar Bar
public static String camelToXmlCase(String s)
CamelCase -> camel-case camelCASE -> camel-case
public static String join(String delimiter, String... parts)
public static String combine(String... s)
public static String truncate(String s, int length)
public static String toCssClass(String s)
public static long parseMillis(String s)
s - seconds m - minutes h - hours D - days W - weeks M - months Y - years
public static String formatMillis(long millis)
public static String getExtension(String filename)
"foo.bar" - "bar" "/some/file.name.foo" - "foo"The following examples will return an empty String:
"foo" "foo." "/dir.with.dots/file" ".bar" "/foo/.bar"
public static String stripExtension(String filename)
public static String stripLeadingSlash(String path)
public static String stripTrailingSlash(String path)
public static Date parseDate(String s)
D - days W - weeks M - months Y - yearsDays is option, any number without a suffix is treated as a number of days
public static String formatDate(Date date, String pattern, Locale locale)
public static String formatMediumDate(Date date, Locale locale)
public static String formatIsoDate(Date date)
public static String getDateFormat(Locale locale)
Locale.ENGLISH - "MM/DD/YYYY" Locale.GERMAN - "DD.MM.YYYY"
public static String getDateDelimiter(String dateFormat)
"MM/DD/YYYY" - "/" "DD.MM.YYYY" - "."
public static String toFilename(String s)
public static String xmlEscape(String input)
input
- the input string
public static String escapeChars(String s, String chars, char escape)
public static String uriEscape(String input)
public static String uriEscapePath(String input)
uriEscape(String)
} that path component separators (/) are
not encoded.
uriEscape(String)
public static String uriUnescape(String input)
public static Object[] htmlEscapeArgs(Object[] args)
xmlEscape(String)
.
public static int extractInt(String s, String regex)
public static String stripWhitespaces(String s)
stripWhitespaces(String, boolean)
public static String stripWhitespaces(String s, boolean preserveBreaks)
s
- The String to tidy uppreserveBreaks
- Whether line breaks should be preservedpublic static String xmlEscapeDanglingAmps(String s)
public static String stripTags(String s)
"</?[^>]+>"
.
public static String stripTagsAndSpaces(String s)
stripTags(String)
,
stripWhitespaces(String)
public static String sanitizePath(String s)
StringUtils.cleanPath(String)
and removes all occurrences
of "../".
public static String repeat(String s, int times)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |