de.uplanet.lucy.server.auxiliaries
Class TextUtil

java.lang.Object
  extended by de.uplanet.lucy.server.auxiliaries.TextUtil

@VelocityCallable(value="singleton")
public final class TextUtil
extends java.lang.Object

Text utilities for the velocity context. This class does not contain any data members and is thread-safe.

Version:
$Revision: 79300 $

Constructor Summary
TextUtil()
           
 
Method Summary
 java.lang.String arrayToString(java.util.Collection<java.lang.String> p_ar)
          Serializes an array list to a string, using default delimiter (|) and escape character (0).
 java.lang.String arrayToString(java.util.Collection<java.lang.String> p_ar, java.lang.String p_strDel, java.lang.String p_strEsc)
          Serializes an array list to a string.
 int calcValueByPercent(java.lang.String p_iPercent, java.lang.String p_iMaxValue)
          calcValueByPercent
 java.lang.String convertIsoDateTimeToXml(java.lang.String p_strValue)
          converts an ISO DateTime String (yyyy-MM-dd HH:mm:ss) to yyy-MM-ddTHH:mm:ssZ uses the actual TimeZone for transforming to UTC
 java.lang.String customDefaultEncode(java.lang.String p_strText)
          JavaScript-encode some text.
 java.lang.StringBuilder escForXml(java.lang.CharSequence p_in)
          Replace <, >, &, ", and ' with their respective XML entities.
 void escForXml(java.io.Writer p_out, java.lang.CharSequence p_in)
          Replace <, >, &, ", and ' with their respective XML entities.
 void filterScript(java.io.Writer p_writer, java.lang.String p_strText)
          filter some text by script-Tag and its content.
 int getAverageColorInt(java.lang.String p_strColorHex)
          get Average Color
 java.lang.String getComplementaryColorHex(java.lang.String p_strColorHex)
          get Complentary Color Hex formated
 java.lang.String getDisplayLanguage(java.lang.String p_strLang, java.lang.String p_strMyLang)
           
 java.lang.String getNumeral(int p_iNumber, java.lang.String p_strLangId)
           
 java.lang.String hexToString(java.lang.String p_str)
           
 java.lang.String hexToString(java.lang.String p_str, java.lang.String p_strCharset)
           
 java.lang.String htmlEncode(java.lang.String p_strText, boolean p_bInsertNbsp, boolean p_bInsertBr)
          HTML-encode some text.
 java.lang.String javaScriptEncode(java.lang.String p_strText)
          The same as javaScriptEncode(p_strText, false).
 java.lang.String javaScriptEncode(java.lang.String p_strText, boolean p_bEscapeLineBreaks)
          JavaScript-encode some text.
 java.lang.String javaScriptEncode(java.lang.String p_strText, java.lang.String p_strPattern, java.lang.String p_strReplacement)
          JavaScript-encode some text after replacing a given pattern.
 java.lang.String javaScriptEncodeFromVTL(java.lang.String p_strText)
          JavaScript-encode some text after replacing """ by """.
 java.lang.String join(java.util.Collection<?> p_coll, java.lang.String p_strDelim)
          Join a collection using the given delimiter.
 java.lang.String jsonEncode(java.lang.Object p_value)
          Get a JSON encoded value literal.
 double parseDouble(java.lang.String p_strIn)
           
 double parseDouble(java.lang.String p_strIn, double p_dblDefault)
           
 int parseFloat(java.lang.String p_strIn)
          Parse Float.
 int parseInt(java.lang.String p_strIn)
          Parse an integer number string.
 int parseInt(java.lang.String p_strIn, int p_iDefault)
          Parse Integer.
 long parseLong(java.lang.String p_strIn)
          Parse an integer number string.
 java.lang.String prepareForTooltip(java.lang.String p_strText)
           
 java.lang.String prepareForTooltip(java.lang.String p_strText, boolean p_bInsertBr)
           
 java.lang.String prepareForTooltipHtml(java.lang.String p_strText)
           
 java.util.List<java.lang.String> split(java.lang.String p_str, java.lang.String p_strDel)
          Split a string to a list at the given delimiter.
 java.util.List<java.lang.String> splitCRLF(java.lang.String p_str)
          Deserialize an array with a given Delimiter.
 java.util.List<java.lang.String> stringToArray(java.lang.String p_str)
          Deserialize an array that was previously serialized using arrayToString(java.util.Collection) with default delimiter (|) and escape character (0).
 java.util.List<java.lang.String> stringToArray(java.lang.String p_str, java.lang.String p_strDel, java.lang.String p_strEsc)
          Deserialize an array that was previously serialized using arrayToString(java.util.Collection).
 java.lang.String stringToHex(java.lang.String p_str)
          Encode a string to it's hex representation, using the default character encoding, i.e, UTF-8.
 java.lang.String stringToHex(java.lang.String p_str, java.lang.String p_strCharset)
           
 java.lang.StringBuilder undoEscForXml(java.lang.CharSequence p_in)
           
 void undoEscForXml(java.io.Writer p_out, java.lang.CharSequence p_in)
           
 java.lang.String vhDateToXML(de.uplanet.lucy.server.dataobjects.IDateTimeValueHolder p_vh)
          returns an xsd:date representation from a DateTimeValueHolder value
 java.lang.String vhTimeToXML(de.uplanet.lucy.server.dataobjects.IDateTimeValueHolder p_vh)
          returns an xsd:time representation from a DateTimeValueHolder value
 void writeHtmlEncoded(java.io.Writer p_writer, java.lang.String p_strText, boolean p_bInsertNbsp, boolean p_bInsertBr)
          Write text HTML-encoded to a stream.
 void writeJavaScriptEncoded(java.io.Writer p_writer, java.lang.String p_strText)
          Deprecated. Use #writeJavaScriptEncoded(Writer, String, Boolean, Boolean) instead.
 void writeJavaScriptEncoded(java.io.Writer p_writer, java.lang.String p_strText, boolean p_bEscapeLineBreaks, boolean p_bDoubleEscapeQuote)
          Write JavaScript-encoded text to a stream.
 void writeJSONEncoded(java.io.Writer p_writer, java.lang.Object p_value)
          Write a JSON encoded value literal.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtil

