Hello,
It wouldn’t be the first time that I was the last person to discover some, err,
idiosyncratic behaviour or other, but here’s one for the archives.
I’m using some features of ERXProperties and ERXLocalizer to be able to deploy
multiple “products” from a single codebase, where by “product” I really just
mean a lightly customised view of an app for a particular class of end user.
One of the customisations is the user-presentable names for entities and some
of their properties, and other labels within the app. Setting a property like
this at launch time:
-Dproduct.name=Foo
allows me to do something like this in Properties:
er.extensions.ERXProperties.OptionalConfigurationFiles=(@@product.name@@.properties)
which then loads the custom Foo.properties. That file sets fileNamesToWatch
like this:
er.extensions.ERXLocalizer.fileNamesToWatch=("Foo-Localizable.strings",
"Foo-ValidationTemplate.strings")
In development, after setting this up, I was seeing the custom
Localizable.strings, but _not_ the ValidationTemplate.strings—none of the keys
(say, "Foo.bar.MandatoryToOneRelationshipException") were being found. Closer
inspection shows what it’s actually looking for is:
“ValidationTemplate.Foo.bar.MandatoryToOneRelationshipException”. What’s
happening is this in ERXLocalizer.load():
// HACK: ak we have could have a collision between the search path for
validation strings and
// the normal localized strings.
if (fileName.indexOf(ERXValidationFactory.VALIDATION_TEMPLATE_PREFIX) == 0) {
NSMutableDictionary<String, Object> newDict = new
NSMutableDictionary<String, Object>();
for (Enumeration<String> keys = dict.keyEnumerator();
keys.hasMoreElements();) {
String key = keys.nextElement();
newDict.setObjectForKey(dict.objectForKey(key),
ERXValidationFactory.VALIDATION_TEMPLATE_PREFIX + key);
}
dict = newDict;
}
That is, if the _filename_ you’re loading from _starts with_
“ValidationTemplate”, then we prefix every property with “ValidationTemplate.”.
And, indeed, that’s what’s being searched for by ERXValidationFactory:
public String templateForKeyPath(String key, String language) {
return
(String)ERXLocalizer.localizerForLanguage(language).valueForKey(VALIDATION_TEMPLATE_PREFIX
+ key);
}
The solution here is to either rename “Foo-ValidationTemplate.strings” to, say,
“ValidationTemplate-Foo.strings” or prefix every property with
“ValidationTemplate”. Trap for young players. And me.
--
Paul Hoadley
http://logicsquad.net/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]