001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portal.container;
021:
022: import java.util.Enumeration;
023: import java.util.Hashtable;
024: import java.util.PropertyResourceBundle;
025: import java.util.ResourceBundle;
026: import java.util.Vector;
027:
028: /**
029: *
030: *
031: * @author Padmanabh dabke
032: * (c) 2003 Nabh Information Systems, Inc. All Rights Reserved.
033: */
034: public class PortletResourceBundle extends ResourceBundle {
035:
036: private ResourceBundle prbUserBundle = null;
037:
038: private Hashtable prbInlineProps = null;
039:
040: private Hashtable prbCachedValues = new Hashtable();
041:
042: /**
043: *
044: */
045: public PortletResourceBundle(ResourceBundle rb, Hashtable props) {
046: prbUserBundle = rb;
047: prbInlineProps = props;
048: }
049:
050: /**
051: * @see java.util.ResourceBundle#handleGetObject(java.lang.String)
052: */
053: @SuppressWarnings("unchecked")
054: protected Object handleGetObject(String key) {
055: Object value = null;
056: if (prbUserBundle != null) {
057: if (prbUserBundle instanceof PropertyResourceBundle) {
058: value = ((PropertyResourceBundle) prbUserBundle)
059: .handleGetObject(key);
060: if (prbCachedValues.get(value) == null) {
061: String newValue = null;
062: try {
063: newValue = new String(((String) value)
064: .getBytes("ISO-8859-1"), "UTF-8");
065: } catch (Exception ex) {
066: newValue = "";
067: }
068: prbCachedValues.put(value, newValue);
069: return newValue;
070: } else {
071: return prbCachedValues.get(value);
072: }
073:
074: } else {
075: value = prbUserBundle.getObject(key);
076: }
077: if (value != null)
078: return value;
079: }
080:
081: if (prbInlineProps != null) {
082: value = prbInlineProps.get(key);
083: if (value == null)
084: return "";
085: else
086: return value;
087: }
088: return "";
089: }
090:
091: /**
092: * @see java.util.ResourceBundle#getKeys()
093: */
094: @SuppressWarnings("unchecked")
095: public Enumeration getKeys() {
096: Vector keyList = new Vector();
097: if (prbInlineProps != null) {
098: Enumeration inlineKeys = prbInlineProps.keys();
099: while (inlineKeys.hasMoreElements()) {
100: keyList.addElement(inlineKeys.nextElement());
101: }
102: }
103:
104: if (prbUserBundle != null) {
105: Enumeration userKeys = prbUserBundle.getKeys();
106: while (userKeys.hasMoreElements()) {
107: keyList.addElement(userKeys.nextElement());
108: }
109: }
110:
111: return keyList.elements();
112: }
113:
114: }
|