cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Java Needs Message Resources from Data Dictionary

pjaromin
Champ on-the-rise
Champ on-the-rise
I've written a custom Java-based Aspect that sends an email. I'm able to retrieve the FreeMarker template from the Data Dictionary just fine, but would also like to use message resources for the "Subject" of the email.

Because this should be customizable for each tenant in a multi-tenant environment, I'd like to retrieve the message resource from a localized bundle stored in /Company Home/Data Dictionary/Messages.

Unfortunately I've been unable to find docs on this and haven't found anything obvious in the code.

What would be the best/right way to retrieve message resources stored in /Company Home/Data Dictionary/Messages from within custom repo Java code?

Thanks!

Patrick
5 REPLIES 5

afaust
Legendary Innovator
Legendary Innovator
Hello,

you can use the MessageService to retrieve localised strings from tenant aware message bundles in the data dictionary.

Regards
Axel

pjaromin
Champ on-the-rise
Champ on-the-rise
I had tried using MessageService and got 'null' back with every trial.

I've used the message resources console to try and load new resources (which reports that they loaded), I've tried various names of bundle files, etc. Whenever I debugged the process I can see only empty caches and bundles in the MessageService.

I've searched the code for examples of it to copy from but to no avail and confess I haven't worked out how MessageService is supposed to be retrieving the messages from the Data Dictionary.

Do you have a working example?

Thanks!

pjaromin
Champ on-the-rise
Champ on-the-rise
I'm still unable to locate ANY resources in the docs or wiki related to the MessageService and *how* I might use it to retrieve messages from a bundle in the data dictionary. It doesn't appear to resolve messages from alfresco-global.properties and I'm looking for a list of the message bundles it would search through….or how/where these should be specified.

In digging into this a bit deeper, I'm seeing that DictionaryRepositoryBootstrap's initMessages() method has NO side-effects. It creates a new List<String> 'resourceBundleBaseNames' but doesn't actually return it or set them anywhere. I can see my bundles being discovered, but then…nothing.

I assume this method should be calling a messageService.registerResourceBundle here, though when I attempted this by overriding the class, it still didn't work. Is anyone doing this who can give me a pointer?

Thanks!

-Patrick

mrogers
Star Contributor
Star Contributor
Not sure about the mt part of your posting :mrgreen:

But I usually use the I18util class to read message bundles.   There will be lots of examples in the code.
Also alfresco-global.properties is not a message bundle.  I suggest when experimenting you use an existing message first.

pjaromin
Champ on-the-rise
Champ on-the-rise
Thanks for the response.

I18NUtil doesn't look like it retrieves messages from the Data Dictionary. The message service *does* and then falls back to the I18NUtil if it can't find them.

However message bundles dropped into the Data Dictionary and loaded manually with the console (http://localhost:8080/alfresco/faces/jsp/admin/repoadmin-console.jsp) aren't re-registered and available after a server restart until I again reload them with the console.

The DictionaryRepositoryBootstrap class appears to be responsible for this, and in fact does locate any bundles placed in /Company Home/Data Dictionary/Messages. But it doesn't actually do anything with them except adding them to a local list that's never returned from the initMessages() method.

I believe this is a bug, but there's also a chance that I've left out some key step or am misunderstanding how this is supposed to work. By adding the following line to org.alfresco.repo.dictionary.DictionaryRepositoryBoostrap (line 62) of the initMessages method it works …


  if (!resourceBundleBaseNames.contains(bundleBaseName))
  {
     resourceBundleBaseNames.add(bundleBaseName);
+   messageService.registerResourceBundle(storeRef + repositoryLocation.getPath() + "/cm:" + bundleBaseName);
  }

Is there something else that needs to happen for these dynamic loaded message resources to be re-loaded upon server restart?

Thanks!

-Patrick