KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > i18n > rebind > util > LocalizedPropertiesResource


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.util.Set JavaDoc;
25
26 /**
27  * Resource wrapper for localized properties.
28  */

29 class LocalizedPropertiesResource extends AbstractResource {
30
31   static class Factory extends ResourceFactory {
32     public String JavaDoc getExt() {
33       return "properties";
34     }
35
36     public AbstractResource load(InputStream JavaDoc m) {
37       LocalizedPropertiesResource bundle = new LocalizedPropertiesResource(m);
38       return bundle;
39     }
40   }
41
42   private LocalizedProperties props;
43
44   public LocalizedPropertiesResource(InputStream JavaDoc m) {
45     props = new LocalizedProperties();
46     try {
47       props.load(m, Util.DEFAULT_ENCODING);
48     } catch (IOException JavaDoc e) {
49       throw new RuntimeException JavaDoc("Failed to load " + this.getPath(), e);
50     }
51   }
52
53   public void addToKeySet(Set JavaDoc s) {
54     s.addAll(props.getPropertyMap().keySet());
55   }
56
57   public Object JavaDoc handleGetObject(String JavaDoc key) {
58     return props.getProperty(key);
59   }
60
61   public String JavaDoc toString() {
62     return getPath();
63   }
64 }
65
Popular Tags