org.progeeks.meta.format
Class FieldSubstitutionFormat

java.lang.Object
  extended by org.progeeks.meta.format.AbstractPropertyFormat
      extended by org.progeeks.meta.format.FieldSubstitutionFormat
All Implemented Interfaces:
PropertyFormat

public class FieldSubstitutionFormat
extends AbstractPropertyFormat

A formatter that will substitute parameters of a format string with the values contained in the MetaObject's properties. For example:
some format comes in as

...person=@name@&place=@homeTown@

@name@
 would be replaced with the value contained in the
      name property of the MetaObject.
Likewise,
@homeTown@
 would be replaced with the value contained
      in the homeTown property of the MetaObject.
The default token pattern used is: @.+?@
An optional flag is also available for Urlencoding parameter values that are substituted. This flag defaults to false

Version:
$Revision: 1.11 $
Author:
Dave Garvis, Paul Speed

Field Summary
static java.lang.String DEFAULT_TOKEN_PATTERN
           
 
Constructor Summary
FieldSubstitutionFormat()
          Default constructor for a URLQueryFormat.
FieldSubstitutionFormat(java.lang.String formatString)
          Creates a FieldSubstitionFormat that will replace any @propertyName@ values in the formatString with meta-object properties matching the property name.
FieldSubstitutionFormat(java.lang.String formatString, java.lang.String tokenPattern)
           
FieldSubstitutionFormat(java.lang.String formatString, java.lang.String tokenPattern, boolean urlEncode)
           
 
Method Summary
 java.lang.String format(java.lang.Object obj)
          Returns the formatted String for the specified Object, null if the Object cannot be formatted or if any errors occur.
 FormatRegistry getFormatRegistry()
           
 java.lang.String getFormatString()
           
 java.lang.String getTokenPattern()
           
 boolean isUrlEncoding()
           
 java.lang.Object parseObject(java.lang.String source, int index)
          Parsing is not supported.
 void setFormatRegistry(FormatRegistry formatRegistry)
          Sets an optional format registry that will be used to resolve the substitued field values.
 void setFormatString(java.lang.String formatString)
           
 void setTokenPattern(java.lang.String tokenPattern)
           
 void setUrlEncoding(boolean urlEncode)
           
 java.lang.String toString()
          String summary.
 
Methods inherited from class org.progeeks.meta.format.AbstractPropertyFormat
format, parseObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_TOKEN_PATTERN

public static final java.lang.String DEFAULT_TOKEN_PATTERN
See Also:
Constant Field Values
Constructor Detail

FieldSubstitutionFormat

public FieldSubstitutionFormat()
Default constructor for a URLQueryFormat. Uses the default tokenPattern. query is null.


FieldSubstitutionFormat

public FieldSubstitutionFormat(java.lang.String formatString)
Creates a FieldSubstitionFormat that will replace any @propertyName@ values in the formatString with meta-object properties matching the property name.

Parameters:
formatString - is the full string whose tokens will be replaced.

FieldSubstitutionFormat

public FieldSubstitutionFormat(java.lang.String formatString,
                               java.lang.String tokenPattern)
Parameters:
formatString - is the full string whose tokens will be replaced.
tokenPattern - is the pattern searched and replaced the formatString. Default value is: @.+?@ which will match @ delimited field values.

FieldSubstitutionFormat

public FieldSubstitutionFormat(java.lang.String formatString,
                               java.lang.String tokenPattern,
                               boolean urlEncode)
Parameters:
formatString - is the full string whose tokens will be replaced.
tokenPattern - is the pattern searched and replaced the formatString. Default value is: @.+?@ which will match @ delimited field values.
urlEncode - to indicate if substituted value(s) need to be url encoded. Default value is: false.
Method Detail

setFormatRegistry

public void setFormatRegistry(FormatRegistry formatRegistry)
Sets an optional format registry that will be used to resolve the substitued field values.


getFormatRegistry

public FormatRegistry getFormatRegistry()

setTokenPattern

public void setTokenPattern(java.lang.String tokenPattern)

getTokenPattern

public java.lang.String getTokenPattern()

setFormatString

public void setFormatString(java.lang.String formatString)

getFormatString

public java.lang.String getFormatString()

setUrlEncoding

public void setUrlEncoding(boolean urlEncode)

isUrlEncoding

public boolean isUrlEncoding()

format

public java.lang.String format(java.lang.Object obj)
Returns the formatted String for the specified Object, null if the Object cannot be formatted or if any errors occur.

Specified by:
format in interface PropertyFormat
Specified by:
format in class AbstractPropertyFormat

parseObject

public java.lang.Object parseObject(java.lang.String source,
                                    int index)
Parsing is not supported.

Specified by:
parseObject in interface PropertyFormat
Specified by:
parseObject in class AbstractPropertyFormat

toString

public java.lang.String toString()
String summary.

Overrides:
toString in class java.lang.Object


Copyright © 2002-2003 Paul Speed. All Rights Reserved.