Skip to content

Commit

Permalink
Allows java.util.Properties objects to be used as variable providers …
Browse files Browse the repository at this point in the history
…with keys that contain keyPath separators.

This also fixes the currently broken my.property=@@some..other.property@@ style declarations in the maze of Properties
files that load at app startup.
  • Loading branch information
kierankelleher authored and Pascal Robert committed Apr 15, 2012
1 parent 99db53a commit f83b55f
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,34 @@ public String parseTemplateWithObject(String template, String delimiter, Object
return buffer.toString();
}

protected Object doGetValue(String aKeyPath, Object anObject) {
Object result;
if(anObject instanceof NSKeyValueCodingAdditions) {
result = ((NSKeyValueCodingAdditions)anObject).valueForKeyPath(aKeyPath);
} else {
result = NSKeyValueCodingAdditions.Utility.valueForKeyPath(anObject, aKeyPath);
}
return result;
}
/**
* To allow flexibility of the variable provider object type we use similar
* logic to NSDictionary valueForKeyPath. Consequently
* <code>java.util.Properties</code> objects that use keyPath separator (.)
* in the property names (which is common) can be reliably used as object
* providers.
*
* @param aKeyPath
* @param anObject
* @return the value corresponding to either a key with value
* <code>aKeypath</code>, or when no key, a keyPath with value
* <code>aKeyPath</code>
*/
protected Object doGetValue(String aKeyPath, Object anObject) {
// Mimic NSDictionary valueForKeypath behavior which first checks for a
// "flattened" key before calling real valueForKeypath logic
Object result = null;
try {
result = NSKeyValueCoding.Utility.valueForKey(anObject, aKeyPath);
}
catch (NSKeyValueCoding.UnknownKeyException t) {
}

if (result == null) {
return NSKeyValueCodingAdditions.Utility.valueForKeyPath(anObject, aKeyPath);
}
return result;
}

/**
* Parses the given templateString with an ERXSimpleTemplateParser.
Expand Down

0 comments on commit f83b55f

Please sign in to comment.