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

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

Introduction

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

Prototype

public static Collection<String> getCookieNames() 

Source Link

Document

Gets the names of all cookies in this page's domain.

Usage

From source file:com.dawg6.web.dhcalc.client.BasePanel.java

License:Open Source License

protected boolean loadStorage() {

    boolean result = false;

    if (Storage.isLocalStorageSupported()) {
        Storage storage = Storage.getLocalStorageIfSupported();

        Collection<String> cookies = null;

        if (Cookies.isCookieEnabled()) {
            cookies = Cookies.getCookieNames();
        }// www  .j  a  va  2 s.  c om

        for (Field f : getFields()) {
            String value = storage.getItem(f.name);

            if (value != null) {
                // do nothing
            } else if ((cookies != null) && (cookies.contains(f.name))) {
                value = getCookie(f.name, f.defaultValue);
                storage.setItem(f.name, value);
                Cookies.removeCookie(f.name);
            } else {
                value = f.defaultValue;
                storage.setItem(f.name, value);
            }

            setFieldValue(f, value);
        }

        result = true;
    }

    return result;
}

From source file:com.google.gwt.sample.showcase.client.content.other.CwCookies.java

License:Apache License

/**
 * Refresh the list of existing cookies.
 *
 * @param selectedCookie the cookie to select by default
 *///from  w  w  w.j  a  v  a 2  s  .c o  m
@ShowcaseSource
private void refreshExistingCookies(String selectedCookie) {
    // Clear the existing cookies
    existingCookiesBox.clear();

    // Add the cookies
    int selectedIndex = 0;
    Collection<String> cookies = Cookies.getCookieNames();
    for (String cookie : cookies) {
        existingCookiesBox.addItem(cookie);
        if (cookie.equals(selectedCookie)) {
            selectedIndex = existingCookiesBox.getItemCount() - 1;
        }
    }

    // Select the index of the selectedCookie. Use a ScheduledCommand to give
    // the options time to register in Opera.
    final int selectedIndexFinal = selectedIndex;
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        public void execute() {
            // Select the default cookie
            if (selectedIndexFinal < existingCookiesBox.getItemCount()) {
                existingCookiesBox.setSelectedIndex(selectedIndexFinal);
            }

            // Display the selected cookie value
            updateExstingCookie();
        }
    });
}

From source file:com.gwtmodel.table.Utils.java

License:Apache License

public static List<IMapEntry> getCookies() {
    List<IMapEntry> cList = new ArrayList<IMapEntry>();
    Collection<String> cookies = Cookies.getCookieNames();
    final String p = jPrefix();
    for (final String s : cookies) {
        if (!s.startsWith(p))
            continue;
        final String value = Cookies.getCookie(s);
        IMapEntry i = new IMapEntry() {

            @Override//from  ww w.  j a va2s . c  o  m
            public String getKey() {
                return s.substring(p.length());
            }

            @Override
            public String getValue() {
                return value;
            }

        };
        cList.add(i);
    }
    return cList;
}

From source file:com.nanosim.client.content.other.CwCookies.java

License:Apache License

/**
 * Refresh the list of existing cookies.
 * /*w  w  w  . j  a v a 2 s.co m*/
 * @param selectedCookie the cookie to select by default
 */
@NanosimSource
private void refreshExistingCookies(String selectedCookie) {
    // Clear the existing cookies
    existingCookiesBox.clear();

    // Add the cookies
    int selectedIndex = 0;
    Collection<String> cookies = Cookies.getCookieNames();
    for (String cookie : cookies) {
        existingCookiesBox.addItem(cookie);
        if (cookie.equals(selectedCookie)) {
            selectedIndex = existingCookiesBox.getItemCount() - 1;
        }
    }

    // Select the index of the selectedCookie. Use a DeferredCommand to give
    // the options time to register in Opera.
    final int selectedIndexFinal = selectedIndex;
    DeferredCommand.addCommand(new Command() {
        public void execute() {
            // Select the default cookie
            if (selectedIndexFinal < existingCookiesBox.getItemCount()) {
                existingCookiesBox.setSelectedIndex(selectedIndexFinal);
            }

            // Display the selected cookie value
            updateExstingCookie();
        }
    });
}

From source file:com.ponysdk.core.terminal.ui.PTCookies.java

License:Apache License

