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

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

Introduction

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

Prototype

public static void removeCookie(String name) 

Source Link

Document

Removes the cookie associated with the given name.

Usage

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

License:Apache License

/**
 * Initialize this example./*  ww w . ja  v a  2  s  . c  o m*/
 */
@Override
public Widget onInitialize() {
    // Create the panel used to layout the content
    Grid mainLayout = new Grid(3, 3);

    // Display the existing cookies
    existingCookiesBox = new ListBox();
    Button deleteCookieButton = new Button(constants.cwCookiesDeleteCookie());
    deleteCookieButton.addStyleName("sc-FixedWidthButton");
    mainLayout.setHTML(0, 0, "<b>" + constants.cwCookiesExistingLabel() + "</b>");
    mainLayout.setWidget(0, 1, existingCookiesBox);
    mainLayout.setWidget(0, 2, deleteCookieButton);

    // Display the name of the cookie
    cookieNameBox = new TextBox();
    mainLayout.setHTML(1, 0, "<b>" + constants.cwCookiesNameLabel() + "</b>");
    mainLayout.setWidget(1, 1, cookieNameBox);

    // Display the name of the cookie
    cookieValueBox = new TextBox();
    Button setCookieButton = new Button(constants.cwCookiesSetCookie());
    setCookieButton.addStyleName("sc-FixedWidthButton");
    mainLayout.setHTML(2, 0, "<b>" + constants.cwCookiesValueLabel() + "</b>");
    mainLayout.setWidget(2, 1, cookieValueBox);
    mainLayout.setWidget(2, 2, setCookieButton);

    // Add a handler to set the cookie value
    setCookieButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            String name = cookieNameBox.getText();
            String value = cookieValueBox.getText();
            Date expires = new Date((new Date()).getTime() + COOKIE_TIMEOUT);

            // Verify the name is valid
            if (name.length() < 1) {
                Window.alert(constants.cwCookiesInvalidCookie());
                return;
            }

            // Set the cookie value
            Cookies.setCookie(name, value, expires);
            refreshExistingCookies(name);
        }
    });

    // Add a handler to select an existing cookie
    existingCookiesBox.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            updateExstingCookie();
        }
    });

    // Add a handler to delete an existing cookie
    deleteCookieButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            int selectedIndex = existingCookiesBox.getSelectedIndex();
            if (selectedIndex > -1 && selectedIndex < existingCookiesBox.getItemCount()) {
                String cookieName = existingCookiesBox.getValue(selectedIndex);
                Cookies.removeCookie(cookieName);
                existingCookiesBox.removeItem(selectedIndex);
                updateExstingCookie();
            }
        }
    });

    // Return the main layout
    refreshExistingCookies(null);
    return mainLayout;
}

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

License:Open Source License

public static void updateCookie(String name, String value) {
    Date expires = new Date(System.currentTimeMillis() + (1000L * 3600L * 24L * (long) GuiConstant.EXP_DAYS));
    Cookies.removeCookie(name);
    Cookies.setCookie(name, value, expires, null, "/", false);
}

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

License:Open Source License

/**
 * Serialize parameters of reports The format in the cookie is
 * reportId=paramName:value;paramName:value;...;paramName:value##reportId=...
 *//*  w  ww.  j ava  2 s  .c om*/
private void updateCookie() {
    StringBuffer cookieValue = new StringBuffer();
    for (int i = 0; i < reportsParameters.size(); i++) {
        cookieValue.append(i);
        cookieValue.append(REPORT_PARAM_SEPARATOR);
        HashMap<String, String> parameters = reportsParameters.get(i);
        for (String paramName : parameters.keySet()) {
            cookieValue.append(paramName);
            cookieValue.append(VALUE_SEPARATOR);
            cookieValue.append(parameters.get(paramName));
            cookieValue.append(PARAMS_SEPARATOR);
        }
        cookieValue.append(REPORT_SEPARATOR);
    }
    String cookieStr = cookieValue.toString();
    Cookies.removeCookie(COOKIE_NAME);
    if (reportsParameters.size() > 0) {
        //            Calendar cal = Calendar.getInstance();
        //            cal.set(Calendar.YEAR, 9999);
        Date exp = new Date();
        exp.setYear(9999);
        Cookies.setCookie(COOKIE_NAME, cookieStr.substring(0, cookieStr.length() - REPORT_SEPARATOR.length()),
                exp);
    }
    GWT.log("updateCookie - cookieValue:" + cookieStr);
}

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

License:Open Source License

/**
 * Remove the cookie from the user browser
 *///w  ww  . j  a  v  a2  s  . co m
@Override
protected final void resetParameters() {
    Cookies.removeCookie(LOGIN_COOKIE_NAME);

    UserSessionVariables.removeUserVariable(COOKIE_NAME);
    UserSessionVariables.removeUserVariable(LOGIN_COOKIE_NAME);
}

From source file:org.C2C.client.CallManager.java

License:Open Source License

public static void clearCookies() {
    Cookies.removeCookie(COOKIE_UID);
}

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

License:Open Source License

public static void disAuthenticate() {
    oauthInstance = null;
    Cookies.removeCookie(COOKIE_TOKEN_NAME);
    Cookies.removeCookie(COOKIE_OAUTH_TYPE);
}

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 www.j av  a  2 s.  c o  m*/
    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 {// ww w  .  ja  v  a  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", "");
        }
    }
}

