From: <fg...@us...> - 2010-11-17 14:32:16
|
Revision: 3141 http://openutils.svn.sourceforge.net/openutils/?rev=3141&view=rev Author: fgiust Date: 2010-11-17 14:32:10 +0000 (Wed, 17 Nov 2010) Log Message: ----------- MESSAGES-8 MessageManager should automatically use bundles defined in messages/basename configuration Modified Paths: -------------- trunk/openutils-mgnlmessages/src/main/resources/META-INF/magnolia/messages.xml trunk/openutils-mgnlmessages/src/main/resources/mgnl-bootstrap/messages-nooverwrite/config.modules.messages.basenames.xml Added Paths: ----------- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMessagesImpl.java trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMgnlMessagesManager.java Added: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMessagesImpl.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMessagesImpl.java (rev 0) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMessagesImpl.java 2010-11-17 14:32:10 UTC (rev 3141) @@ -0,0 +1,108 @@ +/** + * + * Magnolia Messages Module (http://www.openmindlab.com/lab/products/groovy.html) + * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmessages.i18n; + +import info.magnolia.cms.i18n.AbstractMessagesImpl; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.Set; + +import net.sourceforge.openutils.mgnlmessages.configuration.MessagesConfigurationManager; + +import org.apache.commons.collections.IteratorUtils; +import org.apache.commons.lang.StringUtils; + + +/** + * @author molaschi + * @version $Id$ + */ +public class MultiBundleMessagesImpl extends AbstractMessagesImpl +{ + + private List<OpenutilsMessagesImpl> messages; + + /** + * @param basename + * @param locale + */ + public MultiBundleMessagesImpl(Locale locale) + { + super(null, locale); + messages = new ArrayList<OpenutilsMessagesImpl>(); + for (String basename : MessagesConfigurationManager.getBaseNames()) + { + messages.add(new OpenutilsMessagesImpl(basename, locale)); + } + } + + /** + * {@inheritDoc} + */ + public String get(String key) + { + for (OpenutilsMessagesImpl message : messages) + { + String value = message.get(key); + if (StringUtils.isNotBlank(value) && !StringUtils.startsWith(value, "???")) + { + return value; + } + } + return "???" + key + "???"; + } + + /** + * {@inheritDoc} + */ + public Iterator<String> keys() + { + Set<String> keys = new HashSet<String>(); + for (OpenutilsMessagesImpl message : messages) + { + try + { + keys.addAll(IteratorUtils.toList(message.keys())); + } + catch (MissingResourceException ex) + { + // ignore + } + } + return keys.iterator(); + } + + /** + * {@inheritDoc} + */ + public void reload() throws Exception + { + for (OpenutilsMessagesImpl message : messages) + { + message.reload(); + } + } + +} Property changes on: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMessagesImpl.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMgnlMessagesManager.java =================================================================== --- trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMgnlMessagesManager.java (rev 0) +++ trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMgnlMessagesManager.java 2010-11-17 14:32:10 UTC (rev 3141) @@ -0,0 +1,48 @@ +/** + * + * Magnolia Messages Module (http://www.openmindlab.com/lab/products/groovy.html) + * Copyright(C) 2008-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmessages.i18n; + +import info.magnolia.cms.i18n.DefaultMessagesManager; +import info.magnolia.cms.i18n.Messages; +import info.magnolia.cms.i18n.MessagesChain; + + +/** + * @author molaschi + * @version $Id$ + */ +public class MultiBundleMgnlMessagesManager extends DefaultMessagesManager +{ + + /** + * {@inheritDoc} + */ + @Override + protected Messages newMessages(MessagesID messagesID) + { + + Messages parentMessages = super.newMessages(messagesID); + Messages repositoryMsg = new RepositoryMessagesImpl(messagesID.getBasename(), messagesID.getLocale()); + Messages multiBundle = new MultiBundleMessagesImpl(messagesID.getLocale()); + + return new MessagesChain(repositoryMsg).chain(multiBundle).chain(parentMessages); + } + +} \ No newline at end of file Property changes on: trunk/openutils-mgnlmessages/src/main/java/net/sourceforge/openutils/mgnlmessages/i18n/MultiBundleMgnlMessagesManager.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/openutils-mgnlmessages/src/main/resources/META-INF/magnolia/messages.xml =================================================================== --- trunk/openutils-mgnlmessages/src/main/resources/META-INF/magnolia/messages.xml 2010-11-12 16:29:56 UTC (rev 3140) +++ trunk/openutils-mgnlmessages/src/main/resources/META-INF/magnolia/messages.xml 2010-11-17 14:32:10 UTC (rev 3141) @@ -10,7 +10,7 @@ <properties> <property> <name>info.magnolia.cms.i18n.MessagesManager</name> - <value>net.sourceforge.openutils.mgnlmessages.i18n.OpenutilsMgnlMessagesManager</value> + <value>net.sourceforge.openutils.mgnlmessages.i18n.MultiBundleMgnlMessagesManager</value> </property> </properties> <dependencies> Modified: trunk/openutils-mgnlmessages/src/main/resources/mgnl-bootstrap/messages-nooverwrite/config.modules.messages.basenames.xml =================================================================== --- trunk/openutils-mgnlmessages/src/main/resources/mgnl-bootstrap/messages-nooverwrite/config.modules.messages.basenames.xml 2010-11-12 16:29:56 UTC (rev 3140) +++ trunk/openutils-mgnlmessages/src/main/resources/mgnl-bootstrap/messages-nooverwrite/config.modules.messages.basenames.xml 2010-11-17 14:32:10 UTC (rev 3141) @@ -69,78 +69,4 @@ </sv:property> </sv:node> </sv:node> - <sv:node sv:name="templating"> - <sv:property sv:name="jcr:primaryType" sv:type="Name"> - <sv:value>mgnl:contentNode</sv:value> - </sv:property> - <sv:property sv:name="jcr:mixinTypes" sv:type="Name"> - <sv:value>mix:lockable</sv:value> - </sv:property> - <sv:property sv:name="jcr:uuid" sv:type="String"> - <sv:value>b1c9de59-128d-4d8e-bfcf-f3fc5f02ad78</sv:value> - </sv:property> - <sv:property sv:name="basename" sv:type="String"> - <sv:value>info.magnolia.module.admininterface.messages_templating</sv:value> - </sv:property> - <sv:node sv:name="MetaData"> - <sv:property sv:name="jcr:primaryType" sv:type="Name"> - <sv:value>mgnl:metaData</sv:value> - </sv:property> - <sv:property sv:name="mgnl:activated" sv:type="Boolean"> - <sv:value>false</sv:value> - </sv:property> - <sv:property sv:name="mgnl:activatorid" sv:type="String"> - <sv:value>admin</sv:value> - </sv:property> - <sv:property sv:name="mgnl:authorid" sv:type="String"> - <sv:value>admin</sv:value> - </sv:property> - <sv:property sv:name="mgnl:creationdate" sv:type="Date"> - <sv:value>2008-07-15T14:01:17.570Z</sv:value> - </sv:property> - <sv:property sv:name="mgnl:lastaction" sv:type="Date"> - <sv:value>2008-07-15T14:01:44.913Z</sv:value> - </sv:property> - <sv:property sv:name="mgnl:lastmodified" sv:type="Date"> - <sv:value>2008-07-15T14:02:18.430Z</sv:value> - </sv:property> - </sv:node> - </sv:node> - <sv:node sv:name="templating-custom"> - <sv:property sv:name="jcr:primaryType" sv:type="Name"> - <sv:value>mgnl:contentNode</sv:value> - </sv:property> - <sv:property sv:name="jcr:mixinTypes" sv:type="Name"> - <sv:value>mix:lockable</sv:value> - </sv:property> - <sv:property sv:name="jcr:uuid" sv:type="String"> - <sv:value>58009318-ca00-43be-9b3d-62076ee92cce</sv:value> - </sv:property> - <sv:property sv:name="basename" sv:type="String"> - <sv:value>info.magnolia.module.admininterface.messages_templating_custom</sv:value> - </sv:property> - <sv:node sv:name="MetaData"> - <sv:property sv:name="jcr:primaryType" sv:type="Name"> - <sv:value>mgnl:metaData</sv:value> - </sv:property> - <sv:property sv:name="mgnl:activated" sv:type="Boolean"> - <sv:value>false</sv:value> - </sv:property> - <sv:property sv:name="mgnl:activatorid" sv:type="String"> - <sv:value>admin</sv:value> - </sv:property> - <sv:property sv:name="mgnl:authorid" sv:type="String"> - <sv:value>admin</sv:value> - </sv:property> - <sv:property sv:name="mgnl:creationdate" sv:type="Date"> - <sv:value>2008-07-15T14:01:17.570Z</sv:value> - </sv:property> - <sv:property sv:name="mgnl:lastaction" sv:type="Date"> - <sv:value>2008-07-15T14:02:29.547Z</sv:value> - </sv:property> - <sv:property sv:name="mgnl:lastmodified" sv:type="Date"> - <sv:value>2008-07-15T14:02:56.069Z</sv:value> - </sv:property> - </sv:node> - </sv:node> -</sv:node> +</sv:node> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |