1 16 package org.apache.cocoon.taglib.i18n; 17 18 import java.util.Locale ; 19 20 import org.apache.cocoon.environment.ObjectModelHelper; 21 import org.apache.cocoon.taglib.TagSupport; 22 23 27 public class LocaleTag extends TagSupport { 28 private Locale locale; 29 private String language; 30 private String country; 31 private String variant; 32 33 public Locale getLocale() { 34 if (locale == null) { 35 locale = createLocale(); 36 } 37 return locale; 38 } 39 40 public String getLanguage() { 41 return language; 42 } 43 44 public void setLanguage(String language) { 45 this.language = language; 46 } 47 48 public String getCountry() { 49 return country; 50 } 51 52 public void setCountry(String country) { 53 this.country = country; 54 } 55 56 public String getVariant() { 57 return variant; 58 } 59 60 public void setVariant(String variant) { 61 this.variant = variant; 62 } 63 64 67 public void setLocaleRef(String value) { 68 this.locale = (Locale ) findAttribute(value); 69 } 70 71 protected Locale createLocale() { 72 Locale locale = null; 73 74 if (language == null) { 75 locale = ObjectModelHelper.getRequest(objectModel).getLocale(); 76 } else if (country == null) { 77 locale = new Locale (language, ""); 78 } else if (variant == null) { 79 locale = new Locale (language, country); 80 } else { 81 locale = new Locale (language, country, variant); 82 } 83 84 return locale; 85 } 86 87 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 |