From: Robert L. <rob...@lo...> - 2003-04-20 21:48:11
|
Dear Anthony Eden, I walked through your code of FormProc to see how translations are retrieved from the system. I programmed a translation module using the design pattern facade. It has currently only one method: static String getString(String key); static String getString(String key, String defaultTranslation); And several constructors to setup the locale, resourcebundle name (1 central file), and an excemption resource bundle name. I am still in the stage of creating other methods to extend its capabilities. And now my aim: Instead of talking to the Resource Bundle I would like to be able to 'talk' to this Facade. I saw that the classname to express the ResourceBundleMessageProvider has to be mentioned with every single message element. as in: <message classname="org.formproc.message.ResourceBundleMessageProvider"> message.usernamemustbelongerthan8characters </message> I am in favour of mentioning the message key, so that the key get translated according to the current locale. However, would it be possible to mentioning a default MessageProvider in the configuration file FormProc.xml?. Like: <message-provider classname="org.formproc.message.ResourceBundleMessageProvider" /> So that I can use in my form configuration file: <message> message.usernamemustbelongerthan8characters </message> I think it is possible: In DefaultFormElement.jave there is the following code: //-------------------------------------------------------------------------- -------------------------- private void setMessageProvider(Configuration configuration) throws Exception{ String messageElementName = "message"; List messageElements = configuration.getChildren(messageElementName); if(messageElements.size() > 0){ Configuration messageElement = (Configuration)messageElements.get(0); String messageProviderClassName = messageElement.getAttribute("classname"); if(messageProviderClassName == null){ if(messageElement.getAttribute("resource") != null){ messageProvider = new ResourceBundleMessageProvider(); messageProvider.loadConfiguration(messageElement); } else { // AAA // this is to support the old style of inlining messages InlineMessageProvider inlineMessageProvider = new InlineMessageProvider(); inlineMessageProvider.setMessageElementName(messageElementName); inlineMessageProvider.loadConfiguration(configuration); messageProvider = inlineMessageProvider; } } else { messageProvider = (MessageProvider)ClassUtilities.loadClass( messageProviderClassName).newInstance(); messageProvider.loadConfiguration(messageElement); } } } //-------------------------------------------------------------------------- -------------------------- At // AAA the default classname could be retrieved. String messageProviderClassName = messageElement.getAttribute("classname"); if(messageProviderClassName == null){ // do the old thing with inlining messages } else { messageProvider = (MessageProvider)ClassUtilities.loadClass( messageProviderClassName).newInstance(); messageProvider.loadConfiguration(messageElement); } Of course the new element in the FormProx.xml must be loaded. But I think I can leave that to you. The above is just a suggestion for a possible implementation. I am looking forward to your reaction. Kind regards, Robert Lamping The Netherlands |