public PTCookies(final UIBuilder uiBuilder) {
    final Collection<String> cookieNames = Cookies.getCookieNames();
    final JSONArray cookies = new JSONArray();
    if (cookieNames != null) {
        int i = 0;
        for (final String cookie : cookieNames) {
            final JSONObject jsoObject = new JSONObject();
            jsoObject.put(ClientToServerModel.COOKIE_NAME.toStringValue(), new JSONString(cookie));
            jsoObject.put(ClientToServerModel.COOKIE_VALUE.toStringValue(),
                    new JSONString(Cookies.getCookie(cookie)));
            cookies.set(i++, jsoObject);
        }/*from  w  w w .  j  a v a 2s.com*/
    }

    final PTInstruction eventInstruction = new PTInstruction(getObjectID());
    eventInstruction.put(ClientToServerModel.COOKIES, cookies);
    uiBuilder.sendDataToServer(eventInstruction);
}

From source file:com.ponysdk.ui.terminal.CommunicationEntryPoint.java

License:Apache License

@Override
public void onModuleLoad() {
    GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override//from w ww  .  j a v a2 s.  c o  m
        public void onUncaughtException(final Throwable e) {
            log.log(Level.SEVERE, "PonySDK has encountered an internal error : ", e);
            Window.alert("PonySDK has encountered an internal error : " + e.getMessage());
        }
    });

    try {

        final PTInstruction requestData = new PTInstruction();

        final JSONArray cookies = new JSONArray();

        // load all cookies at startup
        final Collection<String> cookieNames = Cookies.getCookieNames();
        if (cookieNames != null) {
            final int i = 0;
            for (final String cookie : cookieNames) {
                cookies.set(i, new JSONString(Cookies.getCookie(cookie)));
            }
        }

        requestData.put(APPLICATION.KEY, APPLICATION.KEY_.START);
        requestData.put(HISTORY.TOKEN, History.getToken());
        requestData.put(PROPERTY.COOKIE, cookies);

        final RequestCallback requestCallback = new RequestCallback() {

            @Override
            public void onDataReceived(final JSONObject data) {
                try {
                    final List<PTInstruction> instructions = new ArrayList<PTInstruction>();

                    if (data.containsKey(APPLICATION.VIEW_ID)) {
                        final long viewID = (long) data.get(APPLICATION.VIEW_ID).isNumber().doubleValue();
                        final JSONArray jsonArray = data.get(APPLICATION.INSTRUCTIONS).isArray();

                        for (int i = 0; i < jsonArray.size(); i++) {
                            instructions
                                    .add(new PTInstruction(jsonArray.get(i).isObject().getJavaScriptObject()));
                        }

                        uiBuilder = new UIBuilder(viewID, requestBuilder);
                        uiBuilder.init();
                        uiBuilder.update(instructions);
                        uiBuilder.hideLoadingMessageBox();
                    } else {
                        final JSONArray jsonArray = data.get(APPLICATION.INSTRUCTIONS).isArray();

                        for (int i = 0; i < jsonArray.size(); i++) {
                            instructions
                                    .add(new PTInstruction(jsonArray.get(i).isObject().getJavaScriptObject()));
                        }

                        uiBuilder.update(instructions);
                        uiBuilder.hideLoadingMessageBox();
                    }
                } catch (final RuntimeException exception) {
                    Window.alert("Loading application has failed #" + exception);
                }
            }

            @Override
            public void onError(final Throwable exception) {
                uiBuilder.onCommunicationError(exception);
            }
        };

        requestBuilder = new HttpRequestBuilder(requestCallback);
        requestBuilder.send(requestData.toString());

    } catch (final Exception e) {
        Window.alert("Loading application has failed #" + e);
    }
}

From source file:com.ponysdk.ui.terminal.PonySDK.java

License:Apache License

