1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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 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  }