1.1 --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Thu Dec 10 08:47:44 2009 +0100
1.2 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Wed Dec 23 20:45:19 2009 +0100
1.3 @@ -39,6 +39,7 @@
1.4 import java.io.IOException;
1.5 import java.io.InputStream;
1.6 import java.net.URI;
1.7 +import java.util.Date;
1.8 import java.util.HashMap;
1.9 import java.util.List;
1.10 import java.util.Locale;
1.11 @@ -407,10 +408,12 @@
1.12 private Viewable viewable(String page, Document doc, Object... more) {
1.13 ResourceBundle rb = null;
1.14 String lng = user == null ? null : user.getProperty("language"); // NOI18N
1.15 + Locale locale = null;
1.16 if (lng != null) {
1.17 try {
1.18 Locale l = new Locale(lng);
1.19 rb = ResourceBundle.getBundle("cz.xelfi.quoridor.freemarkerdor.UI.Bundle", l);
1.20 + locale = l;
1.21 } catch (MissingResourceException e) {
1.22 // OK
1.23 }
1.24 @@ -419,6 +422,8 @@
1.25 for (Locale l : headers.getAcceptableLanguages()) {
1.26 try {
1.27 rb = ResourceBundle.getBundle("cz.xelfi.quoridor.freemarkerdor.UI.Bundle", l);
1.28 + locale = l;
1.29 + break;
1.30 } catch (MissingResourceException e) {
1.31 // OK
1.32 }
1.33 @@ -426,15 +431,26 @@
1.34 }
1.35 if (rb == null) {
1.36 rb = ResourceBundle.getBundle("cz.xelfi.quoridor.freemarkerdor.UI.Bundle", Locale.ENGLISH);
1.37 + locale = Locale.ENGLISH;
1.38 }
1.39
1.40 Map<String,Object> map = new HashMap<String,Object>();
1.41 + class ConvertToDate extends HashMap<Object,Object> {
1.42 + @Override
1.43 + public Object get(Object o) {
1.44 + long time = Long.parseLong(o.toString());
1.45 + return new Date(time);
1.46 + }
1.47 + }
1.48 +
1.49 + map.put("locale", locale.toString());
1.50 map.put("doc", doc);
1.51 if (user != null) {
1.52 map.put("user", user.getId());
1.53 map.put("email", user.getProperty("email"));
1.54 }
1.55 map.put("bundle", rb);
1.56 + map.put("toDate", new ConvertToDate());
1.57 map.put("now", System.currentTimeMillis());
1.58 map.put("version", version);
1.59 for (int i = 0; i < more.length; i += 2) {