@Export
public void start() {
    log("starting...");

    try {/*from  ww  w . j ava2 s. c om*/

        Long viewID = null;
        final Storage storage = Storage.getSessionStorageIfSupported();
        if (storage != null) {
            final String v = storage.getItem(APPLICATION.VIEW_ID);
            if (v != null && !v.isEmpty())
                viewID = Long.parseLong(v);
        }
        final PTInstruction requestData = new PTInstruction();

        final JSONArray cookies = new JSONArray();

        // load all cookies at startup
        final Collection<String> cookieNames = Cookies.getCookieNames();
        if (cookieNames != null) {
            int i = 0;
            for (final String cookie : cookieNames) {
                final JSONObject jsoObject = new JSONObject();
                jsoObject.put(PROPERTY.KEY, new JSONString(cookie));
                jsoObject.put(PROPERTY.VALUE, new JSONString(Cookies.getCookie(cookie)));
                cookies.set(i++, jsoObject);
            }
        }

        requestData.put(APPLICATION.KEY, APPLICATION.KEY_.START);
        requestData.put(APPLICATION.SEQ_NUM, 0);
        requestData.put(HISTORY.TOKEN, History.getToken());
        requestData.put(PROPERTY.COOKIES, cookies);

        if (viewID != null)
            requestData.put(APPLICATION.VIEW_ID, viewID);

        final RequestCallback requestCallback = new RequestCallback() {

            @Override
            public void onDataReceived(final JSONObject data) {
                try {
                    if (data.containsKey(APPLICATION.VIEW_ID)) {
                        applicationViewID = (long) data.get(APPLICATION.VIEW_ID).isNumber().doubleValue();

                        if (storage != null)
                            storage.setItem(APPLICATION.VIEW_ID, Long.toString(applicationViewID));

                        uiBuilder.init(applicationViewID, requestBuilder);
                    }

                    uiBuilder.update(data);

                } catch (final RuntimeException exception) {
                    log.log(Level.SEVERE,
                            "Failed to process data with error #" + exception.getMessage() + ", data: " + data,
                            exception);
                }
            }

            @Override
            public void onError(final Throwable exception) {
                uiBuilder.onCommunicationError(exception);
            }

        };

        requestBuilder = newRequestBuilder(requestCallback);
        requestBuilder.send(requestData.toString());

    } catch (final Exception e) {
        log.log(Level.SEVERE, "Loading application has failed #" + e.getMessage(), e);
    }
}

From source file:com.seanchenxi.gwt.serenity.client.SerenityUtil.java

License:Apache License

public static boolean isLoggedIn() {
    for (String name : Cookies.getCookieNames()) {
        if (name != null && name.contains("logged") && name.contains("in")) {
            return true;
        }// ww w.  ja v a 2s .  c  o  m
    }
    return false;
}

From source file:fr.insalyon.creatis.vip.portal.client.Main.java

License:Open Source License

private void configureVIP() {

    // Cookies//w w w.ja va 2s . co m
    String email = null;
    String session = null;

    if (Cookies.getCookieNames().contains(CoreConstants.COOKIES_USER)) {
        email = Cookies.getCookie(CoreConstants.COOKIES_USER);
        session = Cookies.getCookie(CoreConstants.COOKIES_SESSION);
    }
    // End-Cookies

    final ConfigurationServiceAsync service = ConfigurationService.Util.getInstance();
    final AsyncCallback<User> callback = new AsyncCallback<User>() {
        @Override
        public void onFailure(Throwable caught) {
            Layout.getInstance().getModal().hide();
            SC.warn("Error while configuring VIP:<br />" + caught.getMessage());
        }

        @Override
        public void onSuccess(User user) {
            Layout.getInstance().getModal().hide();
            Layout.getInstance().authenticate(user);

            //Dropbox account confirmation
            String oauth_token = Window.Location.getParameter("oauth_token");
            if (oauth_token != null && !oauth_token.equals("")) {
                service.activateDropboxAccount(oauth_token, new AsyncCallback<Void>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        Layout.getInstance().setWarningMessage("Cannot activate Dropbox account");
                    }

                    @Override
                    public void onSuccess(Void result) {
                        Layout.getInstance().setNoticeMessage("Successfully activated Dropbox account");

                    }
                });
            }
        }
    };
    service.configure(email, session, callback);
}

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

License:Apache License

/**
 * Refresh the list of existing cookies.
 * //from   w w w. j  a  v  a 2s . c  o m
 * @param selectedCookie the cookie to select by default
 */
private void refreshExistingCookies(String selectedCookie) {
    // Clear the existing cookies
    existingCookiesBox.clear();

    // Add the cookies
    int selectedIndex = 0;
    Collection<String> cookies = Cookies.getCookieNames();
    for (String cookie : cookies) {
        existingCookiesBox.addItem(cookie);
        if (cookie.equals(selectedCookie)) {
            selectedIndex = existingCookiesBox.getItemCount() - 1;
        }
    }

    // Select the index of the selectedCookie. Use a DeferredCommand to give
    // the options time to register in Opera.
    final int selectedIndexFinal = selectedIndex;
    DeferredCommand.addCommand(new Command() {
        public void execute() {
            // Select the default cookie
            if (selectedIndexFinal < existingCookiesBox.getItemCount()) {
                existingCookiesBox.setSelectedIndex(selectedIndexFinal);
            }

            // Display the selected cookie value
            updateExstingCookie();
        }
    });
}