public TextUtil()
Method Detail

arrayToString

public java.lang.String arrayToString(java.util.Collection<java.lang.String> p_ar)
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

public java.lang.String arrayToString(java.util.Collection<java.lang.String> p_ar,
                                      java.lang.String p_strDel,
                                      java.lang.String p_strEsc)
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

public java.util.List<java.lang.String> stringToArray(java.lang.String p_str)
Deserialize an array that was previously serialized using arrayToString(java.util.Collection) with default delimiter (|) and escape character (0).

Parameters:
p_str - The string containing the serialized array.
Returns:
The deserialized array.

stringToArray

public java.util.List<java.lang.String> stringToArray(java.lang.String p_str,
                                                      java.lang.String p_strDel,
                                                      java.lang.String p_strEsc)
Deserialize an array that was previously serialized using arrayToString(java.util.Collection).

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.
To Do:
Improve performance and get rid of references to StringHelper.

splitCRLF

public java.util.List<java.lang.String> splitCRLF(java.lang.String p_str)
Deserialize an array with a given Delimiter.

Parameters:
p_str - The string containing the serialized array.
Returns:
The deserialized array.

join

public java.lang.String join(java.util.Collection<?> p_coll,
                             java.lang.String p_strDelim)
Join a collection using the given delimiter.

Note that join and split 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 if p_coll is null.

split

public java.util.List<java.lang.String> split(java.lang.String p_str,
                                              java.lang.String p_strDel)
Split a string to a list at the given delimiter.

Note that join and split 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

public java.lang.String stringToHex(java.lang.String p_str)
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.

stringToHex

public java.lang.String stringToHex(java.lang.String p_str,
                                    java.lang.String p_strCharset)
See Also:
Codec.hexEncodeString(String, String)

hexToString

public java.lang.String hexToString(java.lang.String p_str)
See Also:
Codec.hexDecodeString(String)

hexToString

public java.lang.String hexToString(java.lang.String p_str,
                                    java.lang.String p_strCharset)
See Also:
Codec.hexDecodeString(String, String)

