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 SummaryConstructors
- 
Method SummaryModifier 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.intcalcValueByPercent(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(de.uplanet.lucy.server.renderer.RenderingContext p_ctx, de.uplanet.lucy.server.dataobjects.IValueHolder<?> p_from, de.uplanet.lucy.server.dataobjects.IValueHolder<?> p_dtto, String p_strOneDayFormat, String p_strMoreDayFormat) Formats a date time duration.voidescForXml(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 arenullor empty to a fallback value.voidfilterScript(Writer p_writer, String p_strText) Filter some text by script-tag and its content.intgetAverageColorInt(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.voidincludeTextFromFile(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.doubleparseDouble(String p_strIn) Parse an floating point number string.doubleparseDouble(String p_strIn, double p_dblDefault) Parse an floating point number string.intparseFloat(String p_strIn) Deprecated.Do not use this method.intParse an integer number string.intParse an integer number string.longParse an integer number string.longParse 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) voidundoEscForXml(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.voidwriteHtmlEncoded(Writer p_writer, String p_strText, boolean p_bInsertNbsp, boolean p_bInsertBr) Write text HTML-encoded to a stream.voidwriteJavaScriptEncoded(Writer p_writer, String p_strText) Deprecated.voidwriteJavaScriptEncoded(Writer p_writer, String p_strText, boolean p_bEscapeLineBreaks, boolean p_bDoubleEscapeQuote) Write JavaScript-encoded text to a stream.voidwriteJSONEncoded(Writer p_writer, Object p_value) Deprecated.UseJSONUtil.writeJSONString(Object, Writer)instead.
- 
Constructor Details- 
TextUtilpublic TextUtil()
 
- 
- 
Method Details- 
strGet the string representation of the given object.This method is also useful when a Stringmethod should be invoked on a string literal in Velocity.- Parameters:
- p_obj- The object.
- Returns:
- The string representation of the given object, or
    nullif the given object isnull.
 
- 
strGet 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.
 
- 
repeatGet 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 nullif the given object isnull.
 
- 
arrayToStringSerializes 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.
 
- 
arrayToStringSerializes 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.
 
- 
stringToArrayDeserialize 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.
 
- 
stringToArrayDeserialize 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.
 
- 
splitCRLFDeserialize an array with a given Delimiter.- Parameters:
- p_str- The string containing the serialized array.
- Returns:
- The deserialized array.
 
- 
joinJoin a collection using the given delimiter.Note that joinandsplitare not inverse functions.- Parameters:
- p_coll- The collection to be joined.
- p_strDelim- The delimiter to be used.
- Returns:
- The joined connection, or nullifp_collisnull.
 
- 
splitSplit a string to a list at the given delimiter.Note that joinandsplitare not inverse functions.- Parameters:
- p_str- The string containing the serialized array.
- p_strDel- The delimiter sequence to use.
- Returns:
- The deserialized array.
 
- 
stringToHexEncode 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:
 
- 
htmlEncodeHTML-encode some text.Use writeHtmlEncoded(Writer, String, boolean, boolean)with$Responsefor 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 if- CR/- FLsequences are to be replaced with- <br />.
 
- 
writeHtmlEncodedpublic 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 if- CR/- FLsequences are to be replaced with- <br />.
 
- 
filterScriptFilter some text by script-tag and its content.- Parameters:
- p_writer- The stream to write to.
- p_strText- The text to filter.
 
- 
javaScriptEncodeThe same asjavaScriptEncode(p_strText, false).- Parameters:
- p_strText- The text to encode.
- Returns:
- The encoded text.
- See Also:
 
- 
javaScriptEncodeJavaScript-encode some text.- Parameters:
- p_strText- The text to encode.
- p_bEscapeLineBreaks- If- true,- CRs are ignored.
- Returns:
- The encoded text.
- See Also:
 
- 
customDefaultEncodeJavaScript-encode some text.- Parameters:
- p_strText- The text to encode.
- Returns:
- The encoded text.
- See Also:
 
- 
javaScriptEncodeJavaScript-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:
 
- 
javaScriptEncodeFromVTLJavaScript-encode some text after replacing"by".- Parameters:
- p_strText- The text to encode.
- Returns:
- The encoded text.
- See Also:
 
- 
jsonEncodeDeprecated.UseJSONUtil.toJSONString(Object)instead.
- 
writeJSONEncodedDeprecated.UseJSONUtil.writeJSONString(Object, Writer)instead.- Throws:
- IOException
 
- 
prepareForTooltip
- 
prepareForTooltip
- 
prepareForTooltipHtml
- 
escForXmlReplace <, >, &, ", and ' with their respective XML entities.- Parameters:
- p_in- The input text.
- Returns:
- p_strwith XML markup characters replaced with their entities.
- See Also:
- 
- XmlMarkupEncoder
 
 
- 
escForXmlReplace <, >, &, ", 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:
- 
- XmlMarkupEncoder
 
 
- 
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.
 
- 
writeJavaScriptEncodedDeprecated.The same aswriteJavaScriptEncoded(p_writer, p_strText, false).- Parameters:
- p_writer- The stream to write to.
- p_strText- The text to encode.
- See Also:
 
- 
writeJavaScriptEncodedpublic 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- If- true- CRs are ignored in the output and- LFs are escaped as- \n.
 
- 
getNumeral
- 
getDisplayLanguageReturns the display name of a language in the given language.- Parameters:
- p_strLang- The language tag (e.g.- de, or- zh).
- p_strMyLang- The target language (e.g.- en, or- zh-CN).
- Returns:
- The display name of the language.
 
- 
getDisplayCountryReturns the display name of a country in the given language.- Parameters:
- p_strLangCountry- The language tag (e.g.- de-DE, or- de-CH).
- p_strMyLang- The target language (e.g.- de, or- en).
- Returns:
- The display name of the language.
 
- 
getDisplayLocaleDeprecated.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.
 
- 
parseIntParse 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.
 
- 
parseIntParse an integer number string.- Parameters:
- p_strIn- The string to parse.
- Returns:
- The parsed integer as int.
 
- 
parseLongParse 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.
 
- 
parseLongParse an integer number string.- Parameters:
- p_strIn- The string to parse.
- Returns:
- The parsed integer as long, or0if the input could not be parsed.
 
- 
parseDoubleParse 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.
 
- 
parseDoubleParse an floating point number string.- Parameters:
- p_strIn- The string to parse.
- Returns:
- The parsed floating point number as double, or0if the input could not be parsed.
 
- 
parseFloatDeprecated.Do not use this method.
- 
getGuidsFromTextGet 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.
 
- 
calcValueByPercentCalculates 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.
 
- 
getComplementaryColorHexGet the complementary color to the given HEX formatted color.- Parameters:
- p_strColorHex- The HEX formatted color.
- Returns:
- The complementary color.
 
- 
getAverageColorIntCalculate the average color of the given HEX color.- Parameters:
- p_strColorHex- The HEX formatted color.
- Returns:
- The average color value.
 
- 
convertIsoDateTimeToXmlDeprecated.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.
 
- 
vhDateToXMLReturns 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.
 
- 
vhTimeToXMLReturns 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.
 
- 
getTextFromFileGet 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.
 
- 
includeTextFromFilepublic 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.
 
- 
durationFormatterpublic String durationFormatter(de.uplanet.lucy.server.renderer.RenderingContext p_ctx, de.uplanet.lucy.server.dataobjects.IValueHolder<?> p_from, de.uplanet.lucy.server.dataobjects.IValueHolder<?> p_dtto, String p_strOneDayFormat, String p_strMoreDayFormat) Formats a date time duration.- Parameters:
- p_ctx- The rendering context
- p_from- The from date time value holder
- p_dtto- The to date time value holder
- p_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.
 
- 
fallbackIfNullOrEmptyMap strings or other character sequences that arenullor empty to a fallback value.- Parameters:
- p_chseq- The character sequence to be checked.
- p_strFallback- The fallback value.
- Returns:
- p_chseqif this value is neither- nullnor empty, or the fallback value otherwise.
 
 
-