1
19
20 package com.liferay.portlet;
21
22 import com.liferay.portal.kernel.util.JavaConstants;
23 import com.liferay.portal.model.PortletInfo;
24
25 import java.util.Enumeration;
26 import java.util.Locale;
27 import java.util.MissingResourceException;
28 import java.util.ResourceBundle;
29
30
36 public class PortletResourceBundle extends ResourceBundle {
37
38 public PortletResourceBundle(
39 ResourceBundle parentBundle, PortletInfo portletInfo) {
40
41 _parentBundle = parentBundle;
42 _portletInfo = portletInfo;
43 }
44
45 public Enumeration<String> getKeys() {
46 return _parentBundle.getKeys();
47 }
48
49 public Locale getLocale() {
50 return _parentBundle.getLocale();
51 }
52
53 protected Object handleGetObject(String key) {
54 try {
55 if (_parentBundle == null) {
56 return _getJavaxPortletString(key);
57 }
58 else {
59 return _parentBundle.getObject(key);
60 }
61 }
62 catch (MissingResourceException mre) {
63 String value = _getJavaxPortletString(key);
64
65 if (value != null) {
66 return value;
67 }
68 else {
69 throw mre;
70 }
71 }
72 }
73
74 private String _getJavaxPortletString(String key) {
75 if (key == null) {
76 return null;
77 }
78 else if (key.equals(JavaConstants.JAVAX_PORTLET_TITLE)) {
79 return _portletInfo.getTitle();
80 }
81 else if (key.equals(JavaConstants.JAVAX_PORTLET_SHORT_TITLE)) {
82 return _portletInfo.getShortTitle();
83 }
84 else if (key.equals(JavaConstants.JAVAX_PORTLET_KEYWORDS)) {
85 return _portletInfo.getKeywords();
86 }
87
88 return null;
89 }
90
91 private ResourceBundle _parentBundle;
92 private PortletInfo _portletInfo;
93
94 }