KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > validation > util > BundleReader


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.validation.util;
21
22 import java.util.MissingResourceException JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24
25 import org.netbeans.modules.j2ee.sun.validation.Constants;
26
27
28 /**
29  * BundleReader is a Class to read properties from the bundle.
30  * <code>getValue()</code> method can be used to read the properties
31  * from the bundle file(Bundle.properties). Default bundle file used
32  * is <code>{ @link Constants }.BUNDLE_FILE</code>. Bundle file to use
33  * can be set by using <code>setBundle()</code> method.
34  *
35  * @author Rajeshwar Patil
36  * @version %I%, %G%
37  */

38 public class BundleReader {
39
40     /**
41      * A resource bundle of this reader.
42      */

43     private static ResourceBundle JavaDoc resourceBundle;
44
45     
46     /** Creates a new instance of BundleReader */
47     public BundleReader() {
48     }
49
50     /**
51      * Gets the value of the the given <code>key</code> from the bundle
52      *
53      * @param key the key of which, the value needs to be fetched from
54      * the bundle.
55      */

56     public static String JavaDoc getValue(String JavaDoc key) {
57         if(resourceBundle == null)
58             return key;
59         try {
60             return resourceBundle.getString(key);
61         } catch (MissingResourceException JavaDoc missingResourceException) {
62             return key;
63         }
64     }
65
66
67     /**
68      * sets the given bundle file as the file to use by this object.
69      */

70     public static void setBundle(String JavaDoc bundleFile){
71         try {
72             resourceBundle = ResourceBundle.getBundle(bundleFile);
73         } catch (Exception JavaDoc ex) { }
74     }
75     
76
77     static {
78         try {
79             resourceBundle = ResourceBundle.getBundle(Constants.BUNDLE_FILE);
80         } catch (Exception JavaDoc ex) { }
81     }
82 }
83
Popular Tags