Class TextUtil
java.lang.Object
de.uplanet.lucy.server.auxiliaries.TextUtil
Text utilities for the velocity context.
This class does not contain any data members and is thread-safe.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionarrayToString
(Collection<String> p_ar) Serializes an array list to a string, using default delimiter (|
) and escape character (0
).arrayToString
(Collection<String> p_ar, String p_strDel, String p_strEsc) Serializes an array list to a string.int
calcValueByPercent
(String p_iPercent, String p_iMaxValue) Calculates the percentage value of the given value.convertIsoDateTimeToXml
(String p_strValue) Deprecated.This method is flawed.customDefaultEncode
(String p_strText) JavaScript-encode some text.durationFormatter
(RenderingContext p_ctx, IValueHolder<?> p_from, IValueHolder<?> p_dtto, String p_strOneDayFormat, String p_strMoreDayFormat) Formats a date time duration.void
escForXml
(Writer p_out, CharSequence p_in) Replace <, >, &, ", and ' with their respective XML entities.escForXml
(CharSequence p_in) Replace <, >, &, ", and ' with their respective XML entities.fallbackIfNullOrEmpty
(CharSequence p_chseq, String p_strFallback) Map strings or other character sequences that arenull
or empty to a fallback value.void
filterScript
(Writer p_writer, String p_strText) Filter some text by script-tag and its content.int
getAverageColorInt
(String p_strColorHex) Calculate the average color of the given HEX color.getComplementaryColorHex
(String p_strColorHex) Get the complementary color to the given HEX formatted color.getDisplayCountry
(String p_strLangCountry, String p_strMyLang) Returns the display name of a country in the given language.getDisplayLanguage
(String p_strLang, String p_strMyLang) Returns the display name of a language in the given language.getDisplayLocale
(String p_strLangTag, String p_strMyLang) Deprecated.UsegetDisplayLanguage(String, String)
instead.getGuidsFromText
(CharSequence p_chseq) Get a distinct set of GUIDs from the given text.getNumeral
(int p_iNumber, String p_strLangId) getTextFromFile
(String p_strPath, String p_strEncoding) Get text from a file.hexToString
(String p_str) hexToString
(String p_str, String p_strCharset) htmlEncode
(String p_strText, boolean p_bInsertNbsp, boolean p_bInsertBr) HTML-encode some text.void
includeTextFromFile
(Writer p_writer, String p_strPath, String p_strEncoding) Include text from a file.javaScriptEncode
(String p_strText) The same asjavaScriptEncode(p_strText, false)
.javaScriptEncode
(String p_strText, boolean p_bEscapeLineBreaks) JavaScript-encode some text.javaScriptEncode
(String p_strText, String p_strPattern, String p_strReplacement) JavaScript-encode some text after replacing a given pattern.javaScriptEncodeFromVTL
(String p_strText) JavaScript-encode some text after replacing"
by"
.join
(Collection<?> p_coll, String p_strDelim) Join a collection using the given delimiter.jsonEncode
(Object p_value) Deprecated.UseJSONUtil.toJSONString(Object)
instead.double
parseDouble
(String p_strIn) Parse an floating point number string.double
parseDouble
(String p_strIn, double p_dblDefault) Parse an floating point number string.int
parseFloat
(String p_strIn) Deprecated.Do not use this method.int
Parse an integer number string.int
Parse an integer number string.long
Parse an integer number string.long
Parse an integer number string.prepareForTooltip
(String p_strText) prepareForTooltip
(String p_strText, boolean p_bInsertBr) prepareForTooltipHtml
(String p_strText) Get the string representation of the given object repeated the given number of times.Split a string to a list at the given delimiter.Deserialize an array with a given Delimiter.Get the string representation of the given object.Get the string representation of the given object using a fallback value in case the given value isnull
.stringToArray
(String p_str) Deserialize an array that was previously serialized usingarrayToString(java.util.Collection<java.lang.String>)
with default delimiter (|
) and escape character (0
).stringToArray
(String p_str, String p_strDel, String p_strEsc) Deserialize an array that was previously serialized usingarrayToString(java.util.Collection<java.lang.String>)
.stringToHex
(String p_str) Encode a string to it's hex representation, using the default character encoding, i.e,UTF-8
.stringToHex
(String p_str, String p_strCharset) void
undoEscForXml
(Writer p_out, CharSequence p_in) undoEscForXml
(CharSequence p_in) vhDateToXML
(de.uplanet.lucy.server.dataobjects.IDateTimeValueHolder p_vh) Returns a xsd:date representation from a given DateTimeValueHolder.vhTimeToXML
(de.uplanet.lucy.server.dataobjects.IDateTimeValueHolder p_vh) Returns a xsd:time representation from a given DateTimeValueHolder.void
writeHtmlEncoded
(Writer p_writer, String p_strText, boolean p_bInsertNbsp, boolean p_bInsertBr) Write text HTML-encoded to a stream.void
writeJavaScriptEncoded
(Writer p_writer, String p_strText) Deprecated.void
writeJavaScriptEncoded
(Writer p_writer, String p_strText, boolean p_bEscapeLineBreaks, boolean p_bDoubleEscapeQuote) Write JavaScript-encoded text to a stream.void
writeJSONEncoded
(Writer p_writer, Object p_value) Deprecated.UseJSONUtil.writeJSONString(Object, Writer)
instead.
-
Constructor Details
-
TextUtil
public TextUtil()
-
-
Method Details
-
str
Get the string representation of the given object.This method is also useful when a
String
method should be invoked on a string literal in Velocity.- Parameters:
p_obj
- The object.- Returns:
- The string representation of the given object, or
null
if the given object isnull
.
-
str
Get the string representation of the given object using a fallback value in case the given value isnull
.- Parameters:
p_obj
- The object.p_strFallback
- The fallback value.- Returns:
- The string representation of the given object, or the
fallback value if the given object is
null
.
-
repeat
Get the string representation of the given object repeated the given number of times.- Parameters:
p_obj
- The object.p_iCount
- The number of repetitions.- Returns:
- The repeated string representation of the given object,
or
null
if the given object isnull
.
-
arrayToString
Serializes an array list to a string, using default delimiter (|
) and escape character (0
).- Parameters:
p_ar
- The array list to serialize.- Returns:
- The serialized array list.
-
arrayToString
Serializes an array list to a string.- Parameters:
p_ar
- The array list to serialize.p_strDel
- The delimiter sequence to use.p_strEsc
- The escape sequence to use.- Returns:
- The serialized array list.
-
stringToArray
Deserialize an array that was previously serialized usingarrayToString(java.util.Collection<java.lang.String>)
with default delimiter (|
) and escape character (0
).- Parameters:
p_str
- The string containing the serialized array.- Returns:
- The deserialized array.
-
stringToArray
Deserialize an array that was previously serialized usingarrayToString(java.util.Collection<java.lang.String>)
.- Parameters:
p_str
- The string containing the serialized array.p_strDel
- The delimiter sequence to use.p_strEsc
- The escape sequence to use.- Returns:
- The deserialized array.
-
splitCRLF
Deserialize an array with a given Delimiter.- Parameters:
p_str
- The string containing the serialized array.- Returns:
- The deserialized array.
-
join
Join a collection using the given delimiter.Note that
join
andsplit
are not inverse functions.- Parameters:
p_coll
- The collection to be joined.p_strDelim
- The delimiter to be used.- Returns:
- The joined connection, or
null
ifp_coll
isnull
.
-
split
Split a string to a list at the given delimiter.Note that
join
andsplit
are not inverse functions.- Parameters:
p_str
- The string containing the serialized array.p_strDel
- The delimiter sequence to use.- Returns:
- The deserialized array.
-
stringToHex
Encode a string to it's hex representation, using the default character encoding, i.e,UTF-8
.- Parameters:
p_str
- The string to encode.- Returns:
- The hex representation of the string.
- Throws:
UnsupportedEncodingException
-
stringToHex
- Throws:
UnsupportedEncodingException
- See Also:
-
hexToString
- See Also:
-
hexToString
- See Also:
-
htmlEncode
HTML-encode some text.Use
writeHtmlEncoded(Writer, String, boolean, boolean)
with$Response
for large texts.- Parameters:
p_strText
- The text to encode.p_bInsertNbsp
- Flag that indicates if space characters are to be replaced with
.p_bInsertBr
- Flag that indicates ifCR
/FL
sequences are to be replaced with<br />
.
-
writeHtmlEncoded
public void writeHtmlEncoded(Writer p_writer, String p_strText, boolean p_bInsertNbsp, boolean p_bInsertBr) Write text HTML-encoded to a stream.- Parameters:
p_writer
- The stream to write to.p_strText
- The text to encode.p_bInsertNbsp
- Flag that indicates if space characters are to be replaced with
.p_bInsertBr
- Flag that indicates ifCR
/FL
sequences are to be replaced with<br />
.
-
filterScript
Filter some text by script-tag and its content.- Parameters:
p_writer
- The stream to write to.p_strText
- The text to filter.
-
javaScriptEncode
The same asjavaScriptEncode(p_strText, false)
.- Parameters:
p_strText
- The text to encode.- Returns:
- The encoded text.
- See Also:
-
javaScriptEncode
JavaScript-encode some text.- Parameters:
p_strText
- The text to encode.p_bEscapeLineBreaks
- Iftrue
,CR
s are ignored.- Returns:
- The encoded text.
- See Also:
-
customDefaultEncode
JavaScript-encode some text.- Parameters:
p_strText
- The text to encode.- Returns:
- The encoded text.
- See Also:
-
javaScriptEncode
JavaScript-encode some text after replacing a given pattern.- Parameters:
p_strText
- The text to encode.p_strPattern
- The pattern to search for.p_strReplacement
- The replacement string, if the search pattern is found.- Returns:
- The encoded text.
- See Also:
-
javaScriptEncodeFromVTL
JavaScript-encode some text after replacing"
by"
.- Parameters:
p_strText
- The text to encode.- Returns:
- The encoded text.
- See Also:
-
jsonEncode
Deprecated.UseJSONUtil.toJSONString(Object)
instead. -
writeJSONEncoded
Deprecated.UseJSONUtil.writeJSONString(Object, Writer)
instead.- Throws:
IOException
-
prepareForTooltip
-
prepareForTooltip
-
prepareForTooltipHtml
-
escForXml
Replace <, >, &, ", and ' with their respective XML entities.- Parameters:
p_in
- The input text.- Returns:
p_str
with XML markup characters replaced with their entities.- See Also:
-
escForXml
Replace <, >, &, ", and ' with their respective XML entities.- Parameters:
p_out
- The output stream to write the result to.p_in
- The input text.- Throws:
IOException
- - If an I/O error occurred.- See Also:
-
undoEscForXml
- Parameters:
p_in
- The text to encode.- Returns:
- The decoded text.
-
undoEscForXml
- Parameters:
p_out
- The output stream to write the result to.p_in
- The text to encode.- Throws:
IOException
- - If an I/O error occurred.
-
writeJavaScriptEncoded
Deprecated.The same aswriteJavaScriptEncoded(p_writer, p_strText, false)
.- Parameters:
p_writer
- The stream to write to.p_strText
- The text to encode.- See Also:
-
writeJavaScriptEncoded
public void writeJavaScriptEncoded(Writer p_writer, String p_strText, boolean p_bEscapeLineBreaks, boolean p_bDoubleEscapeQuote) Write JavaScript-encoded text to a stream.Apostrophes and backslashes are escaped by prepending a backslash.
- Parameters:
p_writer
- The stream to write to.p_strText
- The text to encode.p_bEscapeLineBreaks
- Iftrue
CR
s are ignored in the output andLF
s are escaped as\n
.
-
getNumeral
-
getDisplayLanguage
Returns the display name of a language in the given language.- Parameters:
p_strLang
- The language tag (e.g.de
, orzh
).p_strMyLang
- The target language (e.g.en
, orzh-CN
).- Returns:
- The display name of the language.
-
getDisplayCountry
Returns the display name of a country in the given language.- Parameters:
p_strLangCountry
- The language tag (e.g.de-DE
, orde-CH
).p_strMyLang
- The target language (e.g.de
, oren
).- Returns:
- The display name of the language.
-
getDisplayLocale
Deprecated.UsegetDisplayLanguage(String, String)
instead.Returns the locale display name for the given language tag in the given language.- Parameters:
p_strLangTag
- The locale language tag (e.g. de-DE).p_strMyLang
- The target language (e.g. en).- Returns:
- The locale display name.
-
parseInt
Parse an integer number string.- Parameters:
p_strIn
- The string to parse.p_iDefault
- On error return this.- Returns:
- The parsed integer as
int
, or the given fallback if the input could not be parsed.
-
parseInt
Parse an integer number string.- Parameters:
p_strIn
- The string to parse.- Returns:
- The parsed integer as
int
.
-
parseLong
Parse an integer number string.- Parameters:
p_strIn
- The string to parse.p_lDefault
- On error return this.- Returns:
- The parsed integer as
long
, or the given fallback if the input could not be parsed.
-
parseLong
Parse an integer number string.- Parameters:
p_strIn
- The string to parse.- Returns:
- The parsed integer as
long
, or0
if the input could not be parsed.
-
parseDouble
Parse an floating point number string.- Parameters:
p_strIn
- The string to parse.p_dblDefault
- On error return this.- Returns:
- The parsed floating point number as
double
.
-
parseDouble
Parse an floating point number string.- Parameters:
p_strIn
- The string to parse.- Returns:
- The parsed floating point number as
double
, or0
if the input could not be parsed.
-
parseFloat
Deprecated.Do not use this method. -
getGuidsFromText
Get a distinct set of GUIDs from the given text.Note that the order of GUIDs within the text is not preserved in the result.
- Parameters:
p_chseq
- The text to extract GUIDs from.- Returns:
- The (possibly empty) set of GUIDs.
-
calcValueByPercent
Calculates the percentage value of the given value.- Parameters:
p_iPercent
- The percentage value.p_iMaxValue
- The value to calculate the percentage for.- Returns:
- The calculated percentage value.
-
getComplementaryColorHex
Get the complementary color to the given HEX formatted color.- Parameters:
p_strColorHex
- The HEX formatted color.- Returns:
- The complementary color.
-
getAverageColorInt
Calculate the average color of the given HEX color.- Parameters:
p_strColorHex
- The HEX formatted color.- Returns:
- The average color value.
-
convertIsoDateTimeToXml
Deprecated.This method is flawed. Do not use it.Converts an ISO dateTime string (yyyy-MM-dd HH:mm:ss) to yyyy-MM-ddTHH:mm:ssZ using the current TimeZone for UTC transformation.- Parameters:
p_strValue
- ISO datetime string.- Returns:
- The XML conform datetime string in UTC format or an empty string if p_strValue is empty or not an valid ISO dateTime string.
-
vhDateToXML
Returns a xsd:date representation from a given DateTimeValueHolder.- Parameters:
p_vh
- DateTimeValueHolder (must not be null).- Returns:
- A XML xs:date value from a DateTimeValueHolder.
-
vhTimeToXML
Returns a xsd:time representation from a given DateTimeValueHolder.- Parameters:
p_vh
- DateTimeValueHolder (must not be null).- Returns:
- A XML xs:time value from a DateTimeValueHolder.
-
getTextFromFile
Get text from a file.- Parameters:
p_strPath
- The path to the file, relative to the portal directory.p_strEncoding
- The file encoding.- Throws:
IOException
- If an I/O error occurred.
-
includeTextFromFile
public void includeTextFromFile(Writer p_writer, String p_strPath, String p_strEncoding) throws IOException Include text from a file.- Parameters:
p_writer
- The stream to write to.p_strPath
- The path to the file, relative to the portal directory.p_strEncoding
- The file encoding.- Throws:
IOException
- If an I/O error occurred.
-
durationFormatter
public String durationFormatter(RenderingContext p_ctx, IValueHolder<?> p_from, IValueHolder<?> p_dtto, String p_strOneDayFormat, String p_strMoreDayFormat) Formats a date time duration.- Parameters:
p_ctx
- The rendering contextp_from
- The from date time value holderp_dtto
- The to date time value holderp_strOneDayFormat
- The format, used when the from and to date is on the same day. ($from, $to will be replaced by the formatted datetime or time string).p_strMoreDayFormat
- The format, used when the from and to date is not on the same day. ($from, $to will be replaced by the formatted datetime strings).- Returns:
- The formatted duration string.
-
fallbackIfNullOrEmpty
Map strings or other character sequences that arenull
or empty to a fallback value.- Parameters:
p_chseq
- The character sequence to be checked.p_strFallback
- The fallback value.- Returns:
p_chseq
if this value is neithernull
nor empty, or the fallback value otherwise.
-