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