org.ejen.ext
Class StringUtil

java.lang.Object
  |
  +--org.ejen.ext.StringUtil

public class StringUtil
extends Object

String operations utilities (static methods).

Usage (XSL stylesheet)

  <?xml version="1.0" encoding="iso-8859-1"?>

  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  ...
                  xmlns:stu="org.ejen.ext.StringUtil"
                  version="1.0">

    <xsl:output method="text" encoding="iso-8859-1"/>

    <xsl:template match="ejen">

      Date: <xsl:value-of select="stu:dateFormat('yyyy/MM/dd')"/>
      <xsl:if test="stu:equals('abc','abc')">
        ...
      </xsl:if>
      <xsl:if test="stu:equalsIgnoreCase('abc','AbC')">
        ...
      </xsl:if>
      Name (lower case): <xsl:value-of select="stu:toLowerCase('aTtiLa')"/>
      Name (upper case): <xsl:value-of select="stu:toUpperCase('aTtiLa')"/>
      Name (...): <xsl:value-of select="stu:toULowerCase('aTtiLa')"/>
      <xsl:value-of select="stu:indent(2,3)"/>
      Error: <xsl:value-of select="stu:replace('in of memory','in','out')"/>

    </xsl:template>

  </xsl:stylesheet>
 

Version:
1.0
Author:
F. Wolff

Field Summary
static String LINE_SEPARATOR
           
 
Constructor Summary
protected StringUtil()
          Protected constructor (prevents instanciation).
 
Method Summary
static String dateFormat(ExpressionContext context, String format)
          Formats and returns current date.
static boolean equals(ExpressionContext context, String s1, String s2)
          Compares the String s1 to the String s2.
static boolean equalsIgnoreCase(ExpressionContext context, String s1, String s2)
          Compares the String s1 to the String s2, ignoring case considerations.
static String indent(ExpressionContext context, int newLines, int tabs)
          Returns a String starting with 'newLines' new lines followed by 'tabs' tabs.
static String replace(ExpressionContext context, String s1, String s2, String s3)
          Returns a new string resulting from replacing all occurrences of s2 in s1 with s3.
static String toLowerCase(ExpressionContext context, String s)
          Converts all of the characters in the String s to lower case using the rules of the default locale.
static String toULowerCase(ExpressionContext context, String s)
          Converts the first character in the String s to uppercase and the remaining characters to lower case using the rules of the default locale.
static String toUpperCase(ExpressionContext context, String s)
          Converts all of the characters in the String s to upper case using the rules of the default locale.
protected static String unescape(String s)
          Returns a String with common escape sequences ("\t", "\n", "\r", "\f") converted to their respective values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

public static final String LINE_SEPARATOR
Constructor Detail

StringUtil

protected StringUtil()
Protected constructor (prevents instanciation).

Method Detail

dateFormat

public static String dateFormat(ExpressionContext context,
                                String format)
Formats and returns current date.


  <xsl:value-of select="stu:dateFormat('yyyy/MM/dd')"/>
 

See SimpleDateFormat.

XSLT parameters:
[Mandatory/AVT] time pattern to be used to format the date.

Parameters:
context - automatically passed by the xalan extension mechanism.
format - time pattern.
Returns:
the formated current date.

equals

public static boolean equals(ExpressionContext context,
                             String s1,
                             String s2)
Compares the String s1 to the String s2.


  <xsl:if test="stu:equals('abc','abc')">
    ...
  </xsl:if>
 

XSLT parameters:
[Mandatory/AVT] the first String.
[Mandatory/AVT] the second string.

Parameters:
context - automatically passed by the xalan extension mechanism.
s1 - the first String.
s2 - the second String.
Returns:
true if s1 equals s2, false otherwise.

equalsIgnoreCase

public static boolean equalsIgnoreCase(ExpressionContext context,
                                       String s1,
                                       String s2)
Compares the String s1 to the String s2, ignoring case considerations.


  <xsl:if test="stu:equals('abc','ABc')">
    ...
  </xsl:if>
 

XSLT parameters:
[Mandatory/AVT] the first String.
[Mandatory/AVT] the second string.

Parameters:
context - automatically passed by the xalan extension mechanism.
s1 - [AVT] - the first String.
s2 - [AVT] - the second String.
Returns:
true if s1 equals s2, ignoring case, false otherwise.

toLowerCase

public static String toLowerCase(ExpressionContext context,
                                 String s)
Converts all of the characters in the String s to lower case using the rules of the default locale.


  <xsl:value-of select="stu:toLowerCase('aBc')"/>
 

XSLT parameters:
[Mandatory/AVT] the String to be converted to lower case.

Parameters:
context - automatically passed by the xalan extension mechanism.
s - the String to be converted.
Returns:
the String s converted to lower case.

toUpperCase

public static String toUpperCase(ExpressionContext context,
                                 String s)
Converts all of the characters in the String s to upper case using the rules of the default locale.


  <xsl:value-of select="stu:toUpperCase('aBc')"/>
 

XSLT parameters:
[Mandatory/AVT] the String to be converted to upper case.

Parameters:
context - automatically passed by the xalan extension mechanism.
s - the String to be converted.
Returns:
the String s converted to upper case.

toULowerCase

public static String toULowerCase(ExpressionContext context,
                                  String s)
Converts the first character in the String s to uppercase and the remaining characters to lower case using the rules of the default locale.


  <xsl:value-of select="stu:toULowerCase('aBc')"/>
 

XSLT parameters:
[Mandatory/AVT] the String to be converted.

Parameters:
context - automatically passed by the xalan extension mechanism.
s - the String to be converted.
Returns:
the String s converted.

indent

public static String indent(ExpressionContext context,
                            int newLines,
                            int tabs)
Returns a String starting with 'newLines' new lines followed by 'tabs' tabs.


  <xsl:value-of select="stu:indent(1,2)"/>
 

This call will return "\n\t\t".

XSLT parameters:
[Mandatory] number of new lines.
[Mandatory] number of tabs.

Parameters:
context - automatically passed by the xalan extension mechanism.
newLines - number of new lines.
tabs - number of tabs.
Returns:
the indent String.

replace

public static String replace(ExpressionContext context,
                             String s1,
                             String s2,
                             String s3)
Returns a new string resulting from replacing all occurrences of s2 in s1 with s3.


  <xsl:value-of select="stu:replace('ab-ab-ab','ab','cde')"/>
 

This call will return "cde-cde-cde".

XSLT parameters:
[Mandatory] the first String.
[Mandatory] the second string (will be unescaped).
[Mandatory] the third string (will be unescaped).

"unescaped" means: common escape sequences ("\t", "\n", "\r", "\f") converted to their respective values.

Parameters:
context - automatically passed by the xalan extension mechanism.
s1 - the first String.
s2 - the second String (will be unescaped).
s3 - the third String (will be unescaped).
Returns:
true if s1 equals s2, ignoring case, false otherwise.

unescape

protected static String unescape(String s)
Returns a String with common escape sequences ("\t", "\n", "\r", "\f") converted to their respective values. The rule is: "\\" becomes "\"; "\*" (with * in "tnrf") becomes the character '\*'; "\*" (with * not in "tnrf") becomes "*"; if a "\" is the last character of the String, it is removed (except if the String ends with "\\").

Parameters:
s - String to unescape.
Returns:
the String s unescaped.