01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.i18n.rebind.util;
17:
18: import com.google.gwt.dev.util.Util;
19:
20: import org.apache.tapestry.util.text.LocalizedProperties;
21:
22: import java.io.IOException;
23: import java.io.InputStream;
24: import java.util.Set;
25:
26: /**
27: * Resource wrapper for localized properties.
28: */
29: class LocalizedPropertiesResource extends AbstractResource {
30:
31: static class Factory extends ResourceFactory {
32: @Override
33: public String getExt() {
34: return "properties";
35: }
36:
37: @Override
38: public AbstractResource load(InputStream m) {
39: LocalizedPropertiesResource bundle = new LocalizedPropertiesResource(
40: m);
41: return bundle;
42: }
43: }
44:
45: private LocalizedProperties props;
46:
47: public LocalizedPropertiesResource(InputStream m) {
48: props = new LocalizedProperties();
49: try {
50: props.load(m, Util.DEFAULT_ENCODING);
51: } catch (IOException e) {
52: throw new RuntimeException("Failed to load "
53: + this .getPath(), e);
54: }
55: }
56:
57: @Override
58: public void addToKeySet(Set<String> s) {
59: s.addAll(props.getPropertyMap().keySet());
60: }
61:
62: @Override
63: public Object handleGetObject(String key) {
64: return props.getProperty(key);
65: }
66:
67: @Override
68: public String toString() {
69: return getPath();
70: }
71: }
|