001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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_DESCRIPTION) ||
055                            key.equals(JavaConstants.JAVAX_PORTLET_KEYWORDS) ||
056                            key.equals(JavaConstants.JAVAX_PORTLET_LONG_TITLE) ||
057                            key.equals(JavaConstants.JAVAX_PORTLET_SHORT_TITLE) ||
058                            key.equals(JavaConstants.JAVAX_PORTLET_TITLE)) {
059    
060                            key = key.concat(StringPool.PERIOD).concat(_portletName);
061                    }
062    
063                    String value = LanguageUtil.get(_locale, key);
064    
065                    if ((value == null) && ResourceBundleThreadLocal.isReplace()) {
066                            value = ResourceBundleUtil.NULL_VALUE;
067                    }
068    
069                    return value;
070            }
071    
072            private Locale _locale;
073            private String _portletName;
074    
075    }