freemarker.template.utility
Class StringUtil

java.lang.Object
  extended byfreemarker.template.utility.StringUtil

public class StringUtil
extends java.lang.Object

Some text related utilities.

Version:
$Id: StringUtil.java,v 1.40 2004/01/06 17:06:43 szegedia Exp $

Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String capitalize(java.lang.String s)
           
static java.lang.String chomp(java.lang.String s)
          Removes the line-break from the end of the string.
static java.util.Locale deduceLocale(java.lang.String input)
           
static java.lang.String FTLStringLiteralDec(java.lang.String s)
          FTL string literal decoding. \\, \", \', \n, \t, \r, \b and \f will be replaced according to Java rules.
static java.lang.String FTLStringLiteralEnc(java.lang.String s)
           
static boolean getYesNo(java.lang.String s)
           
static java.lang.String HTMLEnc(java.lang.String s)
          HTML encoding (does not convert line breaks).
static boolean isXMLID(java.lang.String name)
           
static java.lang.String javaScriptStringEnc(java.lang.String s)
          Escapes a string so it could be inserted into a JavaScript Language string literal.
static java.lang.String javaStringEnc(java.lang.String s)
          Escapes a string so it could be inserted into a Java Language string literal.
static java.lang.String jQuote(java.lang.String s)
          Quotes string as Java Language string literal.
static boolean matchesName(java.lang.String qname, java.lang.String nodeName, java.lang.String nsURI, Environment env)
           
static java.util.Map parseNameValuePairList(java.lang.String s, java.lang.String defaultValue)
          Parses a name-value pair list, where the pairs are separated with comma, and the name and value is separated with colon.
static java.lang.String replace(java.lang.String text, java.lang.String oldsub, java.lang.String newsub, boolean caseInsensitive, boolean firstOnly)
          Replaces all occurrences of a sub-string in a string.
static java.lang.String RTFEnc(java.lang.String s)
          Rich Text Format encoding (does not replace line breaks).
static java.lang.String[] split(java.lang.String s, char c)
          Splits a string at the specified character.
static java.lang.String[] split(java.lang.String s, java.lang.String sep, boolean caseInsensitive)
          Splits a string at the specified string.
static java.lang.String XMLEnc(java.lang.String s)
          XML Encoding.
static java.lang.String XMLEncNA(java.lang.String s)
          XML encoding without replacing apostrophes.
static java.lang.String XMLEncNQG(java.lang.String s)
          XML encoding without replacing apostrophes and quotation marks and greater-than signs.
static java.lang.String XMLEncQAttr(java.lang.String s)
          XML encoding for attributes valies quoted with " (not with '!).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

HTMLEnc

public static java.lang.String HTMLEnc(java.lang.String s)
HTML encoding (does not convert line breaks). Replaces all '>' '<' '&' and '"' with entity reference


XMLEnc

public static java.lang.String XMLEnc(java.lang.String s)
XML Encoding. Replaces all '>' '<' '&', "'" and '"' with entity reference


XMLEncNA

public static java.lang.String XMLEncNA(java.lang.String s)
XML encoding without replacing apostrophes.

See Also:
XMLEnc(String)

XMLEncQAttr

public static java.lang.String XMLEncQAttr(java.lang.String s)
XML encoding for attributes valies quoted with " (not with '!). Also can be used for HTML attributes that are quoted with ".

See Also:
XMLEnc(String)

XMLEncNQG

public static java.lang.String XMLEncNQG(java.lang.String s)
XML encoding without replacing apostrophes and quotation marks and greater-than signs.

See Also:
XMLEnc(String)

RTFEnc

public static java.lang.String RTFEnc(java.lang.String s)
Rich Text Format encoding (does not replace line breaks). Escapes all '\' '{' '}' and '"'


FTLStringLiteralEnc

public static java.lang.String FTLStringLiteralEnc(java.lang.String s)

FTLStringLiteralDec

public static java.lang.String FTLStringLiteralDec(java.lang.String s)
                                            throws ParseException
FTL string literal decoding. \\, \", \', \n, \t, \r, \b and \f will be replaced according to Java rules. In additional, it knows \g, \l, \a and \{ which are replaced with <, >, & and { respectively. \x works as hexadecimal character code escape. The character codes are interpreted according to UCS basic plane (Unicode). "f\x006Fo", "f\x06Fo" and "f\x6Fo" will be "foo". "f\x006F123" will be "foo123" as the maximum number of digits is 4. All other \X (where X is any character not mentioned above or End-of-string) will cause a ParseException.

Parameters:
s - String literal without the surrounding quotation marks
Returns:
String with all escape sequences resolved
Throws:
ParseException - if there string contains illegal escapes

deduceLocale

public static java.util.Locale deduceLocale(java.lang.String input)

capitalize

public static java.lang.String capitalize(java.lang.String s)

getYesNo

public static boolean getYesNo(java.lang.String s)

split

public static java.lang.String[] split(java.lang.String s,
                                       char c)
Splits a string at the specified character.


split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String sep,
                                       boolean caseInsensitive)
Splits a string at the specified string.


replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.String oldsub,
                                       java.lang.String newsub,
                                       boolean caseInsensitive,
                                       boolean firstOnly)
Replaces all occurrences of a sub-string in a string.

Parameters:
text - The string where it will replace oldsub with newsub.
Returns:
String The string after the replacements.

chomp

public static java.lang.String chomp(java.lang.String s)
Removes the line-break from the end of the string.


jQuote

public static java.lang.String jQuote(java.lang.String s)
Quotes string as Java Language string literal. Returns string "null" if s is null.


javaStringEnc

public static java.lang.String javaStringEnc(java.lang.String s)
Escapes a string so it could be inserted into a Java Language string literal.


javaScriptStringEnc

public static java.lang.String javaScriptStringEnc(java.lang.String s)
Escapes a string so it could be inserted into a JavaScript Language string literal.


parseNameValuePairList

public static java.util.Map parseNameValuePairList(java.lang.String s,
                                                   java.lang.String defaultValue)
                                            throws java.text.ParseException
Parses a name-value pair list, where the pairs are separated with comma, and the name and value is separated with colon. The keys and values can contain only letters, digits and _. They can't be quoted. White-space around the keys and values are ignored. The value can be omitted if defaultValue is not null. When a value is omitted, then the colon after the key must be omitted as well. The same key can't be used for multiple times.

Parameters:
s - the string to parse. For example: "strong:100, soft:900".
defaultValue - the value used when the value is omitted in a key-value pair.
Returns:
the map that contains the name-value pairs.
Throws:
java.text.ParseException - if the string is not a valid name-value pair list.

isXMLID

public static boolean isXMLID(java.lang.String name)
Returns:
whether the name is a valid XML tagname. (This routine might only be 99% accurate. Should maybe REVISIT)

matchesName

public static boolean matchesName(java.lang.String qname,
                                  java.lang.String nodeName,
                                  java.lang.String nsURI,
                                  Environment env)
Returns:
whether the qname matches the combination of nodeName, nsURI, and environment prefix settings.