com.dynamide.util
Class StringTools

java.lang.Object
  extended by com.dynamide.util.StringTools

public class StringTools
extends java.lang.Object


Field Summary
static java.lang.String CR
           
static java.lang.String CRLF
           
static java.lang.String LF
           
static int PAD_CENTER
           
static int PAD_LEFT
           
static int PAD_RIGHT
           
static int SUBSTRING_END
           
 
Constructor Summary
StringTools()
           
 
Method Summary
static void checkSQLSafe(java.lang.String value)
           
static java.lang.String decodeBytea(java.lang.Object o)
           
static java.lang.String dm_nbsp(java.lang.String source)
           
static java.lang.String ellipses(java.lang.String source, int maxLength)
           
static java.lang.String escape(java.lang.String msg)
          Does NOT escape ampersands -- use escapeAmpersands for that, either before or after calling this function.
static java.lang.String escapeAmpersands(java.lang.String msg)
           
static java.lang.String escapeForJavascript(java.lang.String msg)
           
static java.lang.String escapeForPostgres(java.lang.String val)
           
static java.lang.String escapeForWebmacro(java.lang.String msg)
           
static java.lang.String fill(char fillChar, int width)
           
static java.lang.String fill(java.lang.String fillString, int width)
           
static java.lang.String identifier(java.lang.String source)
           
static java.lang.String indent(java.lang.String body, int indent, java.lang.String width, int padding)
          Indents a block by wrapping it in an HTML TABLE tag, with two columns, the left column being the indent width, in pixels.
static java.lang.String indent(java.lang.String body, int indent, java.lang.String tablewidth, int padding, java.lang.String imageLocation)
          Indents a block by wrapping it in an HTML TABLE tag, similar to indent(String,int,String), but allows you to specify the location of the transparent image used to fill the indent cell.
static boolean isEmpty(java.lang.String in)
           
static boolean isValidXHTML(java.lang.String src)
           
static void main(java.lang.String[] args)
           
static java.lang.String makeLineNumbers(java.lang.String source)
           
static java.lang.String makeLineNumbers(java.lang.String source, int linenum)
           
static java.lang.String makeLineNumbers(java.lang.String source, int linenum, int charnum, boolean html)
           
static boolean notEmpty(java.lang.String in)
           
static java.lang.String pad(java.lang.String source, int width, int alignment)
           
static java.util.Vector parseSeparatedValues(java.lang.String source, java.lang.String separator)
           
static java.util.Vector parseSeparatedValues(java.lang.String source, java.lang.String separator, boolean wantEmptyLastItem)
           
static java.lang.String plural(int count, java.lang.String zero, java.lang.String one, java.lang.String many)
          Formats a string based on the count: zero, one or many.
static java.lang.String printArray(java.lang.String[] arr, java.lang.String delim)
           
static java.lang.String remove(java.lang.String substring, java.lang.String source)
           
static java.lang.String removeExtraTrailingWakka(java.lang.String expandedHtmlText)
           
static java.lang.String rtrim(java.lang.String source)
           
static java.lang.String searchAndReplace(java.lang.String source, java.lang.String startStr, java.lang.String endStr, java.lang.String replaceWith)
          Search for a section of text marked with string identifying blocks, and replace with a single string between the markers.
static java.lang.String searchAndReplace(java.lang.String source, java.lang.String startStr, java.lang.String endStr, java.lang.String replaceWith, boolean keepStartAndEndStrs)
          Search for a section of text marked with string identifying blocks, and replace with a single string between the markers.
static java.lang.String searchAndReplaceAll(java.lang.String source, java.lang.String searchFor, java.lang.String replaceWith)
          Overloaded version with ignoreCase defaulted to false.
static java.lang.String searchAndReplaceAll(java.lang.String source, java.lang.String searchFor, java.lang.String replaceWith, boolean ignoreCase)
          Search the "source" string for instances of the "searchFor" string, and replace all instances with "replaceWith".
static java.lang.String searchAndReplaceAll(java.lang.String source, java.lang.String startStr, java.lang.String endStr, java.lang.String replaceWith, boolean keepStartAndEndStrs, boolean doAll)
          Search for a section of text marked with string identifying blocks, and replace with a single string between the markers.
static java.lang.String spacer(Session session, java.lang.String width)
           
static java.lang.String spacer(Session session, java.lang.String width, java.lang.String factor)
           
static java.lang.String sql(java.lang.Object value)
           
static java.lang.String sql(java.lang.String value)
           
static java.lang.String string(java.lang.Object source)
           
static java.lang.String substring(java.lang.String source, int start)
           
static java.lang.String substring(java.lang.String source, int start, int end)
           
static java.lang.String substring(java.lang.String source, java.lang.String endsBefore)
          Returns a substring of source containing everything up to but excluding endsBefore; if does not end in endsBefore, returns "".
static java.lang.String substring(java.lang.String source, java.lang.String delimiter, int index)
          Returns substring delimited by delimiter, counting through the list from zero, stopping at index.
