Project Wonder 5.0

er.extensions.foundation
Class ERXSimpleTemplateParser

java.lang.Object
  extended by er.extensions.foundation.ERXSimpleTemplateParser

public class ERXSimpleTemplateParser
extends java.lang.Object

Very simple template parser. For example if you have the delimiter:

Properties
er.extensions.ERXSimpleTemplateParser.useOldDelimiter if false, only @@ delimeters are supported (defaults to true)
           

Field Summary
static java.lang.String DEFAULT_DELIMITER
          The default delimiter
static java.lang.String DEFAULT_UNDEFINED_KEY_LABEL
          The default label for keys not found while parsing
 boolean isLoggingDisabled
          Flag to disable logging.
static org.apache.log4j.Logger log
          logging support
 
Constructor Summary
ERXSimpleTemplateParser()
          Returns a parser object with the default undefined label
ERXSimpleTemplateParser(java.lang.String undefinedKeyLabel)
          Returns a parser object with the given string as the undefined key label
ERXSimpleTemplateParser(java.lang.String undefinedKeyLabel, boolean useOldDelimiter)
          Returns a parser object with the given string as the undefined key label.
 
Method Summary
protected  java.lang.Object doGetValue(java.lang.String aKeyPath, java.lang.Object anObject)
           
 com.webobjects.foundation.NSArray keysInTemplate(java.lang.String template, java.lang.String delimiter)
          Calculates the set of keys used in a given template for a given delimiter.
static java.lang.String parseTemplatedStringWithObject(java.lang.String templateString, java.lang.Object templateObject)
          Parses the given templateString with an ERXSimpleTemplateParser.
 java.lang.String parseTemplateWithObject(java.lang.String template, java.lang.String delimiter, java.lang.Object object)
          Cover method for calling the four argument method passing in null for the otherObject parameter.
 java.lang.String parseTemplateWithObject(java.lang.String template, java.lang.String delimiter, java.lang.Object object, java.lang.Object otherObject)
          This method replaces the keys enclosed between the delimeter with the values found in object and otherObject.
static void setSharedInstance(ERXSimpleTemplateParser newSharedInstance)
          Sets the shared instance of the template parser.
static ERXSimpleTemplateParser sharedInstance()
          Convience method to return the shared instance of the template parser.
protected  boolean useOldDelimiter()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_UNDEFINED_KEY_LABEL

public static final java.lang.String DEFAULT_UNDEFINED_KEY_LABEL
The default label for keys not found while parsing

See Also:
Constant Field Values

DEFAULT_DELIMITER

public static final java.lang.String DEFAULT_DELIMITER
The default delimiter

See Also:
Constant Field Values

log

public static final org.apache.log4j.Logger log
logging support


isLoggingDisabled

public boolean isLoggingDisabled
Flag to disable logging. ERXPatternLayout will set this to true for its internal parser object in order to prevent an infinite debug logging loop.

Constructor Detail

ERXSimpleTemplateParser

public ERXSimpleTemplateParser()
Returns a parser object with the default undefined label

See Also:
DEFAULT_UNDEFINED_KEY_LABEL

ERXSimpleTemplateParser

public ERXSimpleTemplateParser(java.lang.String undefinedKeyLabel)
Returns a parser object with the given string as the undefined key label

Parameters:
undefinedKeyLabel - string as the undefined key label, for example, "?", "N/A"

ERXSimpleTemplateParser

public ERXSimpleTemplateParser(java.lang.String undefinedKeyLabel,
                               boolean useOldDelimiter)
Returns a parser object with the given string as the undefined key label. Depending on useOldDelimiter value @ can be used as delimiter if @@ is not present in the template.

Parameters:
undefinedKeyLabel - string as the undefined key label, for example, "?", "N/A"
useOldDelimiter - boolean defining if @ is used as delimiter if @@ is not available in the template
Method Detail

sharedInstance

public static ERXSimpleTemplateParser sharedInstance()
Convience method to return the shared instance of the template parser.

Returns:
shared instance of the parser
See Also:
setSharedInstance(er.extensions.foundation.ERXSimpleTemplateParser)

setSharedInstance

public static void setSharedInstance(ERXSimpleTemplateParser newSharedInstance)
Sets the shared instance of the template parser.

Parameters:
newSharedInstance - the parser object that will be shared
See Also:
sharedInstance()

useOldDelimiter

protected boolean useOldDelimiter()

keysInTemplate

public com.webobjects.foundation.NSArray keysInTemplate(java.lang.String template,
                                                        java.lang.String delimiter)
Calculates the set of keys used in a given template for a given delimiter.

Parameters:
template - to check for keys
delimiter - for finding keys
Returns:
array of keys

parseTemplateWithObject

public java.lang.String parseTemplateWithObject(java.lang.String template,
                                                java.lang.String delimiter,
                                                java.lang.Object object)
Cover method for calling the four argument method passing in null for the otherObject parameter. See that method for documentation.

Parameters:
template - to use to parse
delimiter - to use to find keys
object - to resolve keys

parseTemplateWithObject

public java.lang.String parseTemplateWithObject(java.lang.String template,
                                                java.lang.String delimiter,
                                                java.lang.Object object,
                                                java.lang.Object otherObject)
This method replaces the keys enclosed between the delimeter with the values found in object and otherObject. It first looks for a value in object, and then in otherObject if the key is not found in object. Therefore, otherObject is a good place to store default values while object is a good place to override default values.

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.

Parameters:
template - to use to parse
delimiter - to use to check for keys
object - to resolve keys off of
otherObject - object used to resolve default keys
Returns:
parsed template with keys replaced

doGetValue

protected java.lang.Object doGetValue(java.lang.String aKeyPath,
                                      java.lang.Object anObject)

parseTemplatedStringWithObject

public static java.lang.String parseTemplatedStringWithObject(java.lang.String templateString,
                                                              java.lang.Object templateObject)
Parses the given templateString with an ERXSimpleTemplateParser.

Parameters:
templateString - the template string to parse
templateObject - the object to bind to
Returns:
the parsed template string

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.