1
14
15 package com.liferay.portal.kernel.util;
16
17 import java.io.IOException;
18 import java.io.InputStream;
19
20 import java.util.Enumeration;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.Map;
24 import java.util.NoSuchElementException;
25 import java.util.ResourceBundle;
26 import java.util.Set;
27
28
34 public class PropertyResourceBundle extends ResourceBundle {
35
36 @SuppressWarnings("rawtypes")
37 public PropertyResourceBundle(String string, String charsetName)
38 throws IOException {
39
40 _map = new HashMap(PropertiesUtil.load(string, charsetName));
41 }
42
43 @SuppressWarnings("rawtypes")
44 public PropertyResourceBundle(InputStream inputStream, String charsetName)
45 throws IOException {
46
47 _map = new HashMap(PropertiesUtil.load(inputStream, charsetName));
48 }
49
50 public Object handleGetObject(String key) {
51 if (key == null) {
52 throw new NullPointerException();
53 }
54
55 return _map.get(key);
56 }
57
58 public Enumeration<String> getKeys() {
59 final Set<String> keys = _map.keySet();
60
61 final Enumeration<String> parentKeys = parent.getKeys();
62
63 final Iterator<String> itr = keys.iterator();
64
65 return new Enumeration<String>() {
66 String next = null;
67
68 public boolean hasMoreElements() {
69 if (next == null) {
70 if (itr.hasNext()) {
71 next = itr.next();
72 }
73 else if (parentKeys != null) {
74 while ((next == null) && parentKeys.hasMoreElements()) {
75 next = parentKeys.nextElement();
76
77 if (keys.contains(next)) {
78 next = null;
79 }
80 }
81 }
82 }
83
84 if (next != null) {
85 return true;
86 }
87 else {
88 return false;
89 }
90 }
91
92 public String nextElement() {
93 if (hasMoreElements()) {
94 String result = next;
95
96 next = null;
97
98 return result;
99 }
100 else {
101 throw new NoSuchElementException();
102 }
103 }
104 };
105 }
106
107 private Map<String, String> _map;
108
109 }