htmlEncode

public java.lang.String htmlEncode(java.lang.String p_strText,
                                   boolean p_bInsertNbsp,
                                   boolean p_bInsertBr)
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 &nbsp;.
p_bInsertBr - Flag that indicates if CR/FL sequences are to be replaced with <br />.

writeHtmlEncoded

public void writeHtmlEncoded(java.io.Writer p_writer,
                             java.lang.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 &nbsp;.
p_bInsertBr - Flag that indicates if CR/FL sequences are to be replaced with <br />.

filterScript

public void filterScript(java.io.Writer p_writer,
                         java.lang.String p_strText)
filter some text by script-Tag and its content.

Parameters:
p_writer - The stream to write to.
p_strText - The text to filter.

javaScriptEncode

public java.lang.String javaScriptEncode(java.lang.String p_strText)
The same as javaScriptEncode(p_strText, false).

Parameters:
p_strText - The text to encode.
Returns:
The encoded text.
See Also:
writeJavaScriptEncoded(Writer, String)

javaScriptEncode

public java.lang.String javaScriptEncode(java.lang.String p_strText,
                                         boolean p_bEscapeLineBreaks)
JavaScript-encode some text.

Parameters:
p_strText - The text to encode.
p_bEscapeLineBreaks - If true CRs are ignored
Returns:
The encoded text.
See Also:
writeJavaScriptEncoded(Writer, String)

customDefaultEncode

public java.lang.String customDefaultEncode(java.lang.String p_strText)
JavaScript-encode some text.

Parameters:
p_strText - The text to encode.
Returns:
The encoded text.
See Also:
writeJavaScriptEncoded(Writer, String)

javaScriptEncode

public java.lang.String javaScriptEncode(java.lang.String p_strText,
                                         java.lang.String p_strPattern,
                                         java.lang.String p_strReplacement)
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 - Te replacement for the patterns found.
Returns:
The encoded text.
See Also:
writeJavaScriptEncoded(Writer, String)

javaScriptEncodeFromVTL

public java.lang.String javaScriptEncodeFromVTL(java.lang.String p_strText)
JavaScript-encode some text after replacing """ by """.

Parameters:
p_strText - The text to encode.
Returns:
The encoded text.
See Also:
writeJavaScriptEncoded(Writer, String)

jsonEncode

public java.lang.String jsonEncode(java.lang.Object p_value)
                            throws java.io.IOException
Get a JSON encoded value literal.

Parameters:
p_value - The value.
Returns:
A JSON literal that represents p_value.
Throws:
java.io.IOException - If an I/O error occurred.
See Also:
writeJSONEncoded(Writer, Object)

writeJSONEncoded

public void writeJSONEncoded(java.io.Writer p_writer,
                             java.lang.Object p_value)
                      throws java.io.IOException
Write a JSON encoded value literal.

Supported values are

Parameters:
p_writer - The output stream.
p_value - The value to be written.
Throws:
java.io.IOException - If an I/O error occurred.

prepareForTooltip

public java.lang.String prepareForTooltip(java.lang.String p_strText)

prepareForTooltip

public java.lang.String prepareForTooltip(java.lang.String p_strText,
                                          boolean p_bInsertBr)

prepareForTooltipHtml

public java.lang.String prepareForTooltipHtml(java.lang.String p_strText)

escForXml

public java.lang.StringBuilder escForXml(java.lang.CharSequence p_in)
                                  throws java.io.IOException
Replace <, >, &, ", and ' with their respective XML entities.

Parameters:
p_in - The input text.
Returns:
p_str with XML markup characters replaced with their entities.
Throws:
java.io.IOException - - If an I/O error occurred.
See Also:
XmlMarkupEncoder

escForXml

public void escForXml(java.io.Writer p_out,
                      java.lang.CharSequence p_in)
               throws java.io.IOException
Replace <, >, &, ", and ' with their respective XML entities.

Parameters:
p_out - The output stream to write the result to.
p_in - The input text.
Throws:
java.io.IOException - - If an I/O error occurred.
See Also:
XmlMarkupEncoder

undoEscForXml

public java.lang.StringBuilder undoEscForXml(java.lang.CharSequence p_in)
                                      throws java.io.IOException
Parameters:
p_in - The text to encode.
Returns:
The decoded text.
Throws:
java.io.IOException - - This exception actually will never be thrown.

undoEscForXml

public void undoEscForXml(java.io.Writer p_out,
                          java.lang.CharSequence p_in)
                   throws java.io.IOException
Parameters:
p_out - The output stream to write the result to.
p_in - The text to encode.
Throws:
java.io.IOException - - If an I/O error occurred.

writeJavaScriptEncoded

@Deprecated
public void writeJavaScriptEncoded(java.io.Writer p_writer,
                                              java.lang.String p_strText)
Deprecated. Use #writeJavaScriptEncoded(Writer, String, Boolean, Boolean) instead.

The same as writeJavaScriptEncoded(p_writer, p_strText, false).

Parameters:
p_writer - The stream to write to.
p_strText - The text to encode.
See Also:
writeJavaScriptEncoded(Writer, String, boolean, boolean)

writeJavaScriptEncoded

public void writeJavaScriptEncoded(java.io.Writer p_writer,
                                   java.lang.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

public java.lang.String getNumeral(int p_iNumber,
                                   java.lang.String p_strLangId)

getDisplayLanguage

public java.lang.String getDisplayLanguage(java.lang.String p_strLang,
                                           java.lang.String p_strMyLang)

parseInt

public int parseInt(java.lang.String p_strIn,
                    int p_iDefault)
Parse Integer.

Parameters:
p_strIn - The text to parse.
p_iDefault - On error return this.

parseInt

public int parseInt(java.lang.String p_strIn)
Parse an integer number string.

Parameters:
p_strIn - The text to parse.

parseLong

public long parseLong(java.lang.String p_strIn)
Parse an integer number string.

Parameters:
p_strIn - The text to parse.

parseDouble

public double parseDouble(java.lang.String p_strIn,
                          double p_dblDefault)
Parameters:
p_strIn - The text to parse.
p_dblDefault - On error return this.

parseDouble

public double parseDouble(java.lang.String p_strIn)
Parameters:
p_strIn - The text to parse.
Returns:
The parsed value as a double, or 0 if the input could not be parsed.

parseFloat

public int parseFloat(java.lang.String p_strIn)
Parse Float.

Parameters:
p_strIn - The text to parse.

calcValueByPercent

public int calcValueByPercent(java.lang.String p_iPercent,
                              java.lang.String p_iMaxValue)
calcValueByPercent

Parameters:
p_iPercent - percent value
p_iMaxValue - max value

getComplementaryColorHex

public java.lang.String getComplementaryColorHex(java.lang.String p_strColorHex)
get Complentary Color Hex formated

Parameters:
p_strColorHex - The text to convert.

getAverageColorInt

public int getAverageColorInt(java.lang.String p_strColorHex)
get Average Color

Parameters:
p_strColorHex - The text to convert.

convertIsoDateTimeToXml

public java.lang.String convertIsoDateTimeToXml(java.lang.String p_strValue)
converts an ISO DateTime String (yyyy-MM-dd HH:mm:ss) to yyy-MM-ddTHH:mm:ssZ uses the actual TimeZone for transforming to UTC

Parameters:
p_strValue - if null or empty
Returns:
the xml conform datetime string in UTC or an empty string if p_strValue is empty or not an valid iso date time string

vhDateToXML

public java.lang.String vhDateToXML(de.uplanet.lucy.server.dataobjects.IDateTimeValueHolder p_vh)
returns an xsd:date representation from a DateTimeValueHolder value

Parameters:
p_vh - Datetime valueHolder must not be null
Returns:
a xml xs:date value from a DateTimeValueHolder

vhTimeToXML

public java.lang.String vhTimeToXML(de.uplanet.lucy.server.dataobjects.IDateTimeValueHolder p_vh)
returns an xsd:time representation from a DateTimeValueHolder value

Parameters:
p_vh - datetime valueholder (must not be null)
Returns:
a xml xs:time value from a DateTimeValueHolder


Last updated: 2011-01-27
Copyright 2000-2010 United Planet. All Rights Reserved.