1 53 54 package org.swixml.converters; 55 56 import org.jdom.Attribute; 57 import org.swixml.Converter; 58 import org.swixml.Localizer; 59 60 import java.util.Locale ; 61 import java.util.StringTokenizer ; 62 63 72 public class LocaleConverter implements Converter { 73 74 public static final Class TEMPLATE = Locale .class; 75 76 83 public static Locale conv( Attribute attr ) throws Exception { 84 Locale locale = null; if (attr != null) { 86 StringTokenizer st = new StringTokenizer ( attr.getValue(), "," ); 87 int n = st.countTokens(); 88 if (1 == n) { 89 locale = new Locale ( st.nextToken() ); 90 } else if (2 == n) { 91 locale = new Locale ( st.nextToken(), st.nextToken() ); 92 } else if (3 <= n) { 93 locale = new Locale ( st.nextToken(), st.nextToken(), st.nextToken() ); 94 } 95 } 96 return locale; 97 } 98 99 107 public Object convert( Class type, Attribute attr, Localizer localizer ) throws Exception { 108 return LocaleConverter.conv( attr ); 109 } 110 111 112 117 public Class convertsTo() { 118 return TEMPLATE; 119 } 120 121 } 122 | Popular Tags |