1 24 package org.riotfamily.riot.list.ui.render; 25 26 import java.io.PrintWriter ; 27 import java.util.Locale ; 28 29 import org.springframework.util.StringUtils; 30 31 36 public class LocaleRenderer implements CellRenderer { 37 38 public void render(String propertyName, Object value, 39 RenderContext context, PrintWriter writer) { 40 41 if (value != null) { 42 Locale inLocale = context.getMessageResolver().getLocale(); 43 if (value instanceof Locale ) { 44 Locale locale = (Locale ) value; 45 writer.print(locale.getDisplayName(inLocale)); 46 } 47 else { 48 String s = value.toString(); 49 if (propertyName.endsWith("language")) { 50 Locale locale = new Locale (s); 51 writer.print(locale.getDisplayLanguage(inLocale)); 52 } 53 else if (propertyName.endsWith("country")) { 54 Locale locale = new Locale ("en", s); 55 writer.print(locale.getDisplayCountry(inLocale)); 56 } 57 else { 58 Locale locale = StringUtils.parseLocaleString(s); 59 writer.print(locale.getDisplayName(inLocale)); 60 } 61 } 62 } 63 } 64 65 } 66 | Popular Tags |