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

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

Introduction

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

Prototype

public static void setCookie(String name, String value, Date expires, String domain, String path,
        boolean secure) 

Source Link

Document

Sets a cookie.

Usage

From source file:cc.kune.core.client.cookies.MotdManager.java

License:GNU Affero Public License

private void setCookie(final String motdCookieName, final Date expires) {
    Cookies.removeCookie(motdCookieName);
    Cookies.setCookie(motdCookieName, null, expires, null, "/", WindowUtils.isHttps());
}

From source file:cc.kune.wave.client.kspecific.tutorial.InboxTutorial.java

License:GNU Affero Public License

@Inject
public InboxTutorial(GSpaceArmor armor, EventBus eventBus, final WaveClientProvider waveClient) {
    final String cookie = Cookies.getCookie(COOKIE_NAME);
    if (cookie == null) {
        initWidget(uiBinder.createAndBindUi(this));
        armor.wrapDiv(PolymerId.INBOX_TUTORIAL).add(this);
        selectHandler = eventBus.addHandler(SpaceSelectEvent.getType(), new SpaceSelectHandler() {
            @Override//from   w  w  w  .  jav a 2  s  . c  om
            public void onSpaceSelect(SpaceSelectEvent event) {
                if (event.getSpace().equals(Space.userSpace)) {
                    final String encodedToken = HistoryUtils.undoHashbang(History.getToken());
                    if (encodedToken != null && !encodedToken.isEmpty()
                            && TokenMatcher.isInboxToken(encodedToken)) {
                        // Inbox without wave opened
                        setVisible(true);
                        waveClient.get().clear();
                    }
                }
            }
        });
        openHandler = eventBus.addHandler(AfterOpenWaveEvent.getType(), new AfterOpenWaveHandler() {
            @Override
            public void onAfterOpenWave(AfterOpenWaveEvent event) {
                setVisible(false);
            }
        });
        subtitleLabel.setText(I18n.tWithNT("This is your", "Followed by 'inbox', so 'This is your inbox'"));
        titleLabel.setText(I18n.t("Inbox"));
        createLabel.setText(I18n.t("Here you can create, edit and comment documents"));
        addContactLabel.setText(I18n.t("Share them with your contacts"));
        publishLabel.setText(I18n.t("Publish them in your groups"));
        notificationsLabel
                .setText(I18n.t("Get notifications of changes, coments or new documents shared with you"));
        orderedLabel.setText(
                I18n.t("And to have a cronological ordered list of all the contents you are participating in"));
        btn.setText(I18n.t("I got it!"));
        btn.setType(ButtonType.PRIMARY);
        btn.setSize(ButtonSize.LARGE);
        btn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                $(InboxTutorial.this).as(Effects).fadeTo(400, 0);
                Cookies.setCookie(COOKIE_NAME, null, CookieUtils.expireInYears(), CookieUtils.getDomain(), "/",
                        false);
                selectHandler.removeHandler();
                openHandler.removeHandler();
            }
        });
    }
}

From source file:com.eucalyptus.webui.client.session.LocalSessionImpl.java

License:Open Source License

@Override
public void saveSession(Session s, boolean persistent) {
    if (s == null) {
        clearSession();/*from  w w  w  .j a v  a  2  s.c o  m*/
    } else {
        this.session = s;
        if (persistent) {
            Date expiration = new Date(System.currentTimeMillis() + COOKIE_LIFE_IN_MS);
            Cookies.setCookie(SESSION_COOKIE_NAME, this.session.getId(), expiration, null, null,
                    USE_SECURE_COOKIE);
        } else {
            Cookies.setCookie(SESSION_COOKIE_NAME, this.session.getId(), null, null, null, USE_SECURE_COOKIE);
        }
    }
}

From source file:com.extjs.gxt.ui.client.state.CookieProvider.java

License:sencha.com license

protected void setValue(String name, String value) {
    Cookies.setCookie(name, value, expires, domain, path, secure);
}

From source file:com.extjs.gxt.ui.client.state.CookieProvider.java

License:sencha.com license

public void set(String name, String value, Date expires) {
    Cookies.setCookie(name, value, expires, domain, path, secure);
}

From source file:com.google.gwt.sample.feedreader.client.Configuration.java

License:Apache License

/**
 * Save the configuration into the application's cookie.
 *//* ww w .ja v a  2s.  c  o  m*/
