KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > sun > appserv > LocalStringsManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * LocalStringsManager.java
26  *
27  * Created on September 16, 2003
28  */

29
30 package org.apache.tools.ant.taskdefs.optional.sun.appserv;
31
32 //imports
33
import java.util.ResourceBundle JavaDoc;
34 import java.util.Vector JavaDoc;
35 import java.util.Properties JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.MissingResourceException JavaDoc;
38 import java.text.MessageFormat JavaDoc;
39
40 /**
41  * This is a utility class for getting localized string.
42  * Strings are stored in a single property file per package named
43  * LocalStrings[_locale].properties.
44  *
45  */

46 public class LocalStringsManager {
47     
48     private String JavaDoc packageName = "org.apache.tools.ant.taskdefs.optional.sun.appserv";
49     private String JavaDoc propertyFile = "LocalStrings";
50     private ResourceBundle JavaDoc resourceBundle = null;
51
52
53     /** Creates a new instance of LocalStringsManager */
54     public LocalStringsManager()
55     {
56         this.resourceBundle = ResourceBundle.getBundle(packageName + "." + propertyFile);
57     }
58     
59     /*
60      *returns the property file name
61      */

62     public String JavaDoc getPropertiesFile()
63     {
64         return propertyFile;
65     }
66     
67     /*
68      * returns the base package name
69      */

70     public String JavaDoc getPackageName()
71     {
72         return packageName;
73     }
74     
75     /*
76      * Returns the Localized string properties file
77      */

78     public String JavaDoc getString(String JavaDoc key)
79     {
80         String JavaDoc value = "";
81         try
82         {
83             value = resourceBundle.getString(key);
84         }
85         catch (MissingResourceException JavaDoc mre)
86         {
87             // if not found, try next resource bundle in the iterator
88
}
89         return value;
90     }
91
92
93     /*
94      * Return the Localized string with the inserted values
95      */

96     public String JavaDoc getString(String JavaDoc key, Object JavaDoc[] toInsert)
97     {
98         String JavaDoc fmtStr = "";
99         try
100         {
101             MessageFormat JavaDoc msgFormat =
102                             new MessageFormat JavaDoc(getString(key));
103             fmtStr = msgFormat.format(toInsert);
104         }
105         catch(Exception JavaDoc e)
106         {
107         }
108         return fmtStr;
109     }
110 }
111
Popular Tags