Example usage for com.google.gwt.user.client Cookies getCookie

List of usage examples for com.google.gwt.user.client Cookies getCookie

Introduction

In this page you can find the example usage for com.google.gwt.user.client Cookies getCookie.

Prototype

public static String getCookie(String name) 

Source Link

Document

Gets the cookie associated with the given name.

Usage

From source file:org.activityinfo.ui.client.inject.ClientSideAuthProvider.java

License:Open Source License

@Override
public AuthenticatedUser get() {

    String authToken = Cookies.getCookie(AuthenticatedUser.AUTH_TOKEN_COOKIE);
    String userId = Cookies.getCookie(AuthenticatedUser.USER_ID_COOKIE);
    String email = Cookies.getCookie(AuthenticatedUser.EMAIL_COOKIE);

    if (authToken != null && userId != null && email != null) {

        return new AuthenticatedUser(authToken, Integer.parseInt(userId), email.replaceAll("\"", ""),
                currentLocale());/*from www . j  a  va  2s  . c  o  m*/

    }

    throw new InvalidAuthTokenException("Request is not authenticated");
}

From source file:org.atmosphere.gwt.client.impl.IEXDomainRequestCometTransport.java

License:Apache License

/**
 * add a session cookie to the url//from ww  w .j a  v  a2s  .co m
 * @param connectionCount
 * @return 
 */
@Override
public String getUrl(int connectionCount) {
    String url = super.getUrl(connectionCount);
    // Detect if we have a session in a cookie and pass it on the url, because XDomainRequest does not
    // send cookies
    if (url.toLowerCase().contains(";jsessionid") == false) {
        String sessionid = Cookies.getCookie("JSESSIONID");
        if (sessionid != null) {
            String parm = ";jsessionid=" + sessionid;
            int p = url.indexOf('?');
            if (p > 0) {
                return url.substring(0, p) + parm + url.substring(p);
            } else {
                return url + parm;
            }
        }
    }
    if (!url.toUpperCase().contains("PHPSESSID")) {
        String sessionid = Cookies.getCookie("PHPSESSID");
        if (sessionid != null) {
            int p = url.indexOf('?');
            String param = "PHPSESSID=" + sessionid;
            if (p > 0) {
                return url.substring(0, p + 1) + param + "&" + url.substring(p + 1);
            } else {
                return url + "?" + param;
            }
        }
    }

    return url;
}

From source file:org.bonitasoft.console.client.model.reporting.ReportingDataSourceImpl.java

License:Open Source License

private void readCookie() {
    reportsParameters = new ArrayList<HashMap<String, String>>();
    String cookieValue = Cookies.getCookie(COOKIE_NAME);
    GWT.log("readCookie - cookieValue:" + cookieValue);
    if (cookieValue != null) {
        String[] reports = cookieValue.split(REPORT_SEPARATOR);
        for (String r : reports) {
            GWT.log("r:" + r);
            String[] report = r.split(REPORT_PARAM_SEPARATOR);
            HashMap<String, String> parameters = new HashMap<String, String>();
            if (report.length == 2) {
                String[] params = report[1].split(PARAMS_SEPARATOR);
                for (String p : params) {
                    String[] param = p.split(VALUE_SEPARATOR);
                    parameters.put(param[0], param[1]);
                }/*from w w w. j  a  v a 2s .  co  m*/
            }
            reportsParameters.add(Integer.valueOf(report[0]).intValue(), parameters);
        }
    }
}

From source file:org.bonitasoft.console.client.user.process.action.CheckFormMappingAndDisplayProcessInstanciationFormAction.java

License:Open Source License

protected void setAlreadyStartedCookie(final String processId) {
    final String processIdArrayAsString = Cookies.getCookie(ALREADY_STARTED_ARRAY_COOKIE_KEY);
    final ArrayList<String> processIdArray = new ArrayList<String>();
    processIdArray.add(processId);/*from ww w  .  j a  v  a  2  s . c om*/
    if (processIdArrayAsString != null) {
        final JSONValue jsonValue = JSONParser.parseStrict(processIdArrayAsString);
        final JSONArray jsonArray = jsonValue.isArray();
        if (jsonArray != null) {
            for (int i = 0; i < jsonArray.size(); i++) {
                processIdArray.add(jsonArray.get(i).isString().stringValue());
            }
        }
    }
    final String alreadyStartedCookieValue = JSonSerializer.serialize(processIdArray);
    Cookies.setCookie(ALREADY_STARTED_ARRAY_COOKIE_KEY, alreadyStartedCookieValue);
}

From source file:org.bonitasoft.console.client.user.task.action.AddProcesIdToCookieThenDisplayProcessInstanciationFormAction.java

License:Open Source License

protected void setAlreadyStartedCookie(TreeIndexed<String> parameters) {
    String processIdArrayAsString = Cookies.getCookie(ALREADY_STARTED_ARRAY_COOKIE_KEY);
    String processId = parameters.getValue("id");
    ArrayList<String> processIdArray = new ArrayList<String>();
    processIdArray.add(processId);/*  w w  w  .  j  a v  a 2  s  .c om*/
    if (processIdArrayAsString != null) {
        JSONValue jsonValue = JSONParser.parseStrict(processIdArrayAsString);
        JSONArray jsonArray = jsonValue.isArray();
        if (jsonArray != null) {
            for (int i = 0; i < jsonArray.size(); i++) {
                processIdArray.add(jsonArray.get(i).isString().stringValue());
            }
        }
    }
    String alreadyStartedCookieValue = JSonSerializer.serialize(processIdArray);
    Cookies.setCookie(ALREADY_STARTED_ARRAY_COOKIE_KEY, alreadyStartedCookieValue);
}

