001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.taglib.i18n;
018:
019: import java.util.Locale;
020:
021: import org.apache.cocoon.environment.ObjectModelHelper;
022: import org.apache.cocoon.taglib.TagSupport;
023:
024: /**
025: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
026: * @version CVS $Id: LocaleTag.java 433543 2006-08-22 06:22:54Z crossley $
027: */
028: public class LocaleTag extends TagSupport {
029: private Locale locale;
030: private String language;
031: private String country;
032: private String variant;
033:
034: public Locale getLocale() {
035: if (locale == null) {
036: locale = createLocale();
037: }
038: return locale;
039: }
040:
041: public String getLanguage() {
042: return language;
043: }
044:
045: public void setLanguage(String language) {
046: this .language = language;
047: }
048:
049: public String getCountry() {
050: return country;
051: }
052:
053: public void setCountry(String country) {
054: this .country = country;
055: }
056:
057: public String getVariant() {
058: return variant;
059: }
060:
061: public void setVariant(String variant) {
062: this .variant = variant;
063: }
064:
065: /**
066: * Provides a key to retrieve a locale via findAttribute()
067: */
068: public void setLocaleRef(String value) {
069: this .locale = (Locale) findAttribute(value);
070: }
071:
072: protected Locale createLocale() {
073: Locale locale = null;
074:
075: if (language == null) {
076: locale = ObjectModelHelper.getRequest(objectModel)
077: .getLocale();
078: } else if (country == null) {
079: locale = new Locale(language, "");
080: } else if (variant == null) {
081: locale = new Locale(language, country);
082: } else {
083: locale = new Locale(language, country, variant);
084: }
085:
086: return locale;
087: }
088:
089: /*
090: * @see Recyclable#recycle()
091: */
092: public void recycle() {
093: locale = null;
094: language = null;
095: country = null;
096: variant = null;
097: super.recycle();
098: }
099:
100: }
|