From: <ap...@vh...> - 2005-11-07 15:12:14
|
Author: apevec Date: 2005-11-07 16:11:12 +0100 (Mon, 07 Nov 2005) New Revision: 975 Added: trunk/ccm-cms/src/com/arsdigita/cms/util/CMSResourceBundle.java Modified: trunk/ccm-cms/src/com/arsdigita/cms/util/GlobalizationUtil.java trunk/ccm-core/src/com/arsdigita/globalization/ChainedResourceBundle.java Log: a hook to add custom ResourceBundle on the top of the chain of bundles this makes possible to override resource keys in bundles which are part of core or cms for example, notification email text in CMSResources.properties Added: trunk/ccm-cms/src/com/arsdigita/cms/util/CMSResourceBundle.java =================================================================== --- trunk/ccm-cms/src/com/arsdigita/cms/util/CMSResourceBundle.java 2005-11-07 14:20:51 UTC (rev 974) +++ trunk/ccm-cms/src/com/arsdigita/cms/util/CMSResourceBundle.java 2005-11-07 15:11:12 UTC (rev 975) @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2004 Red Hat Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package com.arsdigita.cms.util; + +import java.util.PropertyResourceBundle; +import com.arsdigita.globalization.ChainedResourceBundle; +import com.arsdigita.cms.CMSGlobalized; + +/** + * Main ResourceBundle for CMS UI. + * Can be extended using: + * - addBundle - to add new keys + * - putBundle - to override keys already in CMSResources e.g. to customize notification email text + **/ +public class CMSResourceBundle extends ChainedResourceBundle implements CMSGlobalized { + + public CMSResourceBundle() { + super(); + addBundle((PropertyResourceBundle)getBundle(BUNDLE_NAME)); + } +} Modified: trunk/ccm-cms/src/com/arsdigita/cms/util/GlobalizationUtil.java =================================================================== --- trunk/ccm-cms/src/com/arsdigita/cms/util/GlobalizationUtil.java 2005-11-07 14:20:51 UTC (rev 974) +++ trunk/ccm-cms/src/com/arsdigita/cms/util/GlobalizationUtil.java 2005-11-07 15:11:12 UTC (rev 975) @@ -18,7 +18,6 @@ */ package com.arsdigita.cms.util; -import com.arsdigita.cms.CMSGlobalized; import com.arsdigita.globalization.GlobalizedMessage; /** @@ -31,13 +30,16 @@ * @version $Revision: #7 $ $Date: 2004/08/17 $ */ -public class GlobalizationUtil implements CMSGlobalized { - - public static GlobalizedMessage globalize(String key) { - return new GlobalizedMessage(key, BUNDLE_NAME); - } - public static GlobalizedMessage globalize(String key, Object[] args) { - return new GlobalizedMessage(key, BUNDLE_NAME, args); - } +public class GlobalizationUtil { + public static final String BUNDLE_NAME = "com.arsdigita.cms.util.CMSResourceBundle"; + + public static GlobalizedMessage globalize(String key) { + return new GlobalizedMessage(key, BUNDLE_NAME); + } + + public static GlobalizedMessage globalize(String key, Object[] args) { + return new GlobalizedMessage(key, BUNDLE_NAME, args); + } + } Modified: trunk/ccm-core/src/com/arsdigita/globalization/ChainedResourceBundle.java =================================================================== --- trunk/ccm-core/src/com/arsdigita/globalization/ChainedResourceBundle.java 2005-11-07 14:20:51 UTC (rev 974) +++ trunk/ccm-core/src/com/arsdigita/globalization/ChainedResourceBundle.java 2005-11-07 15:11:12 UTC (rev 975) @@ -18,6 +18,8 @@ */ package com.arsdigita.globalization; +import java.util.LinkedList; +import java.util.List; import java.util.ResourceBundle; import java.util.PropertyResourceBundle; import java.util.ListResourceBundle; @@ -44,13 +46,13 @@ **/ public class ChainedResourceBundle extends ResourceBundle { - private ArrayList m_bundles; - private ArrayList m_keys; + private List m_bundles; + private List m_keys; public ChainedResourceBundle() { super(); - m_bundles = new ArrayList(); - m_keys = new ArrayList(); + m_bundles = new LinkedList(); + m_keys = new LinkedList(); } /** @@ -73,14 +75,32 @@ * This adds bundles to this chained resource. The bundles * are examined for the key in the order that they are added. */ - public void addBundle(ChainableResourceBundle bundle) { + private void addBundle(ChainableResourceBundle bundle) { m_bundles.add(bundle); Enumeration enu = bundle.getKeys(); while (enu.hasMoreElements()) { m_keys.add(enu.nextElement()); } } + + public void putBundle(PropertyResourceBundle bundle) { + putBundle(new ChainablePropertyResourceBundle(bundle)); + } + + public void pubBundle(ListResourceBundle bundle) { + putBundle(new ChainableListResourceBundle(bundle)); + } + private void putBundle(ChainableResourceBundle bundle) { + m_bundles.add(0,bundle); + Enumeration enu = bundle.getKeys(); + List bundleKeys = new LinkedList(); + while (enu.hasMoreElements()) { + bundleKeys.add(enu.nextElement()); + } + m_keys.addAll(0, bundleKeys); + } + /** * Because this particular bundle is just a wrapper around other bundles, * this method will return null so that the ResourceBundle can then |