KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > taglib > i18n > LocaleTag


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.taglib.i18n;
17
18 import java.util.Locale JavaDoc;
19
20 import org.apache.cocoon.environment.ObjectModelHelper;
21 import org.apache.cocoon.taglib.TagSupport;
22
23 /**
24  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
25  * @version CVS $Id: LocaleTag.java 30932 2004-07-29 17:35:38Z vgritsenko $
26  */

27 public class LocaleTag extends TagSupport {
28     private Locale JavaDoc locale;
29     private String JavaDoc language;
30     private String JavaDoc country;
31     private String JavaDoc variant;
32
33     public Locale JavaDoc getLocale() {
34         if (locale == null) {
35             locale = createLocale();
36         }
37         return locale;
38     }
39
40     public String JavaDoc getLanguage() {
41         return language;
42     }
43
44     public void setLanguage(String JavaDoc language) {
45         this.language = language;
46     }
47
48     public String JavaDoc getCountry() {
49         return country;
50     }
51
52     public void setCountry(String JavaDoc country) {
53         this.country = country;
54     }
55
56     public String JavaDoc getVariant() {
57         return variant;
58     }
59
60     public void setVariant(String JavaDoc variant) {
61         this.variant = variant;
62     }
63
64     /**
65      * Provides a key to retrieve a locale via findAttribute()
66      */

67     public void setLocaleRef(String JavaDoc value) {
68         this.locale = (Locale JavaDoc) findAttribute(value);
69     }
70
71     protected Locale JavaDoc createLocale() {
72         Locale JavaDoc locale = null;
73
74         if (language == null) {
75             locale = ObjectModelHelper.getRequest(objectModel).getLocale();
76         } else if (country == null) {
77             locale = new Locale JavaDoc(language, "");
78         } else if (variant == null) {
79             locale = new Locale JavaDoc(language, country);
80         } else {
81             locale = new Locale JavaDoc(language, country, variant);
82         }
83
84         return locale;
85     }
86
87     /*
88      * @see Recyclable#recycle()
89      */

90     public void recycle() {
91         locale = null;
92         language = null;
93         country = null;
94         variant = null;
95         super.recycle();
96     }
97
98 }
99
Popular Tags