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:net.ffxml.gwt.json.client.JsonRpc.java

License:Apache License

/**
 * Executes a json-rpc request.// ww  w . j  a v a  2 s  .c o m
 * 
 * @param url
 *            The location of the service
 * @param username
 *            The username for basic authentification
 * @param password
 *            The password for basic authentification
 * @param method
 *            The method name
 * @param params
 *            An array of objects containing the parameters
 * @param callback
 *            A callbackhandler like in gwt's rpc.
 */
public void request(final String url, String username, String password, final String method, Object[] params,
        final AsyncCallback callback) {

    HashMap request = new HashMap();
    request.put("method", method);
    if (params == null) {
        params = new Object[] {};
    }
    request.put("params", params);
    request.put("id", new Integer(requestSerial++));

    if (username == null)
        if (requestUser != null)
            username = requestUser;
    if (password == null)
        if (requestPassword != null)
            password = requestPassword;

    RequestCallback handler = new RequestCallback() {
        public void onResponseReceived(Request request, Response response) {
            try {
                String resp = response.getText();
                if (resp.equals(""))
                    throw new RuntimeException("empty");
                HashMap reply = (HashMap) decode(resp);

                if (reply == null) {
                    RuntimeException runtimeException = new RuntimeException("parse: " + response.getText());
                    fireFailure(runtimeException);
                    callback.onFailure(runtimeException);
                }

                if (isErrorResponse(reply)) {
                    RuntimeException runtimeException = new RuntimeException("error: " + reply.get("error"));
                    fireFailure(runtimeException);
                    callback.onFailure(runtimeException);
                } else if (isSuccessfulResponse(reply)) {
                    callback.onSuccess(reply.get("result"));
                } else {
                    RuntimeException runtimeException = new RuntimeException("syntax: " + response.getText());
                    fireFailure(runtimeException);
                    callback.onFailure(runtimeException);
                }
            } catch (RuntimeException e) {
                fireFailure(e);
                callback.onFailure(e);
            } finally {
                decreaseRequestCounter();
            }
        }

        public void onError(Request request, Throwable exception) {
            try {
                if (exception instanceof RequestTimeoutException) {
                    RuntimeException runtimeException = new RuntimeException("timeout");
                    fireFailure(runtimeException);
                    callback.onFailure(runtimeException);
                } else {
                    RuntimeException runtimeException = new RuntimeException("other");
                    fireFailure(runtimeException);
                    callback.onFailure(runtimeException);
                }
            } catch (RuntimeException e) {
                fireFailure(e);
                callback.onFailure(e);
            } finally {
                decreaseRequestCounter();
            }
        }

        private boolean isErrorResponse(HashMap response) {
            return response.get("error") != null && response.get("result") == null;
        }

        private boolean isSuccessfulResponse(HashMap response) {
            return response.get("error") == null && response.containsKey("result");
        }
    };

    increaseRequestCounter();

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);
    if (requestTimeout > 0)
        builder.setTimeoutMillis(requestTimeout);
    builder.setHeader("Content-Type", "application/json; charset=utf-8");
    String body = new String(encode(request));
    builder.setHeader("Content-Length", Integer.toString(body.length()));
    if (requestCookie != null)
        if (Cookies.getCookie(requestCookie) != null)
            builder.setHeader("X-Cookie", Cookies.getCookie(requestCookie));
    if (username != null)
        builder.setUser(username);
    if (password != null)
        builder.setPassword(password);
    try {
        builder.sendRequest(body, handler);
    } catch (RequestException exception) {
        handler.onError(null, exception);
    }
}

From source file:net.meddeb.md.admin.client.MenuLauncher.java

License:Open Source License

private boolean isCurrent(MDDAMenu menu) {
    String strMenu = Cookies.getCookie(MENUTAG);
    MDDAMenu currMenu = MDDAMenu.fromName(strMenu);
    return ((currMenu != null) && (currMenu == menu));
}

From source file:net.meddeb.md.admin.client.MenuLauncher.java

License:Open Source License

private boolean isConnected() {
    String sessionID = Cookies.getCookie(SESSIONTAG);
    return ((sessionID != null) && (!sessionID.isEmpty()));
}

From source file:net.meddeb.md.admin.client.MenuManager.java

License:Open Source License

private MDDAMenu getCurrentmenu() {
    String strMenu = Cookies.getCookie(MenuLauncher.MENUTAG);
    MDDAMenu rslt = MDDAMenu.fromName(strMenu);
    return rslt;
}

From source file:net.meddeb.md.core.presentation.MenuLauncher.java

License:Open Source License

private boolean isCurrent(MDCoreMenu menu) {
    String strMenu = Cookies.getCookie(MENUTAG);
    MDCoreMenu currMenu = MDCoreMenu.fromName(strMenu);
    return ((currMenu != null) && (currMenu == menu));
}

From source file:net.meddeb.md.core.presentation.MenuManager.java

License:Open Source License

private MDCoreMenu getCurrentmenu() {
    String strMenu = Cookies.getCookie(MenuLauncher.MENUTAG);
    MDCoreMenu rslt = MDCoreMenu.fromName(strMenu);
    return rslt;
}

From source file:net.s17fabu.vip.gwt.showcase.client.content.other.CwCookies.java

License:Apache License

/**
 * Retrieve the value of the existing cookie and put it into to value label.
 *//*  www. ja  v  a 2s  . c o  m*/
private void updateExstingCookie() {
    // Cannot update if there are no items
    if (existingCookiesBox.getItemCount() < 1) {
        cookieNameBox.setText("");
        cookieValueBox.setText("");
        return;
    }

    int selectedIndex = existingCookiesBox.getSelectedIndex();
    String cookieName = existingCookiesBox.getValue(selectedIndex);
    String cookieValue = Cookies.getCookie(cookieName);
    cookieNameBox.setText(cookieName);
    cookieValueBox.setText(cookieValue);
}

From source file:net.sf.gudoku.client.Gudoku.java

License:Open Source License

private int getNextGameIdFromCookie() {
    String gameIdAsString = Cookies.getCookie(GAME_ID_COOKIE_NAME);
    int gameId = 0;
    if (gameIdAsString != null && gameIdAsString.length() > 0) {
        gameId = Integer.parseInt(gameIdAsString);
    }//from   www .java2 s  .co  m
    gameId += 1;
    Cookies.setCookie(GAME_ID_COOKIE_NAME, String.valueOf(gameId));
    return gameId;
}

From source file:net.vleu.par.gwt.client.storage.PersistentStorage.java

License:Open Source License

/**
 * Reads {@link #cookiesJson} save by {@link #writeCookies()} in the
 * browser's cookie jar/*from  w  w  w  .jav  a 2s .  co  m*/
 * 
 * @return The unserialized object, or null if there weren't any
 */
private JSONObject readCookies() {
    final String serializedCookies = Cookies.getCookie(COOKIE_NAME);
    JSONValue jsonValue;
    if (serializedCookies == null)
        return null;
    try {
        jsonValue = JSONParser.parseLenient(serializedCookies);
    } catch (final Exception _) {
        return null;
    }
    return jsonValue.isObject();
}

From source file:olanto.myTerm.client.CookiesManager.MyTermCookies.java

License:Open Source License

public static void initCookie(String name, String value) {
    Date expires = new Date(System.currentTimeMillis() + (1000L * 3600L * 24L * (long) GuiConstant.EXP_DAYS));
    if ((Cookies.getCookie(name) == null) || (Cookies.getCookie(name).equalsIgnoreCase("null"))) {
        Cookies.setCookie(name, value, expires);
    }//from   w w  w  .  j  a v a 2s .c o m
}