|
@@ -8,31 +8,26 @@ |
8 |
8 |
|
import javax.servlet.http.*; |
9 |
9 |
|
import java.io.*; |
10 |
10 |
|
|
11 |
|
- |
public class IndexHtmlGenerator |
12 |
|
- |
{ |
|
11 |
+ |
public class IndexHtmlGenerator { |
13 |
12 |
|
private static final UserAgentFormFactorDeterminer UAFFD = new UserAgentFormFactorDeterminerImpl(); |
14 |
13 |
|
|
15 |
14 |
|
private final Template mTemplate; |
16 |
15 |
|
|
17 |
|
- |
public IndexHtmlGenerator( Template pTemplate ) |
18 |
|
- |
{ |
|
16 |
+ |
public IndexHtmlGenerator( Template pTemplate ) { |
19 |
17 |
|
mTemplate = pTemplate; |
20 |
18 |
|
} |
21 |
19 |
|
|
22 |
20 |
|
public void respond( String pPath, HttpServletRequest pRequest, HttpServletResponse pResponse ) |
23 |
|
- |
throws ServletException, IOException |
24 |
|
- |
{ |
|
21 |
+ |
throws ServletException, IOException { |
25 |
22 |
|
CacheHeaders.never( pResponse ); |
26 |
23 |
|
|
27 |
24 |
|
String zDeviceToken = getCookie( pRequest, "DeviceToken" ); |
28 |
|
- |
if ( zDeviceToken != null ) |
29 |
|
- |
{ |
|
25 |
+ |
if ( zDeviceToken != null ) { |
30 |
26 |
|
reply( pResponse, "LimitedMode" ); |
31 |
27 |
|
return; |
32 |
28 |
|
} |
33 |
29 |
|
String zUserAuthToken = getCookie( pRequest, "UserAuthToken" ); |
34 |
|
- |
if ( zUserAuthToken != null ) |
35 |
|
- |
{ |
|
30 |
+ |
if ( zUserAuthToken != null ) { |
36 |
31 |
|
reply( pResponse, "FullMode" ); |
37 |
32 |
|
return; |
38 |
33 |
|
} |
|
@@ -42,14 +37,11 @@ |
42 |
37 |
|
} |
43 |
38 |
|
|
44 |
39 |
|
private void reply( HttpServletResponse pResponse, final String pWhat ) |
45 |
|
- |
throws IOException |
46 |
|
- |
{ |
|
40 |
+ |
throws IOException { |
47 |
41 |
|
pResponse.setContentType( "text/html" ); |
48 |
|
- |
mTemplate.dump( new Sink.Simple( pResponse.getWriter() ), new ValueProvider() |
49 |
|
- |
{ |
|
42 |
+ |
mTemplate.dump( new Sink.Simple( pResponse.getWriter() ), new ValueProvider() { |
50 |
43 |
|
@Override |
51 |
|
- |
public Object valueFor( String pKey ) |
52 |
|
- |
{ |
|
44 |
+ |
public Object valueFor( String pKey ) { |
53 |
45 |
|
return pWhat; |
54 |
46 |
|
} |
55 |
47 |
|
} ); |
|
@@ -70,23 +62,17 @@ |
70 |
62 |
|
// return -1; |
71 |
63 |
|
// } |
72 |
64 |
|
|
73 |
|
- |
private static String getCookie( HttpServletRequest pRequest, String pName ) |
74 |
|
- |
{ |
|
65 |
+ |
private static String getCookie( HttpServletRequest pRequest, String pName ) { |
75 |
66 |
|
return checkAndClearCookie( pRequest, pName, false ); |
76 |
67 |
|
} |
77 |
68 |
|
|
78 |
|
- |
private static String checkAndClearCookie( HttpServletRequest pRequest, String pName, boolean pClear ) |
79 |
|
- |
{ |
|
69 |
+ |
private static String checkAndClearCookie( HttpServletRequest pRequest, String pName, boolean pClear ) { |
80 |
70 |
|
Cookie[] zCookies = pRequest.getCookies(); |
81 |
|
- |
if ( zCookies != null ) |
82 |
|
- |
{ |
83 |
|
- |
for ( Cookie zCookie : zCookies ) |
84 |
|
- |
{ |
85 |
|
- |
if ( zCookie.getName().equals( pName ) ) |
86 |
|
- |
{ |
|
71 |
+ |
if ( zCookies != null ) { |
|
72 |
+ |
for ( Cookie zCookie : zCookies ) { |
|
73 |
+ |
if ( zCookie.getName().equals( pName ) ) { |
87 |
74 |
|
String zValue = zCookie.getValue(); |
88 |
|
- |
if ( pClear ) |
89 |
|
- |
{ |
|
75 |
+ |
if ( pClear ) { |
90 |
76 |
|
zCookie.setMaxAge( 0 ); // Delete it... |
91 |
77 |
|
} |
92 |
78 |
|
return zValue; |