KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > webapp > admin > ApplicationLocales


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.webapp.admin;
19
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Locale JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25 import org.apache.struts.Globals;
26 import org.apache.struts.action.ActionServlet;
27 import org.apache.struts.util.MessageResources;
28
29
30 /**
31  * Class to hold the Locales supported by this package.
32  *
33  * @author Patrick Luby
34  * @author Craig R. McClanahan
35  * @version $Revision: 1.4 $ $Date: 2004/07/10 06:56:14 $
36  */

37
38 public final class ApplicationLocales {
39
40
41     // ----------------------------------------------------------- Constructors
42

43
44     /**
45      * Initialize the set of Locales supported by this application.
46      *
47      * @param servlet ActionServlet we are associated with
48      */

49     public ApplicationLocales(ActionServlet servlet) {
50
51         super();
52         Locale JavaDoc list[] = Locale.getAvailableLocales();
53         MessageResources resources = (MessageResources)
54                 servlet.getServletContext().getAttribute(Globals.MESSAGES_KEY);
55         if (resources == null)
56             return;
57         String JavaDoc config = resources.getConfig();
58         if (config == null)
59             return;
60
61         for (int i = 0; i < list.length; i++) {
62             try {
63                 ResourceBundle JavaDoc bundle =
64                     ResourceBundle.getBundle(config, list[i]);
65                 if (bundle == null)
66                     continue;
67                 if (list[i].equals(bundle.getLocale())) {
68                     localeLabels.add(list[i].getDisplayName());
69                     localeValues.add(list[i].toString());
70                     supportedLocales.add(list[i]);
71                 }
72             } catch( Exception JavaDoc ex ) {
73                 servlet.log("Missing locale " + list[i] );
74                 continue;
75             }
76         }
77
78     }
79
80
81     // ----------------------------------------------------- Instance Variables
82

83
84     /**
85      * The set of Locale labels supported by this application.
86      */

87     protected ArrayList JavaDoc localeLabels = new ArrayList JavaDoc();
88
89
90     /**
91      * The set of Locale values supported by this application.
92      */

93     protected ArrayList JavaDoc localeValues = new ArrayList JavaDoc();
94
95
96     /**
97      * The set of supported Locales for this application.
98      */

99     protected ArrayList JavaDoc supportedLocales = new ArrayList JavaDoc();
100
101
102     // --------------------------------------------------------- Public Methods
103

104
105     /**
106      * Return the set of Locale labels supported by this application.
107      */

108     public List JavaDoc getLocaleLabels() {
109
110         return (localeLabels);
111
112     }
113
114
115     /**
116      * Return the set of Locale values supported by this application.
117      */

118     public List JavaDoc getLocaleValues() {
119
120         return (localeValues);
121
122     }
123
124
125     /**
126      * Return the set of Locales supported by this application.
127      */

128     public List JavaDoc getSupportedLocales() {
129
130         return (supportedLocales);
131
132     }
133
134
135 }
136
Popular Tags