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.sigmah.client.offline.OfflineStatus.java

License:Open Source License

public boolean isOfflineInstalled() {
    return "installed".equals(Cookies.getCookie(offlineCookieName)) || isOfflineEnabled();
}

From source file:org.sigmah.client.page.login.LoginView.java

License:Open Source License

public LoginView() {
    final SimplePanel panel = new SimplePanel();
    panel.setStyleName("login-background");

    final Grid grid = new Grid(1, 2);
    grid.setStyleName("login-box");

    // Logo//from w w w  . j a v a2 s  . c  om
    grid.setWidget(0, 0, new Image("image/login-logo.png"));

    // Form
    final FlexTable form = new FlexTable();
    form.setWidth("90%");

    int y = 0;

    // E-Mail field
    form.setText(y, 0, I18N.CONSTANTS.loginLoginField());
    form.getCellFormatter().setStyleName(y, 0, "login-box-form-label");

    final TextBox loginTextBox = new TextBox();
    loginTextBox.setWidth("100%");
    form.setWidget(y, 1, loginTextBox);
    form.getFlexCellFormatter().setColSpan(y, 1, 2);
    y++;

    // Separator
    for (int i = 0; i < 3; i++)
        form.getCellFormatter().setStyleName(y, i, "login-box-form-separator");
    y++;

    // Password field
    form.setText(y, 0, I18N.CONSTANTS.loginPasswordField());
    form.getCellFormatter().setStyleName(y, 0, "login-box-form-label");

    final PasswordTextBox passwordTextBox = new PasswordTextBox();
    passwordTextBox.setWidth("100%");
    form.setWidget(y, 1, passwordTextBox);
    form.getFlexCellFormatter().setColSpan(y, 1, 2);
    y++;

    // Separator
    for (int i = 0; i < 3; i++)
        form.getCellFormatter().setStyleName(y, i, "login-box-form-separator");
    y++;

    // Language field
    form.setText(y, 0, I18N.CONSTANTS.loginLanguageField());
    form.getCellFormatter().setStyleName(y, 0, "login-box-form-label");

    int selection = 0;
    final String currentLanguage = Cookies.getCookie(org.sigmah.shared.Cookies.LOCALE_COOKIE);

    final ListBox languageListBox = new ListBox(false);
    int index = 0;
    for (final Map.Entry<String, String> entry : languageMap.entrySet()) {
        languageListBox.addItem(entry.getKey(), entry.getValue());
        if (entry.getValue().equals(currentLanguage))
            selection = index;
        index++;
    }
    languageListBox.setSelectedIndex(selection);
    languageListBox.setWidth("100%");
    form.setWidget(y, 1, languageListBox);
    form.getFlexCellFormatter().setColSpan(y, 1, 2);
    y++;

    // Separator
    for (int i = 0; i < 3; i++)
        form.getCellFormatter().setStyleName(y, i, "login-box-form-separator");
    y++;

    // Password forgotten link
    final FlowPanel bottomPanel = new FlowPanel();
    bottomPanel.getElement().getStyle().setPosition(Position.RELATIVE);

    final Anchor label = new Anchor(I18N.CONSTANTS.loginPasswordForgotten());
    label.setStyleName("login-box-form-forgotten");
    label.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {

            MessageBox.prompt(I18N.CONSTANTS.loginPasswordForgotten(), I18N.CONSTANTS.loginLoginField(),
                    new Listener<MessageBoxEvent>() {

                        @Override
                        public void handleEvent(MessageBoxEvent be) {
                            // If the user clicked on "OK".
                            if (Dialog.OK.equals(be.getButtonClicked().getItemId())) {
                                final Dialog waitDialog = new Dialog();
                                waitDialog.setHeading(I18N.CONSTANTS.loginPasswordForgotten());
                                waitDialog.addText(I18N.CONSTANTS.loading());
                                waitDialog.setButtons("");
                                waitDialog.setModal(true);
                                waitDialog.setClosable(false);
                                waitDialog.show();

                                final String email = be.getValue();

                                final PasswordManagementServiceAsync service = GWT
                                        .create(PasswordManagementService.class);
                                service.forgotPassword(email,
                                        languageListBox.getValue(languageListBox.getSelectedIndex()),
                                        GWT.getModuleBaseURL(), new AsyncCallback<Void>() {

                                            @Override
                                            public void onFailure(Throwable caught) {
                                                waitDialog.hide();
                                                MessageBox.alert(I18N.CONSTANTS.loginPasswordForgotten(),
                                                        I18N.MESSAGES.loginRetrievePasswordBadLogin(email),
                                                        null);
                                            }

                                            @Override
                                            public void onSuccess(Void result) {
                                                waitDialog.hide();
                                                MessageBox.alert(I18N.CONSTANTS.loginPasswordForgotten(),
                                                        I18N.MESSAGES.loginResetPasswordSuccessfull(email),
                                                        null);
                                            }
                                        });
                            }
                        }
                    });
        }
    });
    bottomPanel.add(label);

    final Image loader = new Image("image/login-loader.gif");
    loader.getElement().getStyle().setVisibility(Visibility.HIDDEN);
    loader.getElement().getStyle().setMarginTop(-8, Unit.PX);
    loader.getElement().getStyle().setPosition(Position.ABSOLUTE);
    loader.getElement().getStyle().setTop(50, Unit.PCT);
    loader.getElement().getStyle().setRight(2, Unit.PX);
    bottomPanel.add(loader);

    form.setWidget(y, 0, bottomPanel);
    form.getFlexCellFormatter().setColSpan(y, 0, 2);

    // Login button
    final Button loginButton = new Button(I18N.CONSTANTS.loginConnectButton());
    loginButton.setWidth("120px");
    form.setWidget(y, 1, loginButton);
    form.getCellFormatter().setHorizontalAlignment(y, 1, HasHorizontalAlignment.ALIGN_RIGHT);
    y++;

    // Login actions
    loginButton.addListener(Events.Select, new Listener<BaseEvent>() {
        @Override
        public void handleEvent(BaseEvent be) {
            Cookies.setCookie(org.sigmah.shared.Cookies.LOCALE_COOKIE,
                    languageListBox.getValue(languageListBox.getSelectedIndex()));
            doLogin(loginTextBox.getText(), passwordTextBox.getText(), loginButton, loader);
        }
    });

    final KeyDownHandler handler = new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                loginButton.fireEvent(Events.Select);
            }
        }
    };
    loginTextBox.addKeyDownHandler(handler);
    passwordTextBox.addKeyDownHandler(handler);

    // Adding the form to the orange box
    grid.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    grid.setWidget(0, 1, form);

    // Styles
    grid.getCellFormatter().setStyleName(0, 0, "login-box-logo");
    grid.getCellFormatter().setStyleName(0, 1, "login-box-form");

    panel.add(grid);

    initWidget(panel);
}