public void save() {
    Cookies.setCookie(COOKIE_NAME, container.toString(),
            new Date(System.currentTimeMillis() + 1000L * 60 * 60 * 24 * 365), null, null, false);

    System.out.println(Cookies.getCookie(COOKIE_NAME));
}

From source file:com.gwtplatform.carstore.client.application.login.LoginPresenter.java

License:Apache License

private void setLoggedInCookie(String value) {
    Cookies.removeCookie(LOGIN_COOKIE_NAME);

    Date expires = new Date();
    CalendarUtil.addDaysToDate(expires, 14);
    String domain = getDomain();//from   w w w . j a v a  2s  .co m
    String path = "/";
    boolean secure = false;
    Cookies.setCookie(LOGIN_COOKIE_NAME, value, expires, domain, path, secure);

    logger.info("LoginPresenter.setLoggedInCookie() Set client cookie=" + value);
}

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

License:Apache License

@Override
public boolean update(final ReaderBuffer buffer, final BinaryModel binaryModel) {
    final ServerToClientModel model = binaryModel.getModel();
    if (ServerToClientModel.ADD_COOKIE == model) {
        final String name = binaryModel.getStringValue();
        // ServerToClientModel.VALUE
        final String value = buffer.readBinaryModel().getStringValue();

        final BinaryModel expireModel = buffer.readBinaryModel();
        final Date expirationDate;
        if (ServerToClientModel.COOKIE_EXPIRE == expireModel.getModel()) {
            expirationDate = new Date(expireModel.getLongValue());
        } else {//from w w  w.  j av  a  2  s  . c  om
            expirationDate = null;
            buffer.rewind(expireModel);
        }

        final BinaryModel domainModel = buffer.readBinaryModel();
        final String domain;
        if (ServerToClientModel.COOKIE_DOMAIN == domainModel.getModel()) {
            domain = domainModel.getStringValue();
        } else {
            domain = null;
            buffer.rewind(domainModel);
        }

        final BinaryModel pathModel = buffer.readBinaryModel();
        final String path;
        if (ServerToClientModel.COOKIE_PATH == pathModel.getModel()) {
            path = pathModel.getStringValue();
        } else {
            path = null;
            buffer.rewind(pathModel);
        }

        final BinaryModel secureModel = buffer.readBinaryModel();
        final boolean secure;
        if (ServerToClientModel.COOKIE_SECURE == secureModel.getModel()) {
            secure = true;
        } else {
            secure = false;
            buffer.rewind(secureModel);
        }

        Cookies.setCookie(name, value, expirationDate, domain, path, secure);

        return true;
    } else if (ServerToClientModel.REMOVE_COOKIE == model) {
        final String name = binaryModel.getStringValue();
        final BinaryModel path = buffer.readBinaryModel();
        if (ServerToClientModel.COOKIE_PATH == path.getModel()) {
            Cookies.removeCookie(name, path.getStringValue());
        } else {
            buffer.rewind(path);
            Cookies.removeCookie(name);
        }
        return true;
    } else {
        return super.update(buffer, binaryModel);
    }
}

From source file:com.sencha.gxt.state.client.CookieProvider.java

License:sencha.com license

@Override
public void setValue(String name, String value) {
    Cookies.setCookie(name, value, expires, domain, path, secure);
}

From source file:es.deusto.weblab.client.WebLabLabLoader.java

License:Open Source License

