org.openadaptor.adaptor.util
Class StringUtils

java.lang.Object
  extended by org.openadaptor.adaptor.util.StringUtils

public class StringUtils
extends java.lang.Object

Some utility methods that perform useful actions on Strings

Author:
Russ Fennell

Field Summary
static java.lang.String ATTRIBUTE_TAG
          defines the character used to denote the start and end of a DataObject attribute when included in a String
(package private) static org.apache.log4j.Logger log
           
 
Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String replaceWithAttributeValues(java.lang.String s, DataObject dob)
          overloaded so that we throw an exception if null atribute values are encountered
static java.lang.String replaceWithAttributeValues(java.lang.String s, DataObject dob, java.lang.String nullAlternative)
          loops through the supplied string and replaces any attribute names enclosed by #ATTRIBUTE_TAG chars with the corresponding attribute values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

static org.apache.log4j.Logger log

ATTRIBUTE_TAG

public static final java.lang.String ATTRIBUTE_TAG
defines the character used to denote the start and end of a DataObject attribute when included in a String

See Also:
Constant Field Values
Constructor Detail

StringUtils

public StringUtils()
Method Detail

replaceWithAttributeValues

public static java.lang.String replaceWithAttributeValues(java.lang.String s,
                                                          DataObject dob)
                                                   throws IbafException
overloaded so that we throw an exception if null atribute values are encountered

Throws:
IbafException
See Also:
replaceWithAttributeValues(String, org.openadaptor.dataobjects.DataObject, String)

replaceWithAttributeValues

public static java.lang.String replaceWithAttributeValues(java.lang.String s,
                                                          DataObject dob,
                                                          java.lang.String nullAlternative)
                                                   throws IbafException
loops through the supplied string and replaces any attribute names enclosed by #ATTRIBUTE_TAG chars with the corresponding attribute values. For example, "The price was @strike@ euros" would become "The price was 28.8 euros" where the DataObject's strike attribute contained the value of 28.8

There is an issue with what to do if the attribute value found is null. This is way we allow a "nullAlternative" string to be specified. If you supply a null value for this then an IBafException will be thrown

Parameters:
s - - the string containing the attribute names to be replaced
dob - - the DataObject to source the attribute values from
nullAlternative - - the string to use if the attribute value is null
Returns:
- String with the attribute names replaced by their corresponding values
Throws:
IbafException - - if there are unmatched tags or the attribute name does not exist in the supplied DataObject - or the supplied DataObject was null - or both the attribute value was null and the nullAlternative string was set to null as well