Package sunlabs.brazil.util
Class Format
- java.lang.Object
-
- sunlabs.brazil.util.Format
-
- Direct Known Subclasses:
ValidateTemplate.GlobFormat
public class Format extends java.lang.Object
Format a string by substituting values into it from a properties object.- Author:
- colin stevens, stephen uhler
-
-
Constructor Summary
Constructors Constructor Description Format()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
deQuote(java.lang.String str)
Remove surrounding quotes (" or ') from a string.static java.lang.String
getProperty(java.util.Properties props, java.lang.String expr, java.lang.String defaultValue)
Allow a property name to contain the value of another property, permitting nested variable substitution in attribute values.static boolean
isFalse(java.lang.String s)
See if a String represents a "false" boolean value, which consists of: "no", "false", "off", or "0", in any case.static boolean
isTrue(java.lang.String s)
See if a String represents a "true" boolean value, which consists of: "yes", "true", "on", or "1", in any case.static java.lang.String
subst(java.util.Dictionary props, java.lang.String str)
Allow a tag attribute value to contain the value of another property, permitting nested variable substitution in attribute values.static java.lang.String
subst(java.util.Dictionary props, java.lang.String str, boolean noEsc)
Allow a tag attribute value to contain the value of another property, permitting nested variable substitution in attribute values.static java.lang.String
unsubst(java.lang.String data)
Make an html string suitable for including as an attribute value.
-
-
-
Method Detail
-
getProperty
public static java.lang.String getProperty(java.util.Properties props, java.lang.String expr, java.lang.String defaultValue)
Allow a property name to contain the value of another property, permitting nested variable substitution in attribute values. The name of the embedded property to be substituted is bracketted by "${" and "}". Seesubst(java.util.Dictionary, java.lang.String)
."ghi" => "foo"
"deffoojkl" => "baz"
"abcbazmno" => "garply"
getProperty("ghi") => "foo"
getProperty("def${ghi}jkl") => "baz"
getProperty("abc${def${ghi}jkl}mno") => "garply"
- Parameters:
props
- The table of variables to use when substituting.expr
- The property name, prossibly containing substitutions.defaultValue
- The value to use if the top-level substitution does not exist. May benull
.
-
subst
public static java.lang.String subst(java.util.Dictionary props, java.lang.String str)
Allow a tag attribute value to contain the value of another property, permitting nested variable substitution in attribute values. To escape ${XXX}, use \${XXX}.The sequence "\X" is identical to "X", except when "X" is one of:
- $
- A literal "$", that will not introduce a variable substitution if it is followed by "{".
- n
- Insert a NL (newline) character
- r
- Insert a CR (Carriage return) character
- "
- Insert a single quote (").
- l
- Insert a (<).
- g
- Insert a (>).
- a
- Insert a (&).
- end of value
- Insert a "\".
"ghi" = "foo"
"deffoojkl" = "baz"
"abcbazmno" = "garply"
subst("ghi") = "ghi"
subst("def${ghi}jkl") = "deffoojkl"
subst("def\${ghi}jkl") = "def${ghi}jkl"
subst("abc${def${ghi}jkl}mno") = "abcbazmno"
subst("${abc${def${ghi}jkl}mno}") = "garply"
- Parameters:
props
- The table of variables to substitute. If this is a Properties object, then the getProperty() method is used instead of the Dictionary class get() method.str
- The expression containing the substitutions. Embedded property names, bracketted by "${" and "}" are looked up in the props table and replaced with their value. Nested substitutions are allowed.- Returns:
- The substituted string. If a variable is not found in the table, the empty string is used.
-
subst
public static java.lang.String subst(java.util.Dictionary props, java.lang.String str, boolean noEsc)
Allow a tag attribute value to contain the value of another property, permitting nested variable substitution in attribute values. To escape ${XXX}, use \${XXX}. Seeabove
.if
noEsc
is true, then The sequence "\X" is identical to "\X" for all X except X=$.
-
isTrue
public static boolean isTrue(java.lang.String s)
See if a String represents a "true" boolean value, which consists of: "yes", "true", "on", or "1", in any case.
-
isFalse
public static boolean isFalse(java.lang.String s)
See if a String represents a "false" boolean value, which consists of: "no", "false", "off", or "0", in any case.
-
deQuote
public static java.lang.String deQuote(java.lang.String str)
Remove surrounding quotes (" or ') from a string.
-
unsubst
public static java.lang.String unsubst(java.lang.String data)
Make an html string suitable for including as an attribute value. Convert '<', '>', '&', '"', and ''' to \l, \g, \a, \q and \a.
-
-