From source file:org.sigmah.client.security.AuthenticationProvider.java

License:Open Source License

/**
 * Returns the authentication token.//from w  ww. j ava 2  s .  c  o  m
 * <p>
 * When anonymous, <code>null</code> is returned.
 * </p>
 * 
 * @return The authentication token or <code>null</code> if anonymous.
 */
public String getAuthenticationToken() {

    return Cookies.getCookie(org.sigmah.shared.Cookies.AUTH_TOKEN_COOKIE);
}

From source file:org.sigmah.client.security.AuthenticationProvider.java

License:Open Source License

/**
 * <p>/*  ww  w  . j  a v a 2  s. c o  m*/
 * Updates the cached {@link Authentication} instance.
 * </p>
 * <p>
 * <em>Should be called <b>exclusively</b> by {@link org.sigmah.client.event.EventBus}.</em>
 * </p>
 * 
 * @param authentication
 *          The authentication. Its {@code authenticationToken} is automatically updated with the one set in cookie.
 */
public void updateCache(final Authentication authentication) {

    if (authentication == null) {
        clearAuthentication();
        return;
    }

    // Caches the authentication data.
    authentication.setAuthenticationToken(Cookies.getCookie(org.sigmah.shared.Cookies.AUTH_TOKEN_COOKIE));
    this.authentication = authentication;
}

From source file:org.sonatype.nexus.ext.gwt.ui.client.ApplicationContext.java

License:Open Source License

public String getCookie(String name) {
    return Cookies.getCookie("st-" + name);
}

From source file:org.spiffyui.client.rest.RESTility.java

License:Apache License

/**
 * The normal GWT mechanism for removing cookies will remove a cookie at the path
 * the page is on.  The is a possibility that the session cookie was set on the
 * server with a slightly different path.  In that case we need to try to delete
 * the cookie on all the paths of the current URL.  This method handles that case.
 * /*w w  w.  j av a2 s . c om*/
 * @param name   the name of the cookie to remove
 */