public void loadLabApp() {

    // We need to initialize the AudioManager singleton
    AudioManager.initialize(this.configurationManager);

    try {//  ww w.j  av a 2 s .  co m
        ExperimentFactory.loadExperiments(this.configurationManager);
    } catch (final Exception e) {
        this.weblabClient.showError("Error checking experiments: " + e.getMessage());
        e.printStackTrace();
        return;
    }

    final ILabCommunication communications = new LabCommunication(this.configurationManager);

    final PollingHandler pollingHandler = new PollingHandler(this.configurationManager);

    final boolean isUsingMobile = this.weblabClient.isMobile();

    final ILabController controller = new LabController(this.configurationManager, communications,
            pollingHandler, isUsingMobile, this.isFacebook());

    pollingHandler.setController(controller);

    final IWlLabThemeLoadedCallback themeLoadedCallback = new IWlLabThemeLoadedCallback() {

        @Override
        public void onThemeLoaded(final LabThemeBase theme) {
            controller.setUIManager(theme);
            boolean stillWaiting = false;
            try {
                String providedSessionId = Window.Location.getParameter(WebLabLabLoader.SESSION_ID_URL_PARAM);
                if (providedSessionId == null)
                    providedSessionId = HistoryProperties.getValue(WebLabLabLoader.SESSION_ID_URL_PARAM);

                String providedReservationId = Window.Location
                        .getParameter(WebLabLabLoader.RESERVATION_ID_URL_PARAM);
                if (providedReservationId == null)
                    providedReservationId = HistoryProperties
                            .getValue(WebLabLabLoader.RESERVATION_ID_URL_PARAM);

                ExperimentID experimentId = null;
                if (providedReservationId != null) {
                    final String selectedExperimentName = HistoryProperties
                            .getValue(HistoryProperties.EXPERIMENT_NAME);
                    final String selectedExperimentCategory = HistoryProperties
                            .getValue(HistoryProperties.EXPERIMENT_CATEGORY);

                    experimentId = new ExperimentID(new Category(selectedExperimentCategory),
                            selectedExperimentName);
                }

                if (providedReservationId != null && experimentId != null) {
                    final String reservationId;
                    final int position = providedReservationId.indexOf(';');
                    if (position >= 0) {
                        reservationId = providedReservationId.substring(0, position);
                        final String cookie = providedReservationId.substring(position + 1);
                        Cookies.setCookie(WebLabLabLoader.WEBLAB_SESSION_ID_COOKIE, cookie, null, null,
                                WebLabClient.baseLocation + "/weblab/", false);
                    } else
                        reservationId = providedReservationId;
                    controller.startReserved(new SessionID(reservationId), experimentId);

                } else if (providedSessionId != null) {
                    final String sessionId;
                    final int position = providedSessionId.indexOf(';');
                    if (position >= 0) {
                        sessionId = providedSessionId.substring(0, position);
                        final String cookie = providedSessionId.substring(position + 1);
                        Cookies.setCookie(WebLabLabLoader.WEBLAB_SESSION_ID_COOKIE, cookie, null, null,
                                WebLabClient.baseLocation + "/weblab/", false);
                    } else
                        sessionId = providedSessionId;
                    controller.startLoggedIn(new SessionID(sessionId), true);
                } else {
                    final String possibleSessionId = Cookies
                            .getCookie(WebLabLabLoader.WEBLAB_SESSION_ID_COOKIE);
                    if (possibleSessionId == null) {
                        theme.onInit(); // If it's still null...
                    } else {
                        final SessionID tentativeSessionId;
                        if (possibleSessionId.contains("."))
                            tentativeSessionId = new SessionID(
                                    possibleSessionId.substring(0, possibleSessionId.indexOf('.')));
                        else
                            tentativeSessionId = new SessionID(possibleSessionId);
                        controller.checkSessionIdStillValid(tentativeSessionId, new IValidSessionCallback() {
                            @Override
                            public void sessionRejected() {
                                theme.onInit();
                                WebLabLabLoader.this.weblabClient.putWidget(theme.getWidget());
                                theme.onLoaded();
                            }

                            @Override
                            public void sessionConfirmed() {
                                controller.startLoggedIn(tentativeSessionId, false);
                            }
                        });
                    }
                }

                System.out.println("----->>> providedSessionId " + providedSessionId);
                System.out.println("----->>> providedReservationId " + providedReservationId);
                System.out.println("----->>> experimentId " + experimentId);

            } catch (final Exception e) {
                WebLabLabLoader.this.weblabClient.showError("Error initializing theme: " + e.getMessage());
                e.printStackTrace();
                return;
            }

            if (!stillWaiting) {
                WebLabLabLoader.this.weblabClient.putWidget(theme.getWidget());
                theme.onLoaded();
            }
        }

        @Override
        public void onFailure(Throwable e) {
            WebLabLabLoader.this.weblabClient.showError("Error creating theme: " + e.getMessage() + "; " + e);
            return;
        }
    };

    try {
        LabThemeFactory.themeFactory(this.configurationManager, controller,
                this.configurationManager.getProperty(WebLabClient.THEME_PROPERTY, WebLabClient.DEFAULT_THEME),
                isUsingMobile, themeLoadedCallback);
    } catch (final Exception e) {
        this.weblabClient.showError("Error creating theme: " + e.getMessage() + "; " + e);
        return;
    }
}