1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
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  /**
26   * <a href="PortletResourceBundle.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   * @author Eduardo Lundgren
30   */
31  public class PortletResourceBundle extends ResourceBundle {
32  
33      public PortletResourceBundle(
34          ResourceBundle parentResourceBundle, PortletInfo portletInfo) {
35  
36          _parentResourceBundle = parentResourceBundle;
37          _portletInfo = portletInfo;
38      }
39  
40      public Enumeration<String> getKeys() {
41          return _parentResourceBundle.getKeys();
42      }
43  
44      public Locale getLocale() {
45          return _parentResourceBundle.getLocale();
46      }
47  
48      protected Object handleGetObject(String key) {
49          try {
50              if (_parentResourceBundle == null) {
51                  return _getJavaxPortletString(key);
52              }
53              else {
54                  return _parentResourceBundle.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      private String _getJavaxPortletString(String key) {
69          if (key == null) {
70              return null;
71          }
72          else if (key.equals(JavaConstants.JAVAX_PORTLET_TITLE)) {
73              return _portletInfo.getTitle();
74          }
75          else if (key.equals(JavaConstants.JAVAX_PORTLET_SHORT_TITLE)) {
76              return _portletInfo.getShortTitle();
77          }
78          else if (key.equals(JavaConstants.JAVAX_PORTLET_KEYWORDS)) {
79              return _portletInfo.getKeywords();
80          }
81          else if (key.equals(JavaConstants.JAVAX_PORTLET_DESCRIPTION)) {
82              return _portletInfo.getDescription();
83          }
84  
85          return null;
86      }
87  
88      private ResourceBundle _parentResourceBundle;
89      private PortletInfo _portletInfo;
90  
91  }