Project Wonder 2.0

er.extensions
Class ERXSimpleTemplateParser

java.lang.Object
  extended byer.extensions.ERXSimpleTemplateParser

public class ERXSimpleTemplateParser
extends Object

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


Field Summary
static String DEFAULT_UNDEFINED_KEY_LABEL
          The default label for keys not found while parsing
protected  boolean isLoggingDisabled
          Flag to disable logging.
static ERXLogger log
          logging support
 
Constructor Summary
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
 
Method Summary
 NSArray keysInTemplate(String template, String delimiter)
          Calculates the set of keys used in a given template for a given delimiter.
 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 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.
 
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 String DEFAULT_UNDEFINED_KEY_LABEL
The default label for keys not found while parsing

See Also:
Constant Field Values

log

public static final ERXLogger log
logging support


isLoggingDisabled

protected 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(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"
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.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()

keysInTemplate

public NSArray keysInTemplate(String template,
                              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 String parseTemplateWithObject(String template,
                                      String delimiter,
                                      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 String parseTemplateWithObject(String template,
                                      String delimiter,
                                      Object object,
                                      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).

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

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.