KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > common > I18NImpl


1 /*
2  * @(#)I18NImpl.java 1.3 03/12/19 16:54:01
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.imageio.plugins.common;
9
10 import java.io.InputStream JavaDoc;
11 import java.util.PropertyResourceBundle JavaDoc;
12 import java.net.URL JavaDoc;
13
14 /**
15  * Class to simplify use of internationalization message strings.
16  * Property files are constructed in terms of content as for JAI with
17  * one "key=value" pair per line. All such files however have the same
18  * name "properties". The resource extractor resolves the extraction of
19  * the file from the jar as the package name is included automatically.
20  *
21  * <p>Extenders need only provide a static method
22  * <code>getString(String)</code> which calls the static method in this
23  * class with the name of the invoking class and returns a
24  * <code>String</code>.
25  */

26 public class I18NImpl {
27     /**
28      * Returns the message string with the specified key from the
29      * "properties" file in the package containing the class with
30      * the specified name.
31      */

32     protected static final String JavaDoc getString(String JavaDoc className, String JavaDoc resource_name, String JavaDoc key) {
33         PropertyResourceBundle JavaDoc bundle = null;
34         try {
35             InputStream JavaDoc stream =
36                 Class.forName(className).getResourceAsStream(resource_name);
37             bundle = new PropertyResourceBundle JavaDoc(stream);
38         } catch(Throwable JavaDoc e) {
39             throw new RuntimeException JavaDoc(e); // Chain the exception.
40
}
41
42         return (String JavaDoc)bundle.handleGetObject(key);
43     }
44 }
45
Popular Tags