001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.JavaConstants;
019    import com.liferay.portal.kernel.util.ResourceBundleThreadLocal;
020    import com.liferay.portal.kernel.util.ResourceBundleUtil;
021    import com.liferay.portal.kernel.util.StringPool;
022    
023    import java.util.Enumeration;
024    import java.util.Locale;
025    import java.util.ResourceBundle;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Eduardo Lundgren
030     */
031    public class StrutsResourceBundle extends ResourceBundle {
032    
033            public StrutsResourceBundle(String portletName, Locale locale) {
034                    _portletName = portletName;
035                    _locale = locale;
036            }
037    
038            @Override
039            public Enumeration<String> getKeys() {
040                    return null;
041            }
042    
043            @Override
044            public Locale getLocale() {
045                    return _locale;
046            }
047    
048            @Override
049            protected Object handleGetObject(String key) {
050                    if (key == null) {
051                            throw new NullPointerException();
052                    }
053    
054                    if ((key.equals(JavaConstants.JAVAX_PORTLET_TITLE) ||
055                             key.equals(JavaConstants.JAVAX_PORTLET_SHORT_TITLE) ||
056                             key.equals(JavaConstants.JAVAX_PORTLET_KEYWORDS) ||
057                             key.equals(JavaConstants.JAVAX_PORTLET_DESCRIPTION))) {
058    
059                            key = key.concat(StringPool.PERIOD).concat(_portletName);
060                    }
061    
062                    String value = LanguageUtil.get(_locale, key);
063    
064                    if ((value == null) && ResourceBundleThreadLocal.isReplace()) {
065                            value = ResourceBundleUtil.NULL_VALUE;
066                    }
067    
068                    return value;
069            }
070    
071            private String _portletName;
072            private Locale _locale;
073    
074    }