1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
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  /**
31   * <a href="PortletResourceBundle.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   *
35   */
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  }