static java.lang.String substring(java.lang.String source, java.lang.String start, java.lang.String end)
          Returns substring between start and end strings.
static void test_removeExtraTrailingWakka()
           
static java.lang.String trimClass(java.lang.Class cls)
          Chops the package "path" off a class name and returns the "tail."
static java.lang.String truncate(java.lang.String source, int maxLength)
           
static java.lang.String truncate(java.lang.String source, int maxLength, java.lang.String ellipses)
           
static java.lang.String unescape(java.lang.String msg)
           
static java.lang.String upperCaseFirstLetter(java.lang.String src)
           
static java.lang.String wrap(java.lang.String source, int lineMinLength)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAD_LEFT

public static final int PAD_LEFT
See Also:
Constant Field Values

PAD_RIGHT

public static final int PAD_RIGHT
See Also:
Constant Field Values

PAD_CENTER

public static final int PAD_CENTER
See Also:
Constant Field Values

SUBSTRING_END

public static final int SUBSTRING_END
See Also:
Constant Field Values

CR

public static final java.lang.String CR
See Also:
Constant Field Values

LF

public static final java.lang.String LF
See Also:
Constant Field Values

CRLF

public static final java.lang.String CRLF
See Also:
Constant Field Values
Constructor Detail

StringTools

public StringTools()
Method Detail

string

public static final java.lang.String string(java.lang.Object source)

fill

public static final java.lang.String fill(char fillChar,
                                          int width)

fill

public static final java.lang.String fill(java.lang.String fillString,
                                          int width)

pad

public static java.lang.String pad(java.lang.String source,
                                   int width,
                                   int alignment)

parseSeparatedValues

public static java.util.Vector parseSeparatedValues(java.lang.String source,
                                                    java.lang.String separator)
Returns:
All elements, except does not add an extra element if the string ends with separator.

parseSeparatedValues

public static java.util.Vector parseSeparatedValues(java.lang.String source,
                                                    java.lang.String separator,
                                                    boolean wantEmptyLastItem)
Returns:
an extra element if the string ends with separator and param wantEmptyLastItem is true.

printArray

public static java.lang.String printArray(java.lang.String[] arr,
                                          java.lang.String delim)

remove

public static java.lang.String remove(java.lang.String substring,
                                      java.lang.String source)

searchAndReplace

public static java.lang.String searchAndReplace(java.lang.String source,
                                                java.lang.String startStr,
                                                java.lang.String endStr,
                                                java.lang.String replaceWith)
Search for a section of text marked with string identifying blocks, and replace with a single string between the markers. Removes the markers from the result.


searchAndReplace

public static java.lang.String searchAndReplace(java.lang.String source,
                                                java.lang.String startStr,
                                                java.lang.String endStr,
                                                java.lang.String replaceWith,
                                                boolean keepStartAndEndStrs)
Search for a section of text marked with string identifying blocks, and replace with a single string between the markers.

Parameters:
keepStartAndEndStrs - Optionally leave the markers in place by setting this to true, or remove them from the result with false.

searchAndReplaceAll

public static java.lang.String searchAndReplaceAll(java.lang.String source,
                                                   java.lang.String startStr,
                                                   java.lang.String endStr,
                                                   java.lang.String replaceWith,
                                                   boolean keepStartAndEndStrs,
                                                   boolean doAll)
Search for a section of text marked with string identifying blocks, and replace with a single string between the markers.

Parameters:
keepStartAndEndStrs - Optionally leave the markers in place using the keepStartAndEndStrs parameter, or remove them from the result.

searchAndReplaceAll

public static java.lang.String searchAndReplaceAll(java.lang.String source,
                                                   java.lang.String searchFor,
                                                   java.lang.String replaceWith)
Overloaded version with ignoreCase defaulted to false. This version searches case sensitively


searchAndReplaceAll

public static java.lang.String searchAndReplaceAll(java.lang.String source,
                                                   java.lang.String searchFor,
                                                   java.lang.String replaceWith,
                                                   boolean ignoreCase)
Search the "source" string for instances of the "searchFor" string, and replace all instances with "replaceWith". "ignoreCase" will perform case insensitive searches.

Returns:
A String with all replacements made.

substring

public static java.lang.String substring(java.lang.String source,
                                         java.lang.String endsBefore)
Returns a substring of source containing everything up to but excluding endsBefore; if does not end in endsBefore, returns "".


substring

public static java.lang.String substring(java.lang.String source,
                                         java.lang.String delimiter,
                                         int index)
Returns substring delimited by delimiter, counting through the list from zero, stopping at index. For example, substring("a_b_c", "_", 1) returns "b"; note: substring("_a_b_c", "_", 0) returns "", since the leading delimiter makes an empty element.


substring

public static java.lang.String substring(java.lang.String source,
                                         java.lang.String start,
                                         java.lang.String end)
Returns substring between start and end strings. If end string is "", cut to end of string. For example, substring("mojo=bar.thing", "mojo=", "") returns "bar.thing" whereas substring("mojo=bar.thing", "mojo=", ".thing") returns "bar".


