package data;

import util.UserAuthUtil;

public class ResponseBuilder {
  public static String toJson(boolean isLoggedIn, String redirectURL) {
    // sample output (logged in): { "isLoggedIn" : {"logoutURL"}, "isLoggedOut" : {}}
    // sample output (logged out): { "isLoggedIn" : {}, "isLoggedOut" : { "loginURL" }}
    return "{ \"isLoggedIn\":{" + buildLogout(isLoggedIn, redirectURL) + "}, \"isLoggedOut\":{"
            + buildLogin(isLoggedIn, redirectURL) + "}}";
  }

  private static String buildLogin(boolean isLoggedIn, String redirectURL) {
    return isLoggedIn ? "" : UserAuthUtil.getLoginURL(redirectURL);
  }

  private static String buildLogout(boolean isLoggedIn, String redirectURL) {
    return isLoggedIn ? UserAuthUtil.getLogoutURL(redirectURL) : "";
  }
}

@@ -141,39 +141,24 @@
 L) %7B%0A    // 
-sample output (
 logged in): 
@@ -154,17 +154,16 @@
 ogged in
-)
 : %7B %22isL
@@ -174,22 +174,40 @@
 dIn%22
- : %7B%22logoutURL
+:%7B%22/_ah/logout?continue=%252FLogin
 %22%7D, 
@@ -219,20 +219,20 @@
 ggedOut%22
- : %7B
+:%7B%22%22
 %7D%7D%0A    /
@@ -237,23 +237,8 @@
  // 
-sample output (
 logg
@@ -243,17 +243,16 @@
 gged out
-)
 : %7B %22isL
@@ -259,20 +259,20 @@
 oggedIn%22
- : %7B
+:%7B%22%22
 %7D, %22isLo
@@ -283,24 +283,40 @@
 Out%22
- : %7B %22loginURL%22 
+:%7B%22/_ah/login?continue=%252FLogin%22
 %7D%7D%0A 
@@ -344,16 +344,18 @@
 edIn%5C%22:%7B
+%5C%22
 %22 + buil
@@ -389,20 +389,39 @@
 tURL) + 
+%22%5C
 %22%7D, 
+%22 +%0A            %22
 %5C%22isLogg
@@ -433,21 +433,11 @@
 %5C%22:%7B
-%22%0A           
+%5C%22%22
  + b
@@ -473,16 +473,18 @@
 tURL) + 
+%22%5C
 %22%7D%7D%22;%0A  

Add double quotes for JSON formatting