From source file:org.clevermore.monitor.client.utils.LocalStorage.java

License:Apache License

public static void removeItem(final String key) {
    if (Storage.isSupported()) {
        Log.debug("Removing key:" + key + ", from local storage");
        Storage.getLocalStorageIfSupported().removeItem(key);
    } else {/*  w  w w  . j a v a2s  .c  o m*/
        // store to cookies
        Log.debug("Removing key:" + key + ", from cookies");
        Cookies.removeCookie(key);
    }
}

From source file:org.ebayopensource.turmeric.policy.adminui.client.AppController.java

License:Open Source License

private void bind() {
    // if login succeeded
    this.eventBus.addHandler(LoginSuccessEvent.TYPE, new LoginSuccessEventHandler() {
        public void onSuccess(AppUser arg) {

            AppController.this.rootContainer.clear();
            History.newItem(HistoryToken.newHistoryToken(MenuController.PRESENTER_ID, null).toString());
        }/*w ww.j  a  v a2 s . c  o m*/
    });

    // if login failed
    this.eventBus.addHandler(LoginFailureEvent.TYPE, new LoginFailureEventHandler() {
        public void onFailure() {
            SplashPresenter concreteSplashPresenter = (SplashPresenter) presenters
                    .get(SplashPresenter.SPLASH_ID);
            concreteSplashPresenter.handleLoginErrorView();
        }
    });

    // logout
    this.eventBus.addHandler(LogoutEvent.TYPE, new LogoutEventHandler() {
        public void onLogout(LogoutEvent event) {

            Cookies.removeCookie(AppKeyUtil.COOKIE_SESSID_KEY);
            AppUser.logout();

            // Clean up
            cleanup();
            initPresenters();

            // Go back to the splash screen
            HistoryToken token = HistoryToken.newHistoryToken();
            PresenterUtil.forceRedirectToPresenter(token, presenters.get(SplashPresenter.SPLASH_ID));

            SplashPresenter concreteSplashPresenter = (SplashPresenter) presenters
                    .get(SplashPresenter.SPLASH_ID);
            concreteSplashPresenter.handleLogoutSuccessView();
        }

    });

    // login event handler
    this.eventBus.addHandler(LoginEvent.TYPE, new LoginEventHandler() {
        public void onLogin(LoginEvent event) {
            // there is no service to authenticate the username/password
            // This info has to be presented on every request, so the only
            // time we find out if login/password is accepted is when we
            // supply
            // it on a request.
            AppUser.newAppUser(event.getLogin(), event.getPassword(), event.getDomain());
            Cookies.removeCookie(AppKeyUtil.COOKIE_SESSID_KEY);

            Map<String, String> credentials = new HashMap<String, String>();
            credentials.put("X-TURMERIC-SECURITY-PASSWORD", AppUser.getUser().getPassword());
            OperationKey opKey = new OperationKey();

            opKey.setResourceName(PolicyEnforcementService.POLICY_SERVICE_NAME);
            opKey.setOperationName("");
            opKey.setResourceType("OBJECT");

            List<String> policyTypes = Collections.singletonList("AUTHZ");

            String[] subjectType = { "USER", AppUser.getUser().getUsername() };
            List<String[]> subjectTypes = Collections.singletonList(subjectType);

            PolicyEnforcementService enforcementService = (PolicyEnforcementService) serviceMap
                    .get(SupportedService.POLICY_ENFORCEMENT_SERVICE);

            enforcementService.verify(opKey, policyTypes, credentials, subjectTypes, null, null, null,
                    new AsyncCallback<VerifyAccessResponse>() {

                        public void onFailure(Throwable arg) {
                            AppController.this.eventBus.fireEvent(new LoginFailureEvent());
                        }

                        public void onSuccess(VerifyAccessResponse response) {
                            PolicyQueryService policyService = (PolicyQueryService) serviceMap
                                    .get(SupportedService.POLICY_QUERY_SERVICE);
                            SubjectGroupQuery query = new SubjectGroupQuery();
                            SubjectGroupKey key = new SubjectGroupKey();
                            key.setType("USER");
                            key.setName("Admin_Policy_SuperPolicy");
                            query.setGroupKeys(Arrays.asList(key));
                            query.setIncludeSubjects(true);
                            policyService.findSubjectGroups(query,
                                    new AsyncCallback<PolicyQueryService.FindSubjectGroupsResponse>() {

                                        @Override
                                        public void onSuccess(FindSubjectGroupsResponse arg0) {
                                            // arg0.getGroups().
                                            boolean isAdmin = false;
                                            if (arg0.getGroups() != null && !arg0.getGroups().isEmpty()) {
                                                SubjectGroup sgSuperPolicy = arg0.getGroups().get(0);
                                                if (sgSuperPolicy.getSubjects() != null
                                                        && !sgSuperPolicy.getSubjects().isEmpty()) {
                                                    isAdmin = sgSuperPolicy.getSubjects()
                                                            .contains(AppUser.getUser().getUsername());
                                                }
                                            }

                                            AppUser.getUser().setAdminUser(isAdmin);
                                        }

                                        @Override
                                        public void onFailure(Throwable arg0) {
                                            AppUser.getUser().setAdminUser(false);
                                        }
                                    });

                            initSessionTimers();
                            AppController.this.eventBus.fireEvent(new LoginSuccessEvent(AppUser.getUser()));

                        }
                    });

        }
    });
}