substring

public static java.lang.String substring(java.lang.String source,
                                         int start)

substring

public static java.lang.String substring(java.lang.String source,
                                         int start,
                                         int end)

rtrim

public static java.lang.String rtrim(java.lang.String source)

ellipses

public static java.lang.String ellipses(java.lang.String source,
                                        int maxLength)

indent

public static java.lang.String indent(java.lang.String body,
                                      int indent,
                                      java.lang.String width,
                                      int padding)
Indents a block by wrapping it in an HTML TABLE tag, with two columns, the left column being the indent width, in pixels. The entire table can be sized by passing a width, either a number or a percentage, as a string, for example indent(body, 40, "100%") or indent(body, 40, "200"). If you pass an empty string for "width", the table will not have a width attribute. The indent cell is filled with a transparent GIF image that is present in all Dynamide installations.

See Also:
indent(String,int,String,int,String)

indent

public static java.lang.String indent(java.lang.String body,
                                      int indent,
                                      java.lang.String tablewidth,
                                      int padding,
                                      java.lang.String imageLocation)
Indents a block by wrapping it in an HTML TABLE tag, similar to indent(String,int,String), but allows you to specify the location of the transparent image used to fill the indent cell.

See Also:
indent(String,int,String,int)

spacer

public static java.lang.String spacer(Session session,
                                      java.lang.String width)

spacer

public static java.lang.String spacer(Session session,
                                      java.lang.String width,
                                      java.lang.String factor)

truncate

public static java.lang.String truncate(java.lang.String source,
                                        int maxLength,
                                        java.lang.String ellipses)

truncate

public static java.lang.String truncate(java.lang.String source,
                                        int maxLength)

wrap

public static java.lang.String wrap(java.lang.String source,
                                    int lineMinLength)

trimClass

public static java.lang.String trimClass(java.lang.Class cls)
Chops the package "path" off a class name and returns the "tail." In other words "com.dynamide.reporter.ReportSection" becomes "ReportSection."

Parameters:
cls - The Class to trim
Returns:
The class name, without all the package stuff

test_removeExtraTrailingWakka

public static void test_removeExtraTrailingWakka()

removeExtraTrailingWakka

public static java.lang.String removeExtraTrailingWakka(java.lang.String expandedHtmlText)

makeLineNumbers

public static java.lang.String makeLineNumbers(java.lang.String source,
                                               int linenum,
                                               int charnum,
                                               boolean html)

makeLineNumbers

public static java.lang.String makeLineNumbers(java.lang.String source,
                                               int linenum)

makeLineNumbers

public static java.lang.String makeLineNumbers(java.lang.String source)

isEmpty

public static boolean isEmpty(java.lang.String in)

notEmpty

public static boolean notEmpty(java.lang.String in)

isValidXHTML

public static boolean isValidXHTML(java.lang.String src)

escape

public static java.lang.String escape(java.lang.String msg)
Does NOT escape ampersands -- use escapeAmpersands for that, either before or after calling this function.


escapeForWebmacro

public static java.lang.String escapeForWebmacro(java.lang.String msg)

escapeForJavascript

public static java.lang.String escapeForJavascript(java.lang.String msg)

escapeAmpersands

public static java.lang.String escapeAmpersands(java.lang.String msg)

unescape

public static java.lang.String unescape(java.lang.String msg)

checkSQLSafe

public static void checkSQLSafe(java.lang.String value)
                         throws java.lang.Exception
Throws:
java.lang.Exception

sql

public static java.lang.String sql(java.lang.Object value)
                            throws java.lang.Exception
Throws:
java.lang.Exception

sql

public static java.lang.String sql(java.lang.String value)
                            throws java.lang.Exception
Throws:
java.lang.Exception

escapeForPostgres

public static java.lang.String escapeForPostgres(java.lang.String val)

identifier

public static java.lang.String identifier(java.lang.String source)

decodeBytea

public static java.lang.String decodeBytea(java.lang.Object o)

dm_nbsp

public static java.lang.String dm_nbsp(java.lang.String source)

plural

public static java.lang.String plural(int count,
                                      java.lang.String zero,
                                      java.lang.String one,
                                      java.lang.String many)
Formats a string based on the count: zero, one or many. One variable is expanded: $count is replaced with the String value of the count sent.
Examples:
  plural(0, "no items", "one item", "$count items")
    ==> no items

  plural(1, "no items", "one item", "$count items")
    ==> one item

  plural(8, "no items", "one item", "$count items")
    ==> 8 items
 
In a Page or widget source, you could write
  #set $count = $session.getFieldValue("shoppingCartCount")
  You have
     $tools.plural($count , "no items", "one item", "$count items")
     in your basket
 
If the field value was 8, the result would be:
       You have 8 items in your basket
 


upperCaseFirstLetter

public static java.lang.String upperCaseFirstLetter(java.lang.String src)

main

public static void main(java.lang.String[] args)


Copyright © 2001-2013 DYNAMIDE.COM. All Rights Reserved.