01: /* ***** BEGIN LICENSE BLOCK *****
02: * Version: MPL 1.1
03: * The contents of this file are subject to the Mozilla Public License Version
04: * 1.1 (the "License"); you may not use this file except in compliance with
05: * the License. You may obtain a copy of the License at
06: * http://www.mozilla.org/MPL/
07: *
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10: * for the specific language governing rights and limitations under the
11: * License.
12: *
13: * The Original Code is Riot.
14: *
15: * The Initial Developer of the Original Code is
16: * Neteye GmbH.
17: * Portions created by the Initial Developer are Copyright (C) 2007
18: * the Initial Developer. All Rights Reserved.
19: *
20: * Contributor(s):
21: * Felix Gnass [fgnass at neteye dot de]
22: *
23: * ***** END LICENSE BLOCK ***** */
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: import org.springframework.util.StringUtils;
32:
33: /**
34: * @author Felix Gnass [fgnass at neteye dot de]
35: * @since 6.5
36: */
37: public class CountryFlagRenderer implements CellRenderer,
38: RiotRuntimeAware {
39:
40: private RiotRuntime runtime;
41:
42: public void setRiotRuntime(RiotRuntime runtime) {
43: this .runtime = runtime;
44: }
45:
46: public void render(String propertyName, Object value,
47: RenderContext context, PrintWriter writer) {
48:
49: if (value != null) {
50: String flag = null;
51: String title = null;
52: if (value instanceof Locale) {
53: Locale locale = (Locale) value;
54: flag = locale.getCountry();
55: title = locale.getDisplayName();
56: } else {
57: flag = value.toString();
58: }
59: if (StringUtils.hasLength(flag)) {
60: writer.print("<img src=\"");
61: writer.print(context.getContextPath());
62: writer.print(runtime.getResourcePath());
63: writer.print("style/icons/flags/");
64: writer.print(flag.toLowerCase());
65: writer.print(".gif\"");
66: if (title != null) {
67: writer.print("title=\"");
68: writer.print(title);
69: writer.print('"');
70: }
71: writer.print(" />");
72: }
73: }
74: }
75:
76: }
|