1 24 package org.riotfamily.riot.list.ui.render; 25 26 import java.io.PrintWriter ; 27 import java.util.Locale ; 28 29 import org.riotfamily.riot.runtime.RiotRuntime; 30 import org.riotfamily.riot.runtime.RiotRuntimeAware; 31 32 36 public class CountryFlagRenderer implements CellRenderer, RiotRuntimeAware { 37 38 private RiotRuntime runtime; 39 40 public void setRiotRuntime(RiotRuntime runtime) { 41 this.runtime = runtime; 42 } 43 44 public void render(String propertyName, Object value, 45 RenderContext context, PrintWriter writer) { 46 47 if (value != null) { 48 String flag = null; 49 String title = null; 50 if (value instanceof Locale ) { 51 Locale locale = (Locale ) value; 52 flag = locale.getCountry(); 53 if (flag == null) { 54 flag = locale.getLanguage(); 55 } 56 title = locale.getDisplayName(); 57 } 58 else { 59 flag = value.toString(); 60 } 61 writer.print("<img SRC=\""); 62 writer.print(context.getContextPath()); 63 writer.print(runtime.getResourcePath()); 64 writer.print("/style/icons/flags/"); 65 writer.print(flag.toLowerCase()); 66 writer.print(".gif\""); 67 if (title != null) { 68 writer.print("title=\""); 69 writer.print(title); 70 writer.print('"'); 71 } 72 writer.print(" />"); 73 } 74 } 75 76 } 77 | Popular Tags |