# HG changeset patch # User Jaroslav Tulach # Date 1259482375 -3600 # Node ID e3d6e326eac14629c10b7b823123bdb2d284027f # Parent 07e3bcb65c1d303df62fc4689ff31274fb4d8592 Automatically detecting connections from a phone and switching to small format diff -r 07e3bcb65c1d -r e3d6e326eac1 freemarkerdor/pom.xml --- a/freemarkerdor/pom.xml Thu Nov 19 09:35:29 2009 +0100 +++ b/freemarkerdor/pom.xml Sun Nov 29 09:12:55 2009 +0100 @@ -10,7 +10,7 @@ org.apidesign freemarkerdor freemarkerdor - 1.41 + 1.42 http://maven.apache.org @@ -123,3 +123,4 @@ + diff -r 07e3bcb65c1d -r e3d6e326eac1 freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java --- a/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Thu Nov 19 09:35:29 2009 +0100 +++ b/freemarkerdor/src/main/java/cz/xelfi/quoridor/freemarkerdor/UI.java Sun Nov 29 09:12:55 2009 +0100 @@ -40,6 +40,7 @@ import java.io.InputStream; import java.net.URI; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; @@ -205,6 +206,10 @@ if (format.length() == 0) { if (cFormat != null) { format = cFormat.getValue(); + } else { + if (isMobile(headers)) { + format = "small"; + } } } else { if (cFormat == null || !format.equals(cFormat.getValue())) { @@ -438,4 +443,22 @@ return new Viewable(page, map); } + + private static boolean isMobile(HttpHeaders headers) { + final String[] keywords = { + "Profile/MIDP", + }; + List agent = headers.getRequestHeader(HttpHeaders.USER_AGENT); + if (agent != null) { + for (String a : agent) { + for (String k : keywords) { + if (a.contains(k)) { + return true; + } + } + } + } + return false; + } + }