From source file:org.bonitasoft.forms.client.view.common.URLUtils.java

License:Open Source License

/**
 * @return the locale ("en" if the locale is not set)
 *//*w ww  .jav  a 2s.c  o  m*/
public String getLocale() {
    String localeStr = null;
    if (Window.Location.getParameter(LOCALE_PARAM) == null) {
        localeStr = Cookies.getCookie(FORM_LOCALE_COOKIE_NAME);
    } else {
        localeStr = Window.Location.getParameter(LOCALE_PARAM);
    }
    if (localeStr == null || localeStr.length() == 0) {
        localeStr = LocaleInfo.getCurrentLocale().getLocaleName();
    }
    if (DEFAULT_GWT_LOCALE_NAME.equals(localeStr)) {
        localeStr = DEFAULT_LOCALE;
    }
    return localeStr;
}

From source file:org.bonitasoft.web.toolkit.client.ParametersStorageWithCookie.java

License:Open Source License

/**
 * Get the value of a parameter./* ww w.  j a v a  2s  .co m*/
 * 
 * @param name
 * @return This method returns the value of a parameter or NULL if the parameter doesn't exist or is an array.
 */
public static String getParameter(final String name) {
    return Cookies.getCookie(name);
}

From source file:org.celstec.arlearn2.gwtcommonlib.client.auth.OauthClient.java

License:Open Source License

public static OauthClient checkAuthentication() {
    if (oauthInstance != null)
        return oauthInstance;
    if (Window.Location.getParameter("accessToken") != null) {
        oauthInstance = readFromUrl();/* w ww .  j  av a 2s  .co  m*/
    } else if (Cookies.getCookie(COOKIE_TOKEN_NAME) != null) {
        oauthInstance = readFromCookie();
    }
    return oauthInstance;
}

From source file:org.celstec.arlearn2.gwtcommonlib.client.auth.OauthClient.java

License:Open Source License

public static OauthClient readFromCookie() {
    String accessToken = Cookies.getCookie(COOKIE_TOKEN_NAME);
    String typeString = Cookies.getCookie(COOKIE_OAUTH_TYPE);

    if (typeString == null || accessToken == null) {
        Cookies.removeCookie(COOKIE_TOKEN_NAME);
        Cookies.removeCookie(COOKIE_OAUTH_TYPE);
        return null;
    }//from   w w w . j a  v  a  2  s  .c  om
    Integer type = Integer.parseInt(typeString);
    OauthClient client = null;
    switch (type) {
    case AccountJDO.FBCLIENT:
        client = new OauthFbClient();
        break;
    case AccountJDO.GOOGLECLIENT:
        client = new OauthGoogleClient();
        break;
    case AccountJDO.LINKEDINCLIENT:
        client = new OauthLinkedIn();
        break;
    case AccountJDO.ECOCLIENT:
        client = new OauthECO();
        break;
    default:
        break;
    }
    client.accessToken = accessToken;
    return client;

}

From source file:org.celstec.arlearn2.portal.client.Entry.java

License:Open Source License

public void loadPage() {
    final OauthClient client = OauthClient.checkAuthentication();
    if (client != null) {
        String href = Cookies.getCookie("redirectAfterOauth");
        if (href != null) {
            Cookies.removeCookie("redirectAfterOauth");
            Window.open(href, "_self", "");

        } else {/*  w ww  .  ja va 2  s . c o m*/
            if (RootPanel.get("button-facebook") != null)
                (new OauthPage()).loadPage();
            if (RootPanel.get("author") != null)
                (new AuthorPage()).loadPage();
            if (RootPanel.get("test") != null)
                (new TestPage()).loadPage();
            if (RootPanel.get("contact") != null)
                (new AddContactPage()).loadPage();
            if (RootPanel.get("register") != null && Window.Location.getParameter("gameId") != null)
                (new RegisterForGame()).loadPage();
            if (RootPanel.get("register") != null && Window.Location.getParameter("runId") != null)
                (new RegisterForRun()).loadPage();
            if (RootPanel.get("result") != null)
                (new ResultDisplayPage()).loadPage();
            if (RootPanel.get("portal") != null)
                (new org.celstec.arlearn2.portal.client.portal.PortalPage()).loadPage();
            if (RootPanel.get("oauth_new") != null)
                (new OauthPage()).loadPage();
            if (RootPanel.get("resultDisplayRuns") != null)
                (new ResultDisplayRuns()).loadPage();
            if (RootPanel.get("htmlDisplay") != null)
                (new CrsDisplay()).loadPage();
            if (RootPanel.get("resultDisplayRunsParticipate") != null)
                (new ResultDisplayRunsParticipate()).loadPage();

            if (RootPanel.get("network") != null)
                (new NetworkPage()).loadPage();
            if (RootPanel.get("search") != null)
                (new SearchPage()).loadPage();
            if (RootPanel.get("game") != null)
                (new GamePage()).loadPage();
            if (RootPanel.get("debug") != null)
                (new DebugPage()).loadPage();
            if (RootPanel.get("testContentUpload") != null)
                (new ContentUploadPage()).loadPage();
            if (RootPanel.get("authToken") != null)
                (new AuthTokenPage()).loadPage();
        }
    } else {
        String href = Window.Location.getHref();
        if (href.contains("oauth.html")) {
            (new OauthPage()).loadPage();
        } else {
            Cookies.setCookie("redirectAfterOauth", href);
            Window.open("/oauth.html", "_self", "");
        }
    }
}