001
014
015 package com.liferay.portlet;
016
017 import com.liferay.portal.kernel.util.JavaConstants;
018 import com.liferay.portal.model.PortletInfo;
019
020 import java.util.Enumeration;
021 import java.util.Locale;
022 import java.util.MissingResourceException;
023 import java.util.ResourceBundle;
024
025
029 public class PortletResourceBundle extends ResourceBundle {
030
031 public PortletResourceBundle(
032 ResourceBundle parentResourceBundle, PortletInfo portletInfo) {
033
034 _parentResourceBundle = parentResourceBundle;
035 _portletInfo = portletInfo;
036 }
037
038 public Enumeration<String> getKeys() {
039 return _parentResourceBundle.getKeys();
040 }
041
042 public Locale getLocale() {
043 return _parentResourceBundle.getLocale();
044 }
045
046 protected Object handleGetObject(String key) {
047 try {
048 if (_parentResourceBundle == null) {
049 return _getJavaxPortletString(key);
050 }
051 else {
052 return _parentResourceBundle.getObject(key);
053 }
054 }
055 catch (MissingResourceException mre) {
056 String value = _getJavaxPortletString(key);
057
058 if (value != null) {
059 return value;
060 }
061 else {
062 throw mre;
063 }
064 }
065 }
066 private String _getJavaxPortletString(String key) {
067 if (key == null) {
068 return null;
069 }
070 else if (key.equals(JavaConstants.JAVAX_PORTLET_TITLE)) {
071 return _portletInfo.getTitle();
072 }
073 else if (key.equals(JavaConstants.JAVAX_PORTLET_SHORT_TITLE)) {
074 return _portletInfo.getShortTitle();
075 }
076 else if (key.equals(JavaConstants.JAVAX_PORTLET_KEYWORDS)) {
077 return _portletInfo.getKeywords();
078 }
079 else if (key.equals(JavaConstants.JAVAX_PORTLET_DESCRIPTION)) {
080 return _portletInfo.getDescription();
081 }
082
083 return null;
084 }
085
086 private ResourceBundle _parentResourceBundle;
087 private PortletInfo _portletInfo;
088
089 }