private static void removeCookie(String name) {
    Cookies.removeCookie(name);
    if (Cookies.getCookie(name) != null) {
        /*
         * This could mean that the cookie was there,
         * but was on a different path than the one that
         * we get by default.
         */
        removeCookie(name, Window.Location.getPath());
    }
}

From source file:org.spiffyui.client.rest.RESTility.java

License:Apache License

private static void removeCookie(String name, String currentPath) {
    Cookies.removeCookie(name, currentPath);
    if (Cookies.getCookie(name) != null) {
        /*/*from  w w  w  .j a va2 s .c  om*/
         * This could mean that the cookie was there,
         * but was on a different path than the one that
         * we were passed.  In that case we'll bump up
         * the path and try again.
         */
        String path = currentPath;
        if (path.charAt(0) != '/') {
            path = "/" + path;
        }

        int slashloc = path.lastIndexOf('/');
        if (slashloc > 1) {
            path = path.substring(0, slashloc);
            removeCookie(name, path);
        }
    }
}

From source file:org.spiffyui.client.rest.RESTility.java

License:Apache License

private static void checkSessionCookie() {
    String sessionCookie = Cookies.getCookie(RESTILITY.m_sessionCookie);
    if (sessionCookie != null && sessionCookie.length() > 0) {

        // If the cookie value is quoted, strip off the enclosing quotes
        if (sessionCookie.length() > 2 && sessionCookie.charAt(0) == '"'
                && sessionCookie.charAt(sessionCookie.length() - 1) == '"') {
            sessionCookie = sessionCookie.substring(1, sessionCookie.length() - 1);
        }//ww  w .j ava 2s . c om
        String sessionCookiePieces[] = sessionCookie.split(",");

        if (sessionCookiePieces != null) {
            if (sessionCookiePieces.length >= 1) {
                RESTILITY.m_tokenType = sessionCookiePieces[0];
            }
            if (sessionCookiePieces.length >= 2) {
                RESTILITY.m_userToken = sessionCookiePieces[1];
            }
            if (sessionCookiePieces.length >= 3) {
                RESTILITY.m_tokenServerUrl = sessionCookiePieces[2];
            }
            if (sessionCookiePieces.length >= 4) {
                RESTILITY.m_tokenServerLogoutUrl = sessionCookiePieces[3];
            }
            if (sessionCookiePieces.length >= 5) {
                RESTILITY.m_username = sessionCookiePieces[4];
            }
        }
    }
}

From source file:org.spiffyui.client.rest.RESTility.java

License:Apache License

/**
 * Returns best matched locale/*from w  w  w  .  j  a  va  2  s  .c o  m*/
 *
 * @return best matched locale
 */
public static String getBestLocale() {
    if (RESTILITY.m_bestLocale != null) {
        return RESTILITY.m_bestLocale;
    } else {
        RESTILITY.m_bestLocale = Cookies.getCookie(LOCALE_COOKIE);
        return RESTILITY.m_bestLocale;
    }
}

From source file:org.spiffyui.hellospiffyoauth.client.Index.java

License:Apache License

private void getContacts() {
    m_contactsButton.setInProgress(true);
    RootPanel.get("Contacts").clear();

    /*//from   w  ww  .  j av a 2s .  co  m
     * Use the url params or the cookie for the verifier and token,
     * if none found then throw an exception
     */
    String oauthVerifier = Window.Location.getParameter(OAUTH_VERIFIER);
    String oauthToken = Window.Location.getParameter(OAUTH_TOKEN);

    if (isEmpty(oauthVerifier)) {
        oauthVerifier = Cookies.getCookie(OAUTH_VERIFIER);
    }
    if (isEmpty(oauthToken)) {
        oauthToken = Cookies.getCookie(OAUTH_TOKEN);
    }

    if (isEmpty(oauthVerifier) && isEmpty(oauthToken)) {
        throw new RuntimeException("No verifier or token were found.");
    }

    Contacts.loadContacts(oauthVerifier, oauthToken, new RESTObjectCallBack<Contacts>() {

        @Override
        public void success(Contacts o) {
            showContacts(o);
            m_contactsButton.setInProgress(false);
        }

        @Override
        public void error(RESTException e) {
            MessageUtil.showError(e.getReason());
            m_contactsButton.setInProgress(false);
        }

        @Override
        public void error(String message) {
            MessageUtil.showError(message);
            m_contactsButton.setInProgress(false);
        }
    });
}