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