public class ERXSimpleTemplateParser extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DELIMITER
The default delimiter
|
static String |
DEFAULT_UNDEFINED_KEY_LABEL
The default label for keys not found while parsing
|
boolean |
isLoggingDisabled
Flag to disable logging.
|
Constructor and Description |
---|
ERXSimpleTemplateParser()
Returns a parser object with the default undefined label
|
ERXSimpleTemplateParser(String undefinedKeyLabel)
Returns a parser object with the given string as the undefined key label
|
Modifier and Type | Method and Description |
---|---|
protected Object |
doGetValue(String aKeyPath,
Object anObject)
To allow flexibility of the variable provider object type we use similar
logic to NSDictionary valueForKeyPath.
|
NSArray |
keysInTemplate(String template,
String delimiter)
Calculates the set of keys used in a given template
for a given delimiter.
|
static String |
parseTemplatedStringWithObject(String templateString,
Object templateObject)
Parses the given templateString with an ERXSimpleTemplateParser.
|
String |
parseTemplateWithObject(String template,
String delimiter,
Object object)
Cover method for calling the four argument method
passing in
null for the otherObject
parameter. |
String |
parseTemplateWithObject(String template,
String delimiter,
Object object,
Object otherObject)
This method replaces the keys enclosed between the
delimiter with the values found in object and otherObject.
|
static void |
setSharedInstance(ERXSimpleTemplateParser newSharedInstance)
Sets the shared instance of the template parser.
|
static ERXSimpleTemplateParser |
sharedInstance()
Convenience method to return the shared instance
of the template parser.
|
public static final String DEFAULT_UNDEFINED_KEY_LABEL
public static final String DEFAULT_DELIMITER
public boolean isLoggingDisabled
ERXPatternLayout
will set
this to true for its internal parser object in order to
prevent an infinite debug logging loop.public ERXSimpleTemplateParser()
DEFAULT_UNDEFINED_KEY_LABEL
public ERXSimpleTemplateParser(String undefinedKeyLabel)
undefinedKeyLabel
- string as the undefined key label,
for example, "?", "N/A"public static ERXSimpleTemplateParser sharedInstance()
setSharedInstance(er.extensions.foundation.ERXSimpleTemplateParser)
public static void setSharedInstance(ERXSimpleTemplateParser newSharedInstance)
newSharedInstance
- the parser object that will be sharedsharedInstance()
public NSArray keysInTemplate(String template, String delimiter)
template
- to check for keysdelimiter
- for finding keyspublic String parseTemplateWithObject(String template, String delimiter, Object object)
null
for the otherObject
parameter. See that method for documentation.template
- to use to parsedelimiter
- to use to find keysobject
- to resolve keyspublic String parseTemplateWithObject(String template, String delimiter, Object object, Object otherObject)
When the value is not found in both object and otherObject,
it will replace the key with the undefined key label which
defaults to "?". You can set the label via the constructor
ERXSimpleTemplateParser(String)
. Note that a null
result will also output the label, so you might want to have the empty
string as the undefined key label.
template
- to use to parsedelimiter
- to use to check for keysobject
- to resolve keys off ofotherObject
- object used to resolve default keysprotected Object doGetValue(String aKeyPath, Object anObject)
java.util.Properties
objects that use keyPath separator (.)
in the property names (which is common) can be reliably used as object
providers.aKeyPath
- anObject
- aKeypath
, or when no key, a keyPath with value
aKeyPath
public static String parseTemplatedStringWithObject(String templateString, Object templateObject)
templateString
- the template string to parsetemplateObject
- the object to bind toCopyright © 2002 – 2024 Project Wonder.