List of usage examples for com.google.gwt.user.client Cookies setCookie
public static void setCookie(String name, String value, Date expires)
From source file:org.gwtportlets.portlet.client.ui.Theme.java
License:Open Source License
/** * Store the name of the selected theme in a cookie or something so it * is available via {@link #loadThemeName()} when the application reloads. *//* w w w .jav a 2 s. c o m*/ protected void saveThemeName(String name) { Date exp = new Date(System.currentTimeMillis() + 1000L * 60 * 60 * 24 * 365); // expires in 1 years time Cookies.setCookie(themeCookie, name, exp); }
From source file:org.jboss.as.console.client.core.Preferences.java
License:Open Source License
public static void set(Key key, String value) { Date twoWeeks = new Date(System.currentTimeMillis() + (2 * 604800 * 1000)); Cookies.setCookie(COOKIE_PREFIX + key.getToken(), value, twoWeeks); }
From source file:org.jboss.as.console.client.shared.Preferences.java
License:Open Source License
public static void set(Key key, String value) { Date twoWeeks = new Date(System.currentTimeMillis() + (2 * 604800 * 1000)); Cookies.setCookie(AS7_UI + key.getToken(), value, twoWeeks); }
From source file:org.jboss.errai.workspaces.client.framework.CookiePreferences.java
License:Apache License
public void set(String key, String value) { Date twoWeeks = new Date(System.currentTimeMillis() + (2 * 604800 * 1000)); Cookies.setCookie(key, value, twoWeeks); }
From source file:org.mklab.taskit.client.activity.LoginActivity.java
License:Apache License
/** * ??????/*from ww w .j a v a 2 s.c om*/ * <p> * ???????????????????????????? * * @param view ?????????? */ void tryLoginAsync(final LoginView view) { final String id = view.getId(); final String password = view.getPassword(); this.clientFactory.getRequestFactory().accountRequest().login(id, password).fire(new Receiver<UserProxy>() { @SuppressWarnings("synthetic-access") @Override public void onSuccess(UserProxy loginUser) { view.setStatusText(LoginActivity.this.clientFactory.getMessages().loginSuccessMessage()); final boolean autoLoginEnabled = view.isAutoLoginEnabled(); storeAutoLoginState(autoLoginEnabled); startApplication(loginUser); } private void storeAutoLoginState(final boolean autoLoginEnabled) { final int A_DAY_IN_MILLIS = 24 * 60 * 60 * 1000; final Date expire = new Date(System.currentTimeMillis() + 10 * A_DAY_IN_MILLIS); Cookies.setCookie(COOKIE_AUTO_LOGIN_KEY, String.valueOf(autoLoginEnabled), expire); } /** * {@inheritDoc} */ @Override public void onFailure(ServerFailure error) { view.setStatusText("Login failure. " + error.getMessage()); //$NON-NLS-1$ } }); }
From source file:org.olanto.mySelfQD.client.MyParseCookies.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.setCookie(name, value, expires); }//from ww w. jav a2 s. c o m }
From source file:org.olanto.mySelfQD.client.MyParseCookies.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);// w ww . j av a 2 s.co m Cookies.setCookie(name, value, expires); }
From source file:org.onecmdb.ui.gwt.desktop.client.mvc.contoller.DesktopContoller.java
License:Open Source License
@Override public void handleEvent(AppEvent<?> event) { switch (event.type) { // Main entry point. case CMDBEvents.DESKTOP_CHECK_SESSION: // Save URL arguments urlMap = com.google.gwt.user.client.Window.Location.getParameterMap(); // Check for autologin. List<String> alids = urlMap.get("alid"); if (alids != null && alids.size() > 0) { String alid = alids.get(0); // Need to validate this token. ModelServiceFactory.get().autoLogin(alid, new AsyncCallback<CMDBSession>() { public void onFailure(Throwable arg0) { Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN); return; }/*from w w w . j a v a 2 s. c o m*/ public void onSuccess(CMDBSession arg0) { arg0.setURLValues(urlMap); CMDBSession.get().setSession(arg0); initDesktop(); setupDesktop(arg0.getDesktopConfig()); } }); return; } // Check if we have a cookie set. String token = Cookies.getCookie("auth_token"); if (token != null) { // Need to validate this token. ModelServiceFactory.get().validateToken(token, new AsyncCallback<CMDBSession>() { public void onFailure(Throwable arg0) { Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN); return; } public void onSuccess(CMDBSession arg0) { arg0.setUsername(Cookies.getCookie("auth_username")); arg0.setURLValues(urlMap); CMDBSession.get().setSession(arg0); initDesktop(); setupDesktop(arg0.getDesktopConfig()); } }); return; } // Normal login. Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN); break; case CMDBEvents.DESKTOP_MENU_SELECTED: CMDBDesktopMenuItem item = (CMDBDesktopMenuItem) event.data; CMDBDesktopWindowItem wItem = item.getWindowItem(); Window window = WindowFactory.showWindow(desktop, wItem); break; case CMDBEvents.DESKTOP_LOCK_TIMEOUT: stopActivityTimer(); LoginWidget.login(true, new AsyncCallback<CMDBSession>() { public void onFailure(Throwable arg0) { if (arg0 instanceof CMDBLoginException) { CMDBLoginException ex = (CMDBLoginException) arg0; MessageBox.alert(ex.getHeader(), ex.getMessage(), new Listener<WindowEvent>() { public void handleEvent(WindowEvent be) { Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOCK_TIMEOUT); } }); return; } ExceptionErrorDialog.showError("Login Failed!", arg0, new Listener<WindowEvent>() { public void handleEvent(WindowEvent be) { } }); } public void onSuccess(CMDBSession arg0) { Date date = new Date(); long dateLong = date.getTime(); dateLong += (1000 * 60 * 60 * 8);// 8h convert days to ms date.setTime(dateLong); // Set the new date Cookies.setCookie("auth_token", arg0.getToken(), date); Cookies.setCookie("auth_username", arg0.getUsername(), date); arg0.setURLValues(urlMap); CMDBSession.get().setSession(arg0); startActivityTimeout(CMDBSession.get().getConfig().getDesktopLockTimeout()); } }); break; case CMDBEvents.DESKTOP_LOGIN: LoginWidget.login(false, new AsyncCallback<CMDBSession>() { public void onFailure(Throwable arg0) { if (arg0 instanceof CMDBLoginException) { CMDBLoginException ex = (CMDBLoginException) arg0; MessageBox.alert(ex.getHeader(), ex.getMessage(), new Listener<WindowEvent>() { public void handleEvent(WindowEvent be) { Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN); } }); return; } ExceptionErrorDialog.showError("Login Failed!", arg0, new Listener<WindowEvent>() { public void handleEvent(WindowEvent be) { } }); } public void onSuccess(CMDBSession arg0) { Date date = new Date(); long dateLong = date.getTime(); dateLong += (1000 * 60 * 60 * 8);// 8h convert days to ms date.setTime(dateLong); // Set the new date Cookies.setCookie("auth_token", arg0.getToken(), date); Cookies.setCookie("auth_username", arg0.getUsername(), date); arg0.setURLValues(urlMap); CMDBSession.get().setSession(arg0); initDesktop(); setupDesktop(arg0.getDesktopConfig()); } }); break; case CMDBEvents.DESKTOP_LOGOUT: // close all windows. clearWindow(); // Logout ModelServiceFactory.get().logout(CMDBSession.get().getToken(), new AsyncCallback<Boolean>() { public void onFailure(Throwable caught) { } public void onSuccess(Boolean result) { } }); // Clear session... CMDBSession.setSession(null); // Stop Lock timer stopActivityTimer(); // Clear Cookies. Cookies.removeCookie("auth_token"); Cookies.removeCookie("auth_username"); // Call login. // Reload application.... reloadApplication(); //Dispatcher.get().dispatch(CMDBEvents.DESKTOP_LOGIN); break; case CMDBEvents.DESKTOP_ABOUT: CMDBDesktopWindowItem about = new CMDBDesktopWindowItem(); about.setID(CMDBURLFrameWidget.ID); about.getParams().set("url", GWT.getModuleBaseURL() + "/about.html"); about.getParams().set("newWindow", "true"); about.setHeading("About - OneCMDB"); WindowFactory.showWindow(desktop, about); break; case CMDBEvents.DESKTOP_CHANGE_ROLE: final String role = (String) event.data; //desktop.getStartMenu().hide(); final MessageBox info = MessageBox.wait("Progress", "Change Role to " + role, "Wait..."); ModelServiceFactory.get().getDesktopConfig(CMDBSession.get().getUsername(), CMDBSession.get().getToken(), role, new CMDBAsyncCallback<CMDBDesktopConfig>() { @Override public void onFailure(Throwable t) { info.close(); super.onFailure(t); } @Override public void onSuccess(CMDBDesktopConfig arg0) { info.close(); clearWindow(); CMDBSession.get().setDesktopConfig(arg0); CMDBSession.get().setDefaultRole(role); initDesktop(); setupDesktop(arg0); } }); break; } }
From source file:org.onecmdb.ui.gwt.toolkit.client.control.OneCMDBSession.java
License:Open Source License
/** * Helper function to save Cookie//from w w w . j a va 2 s.c o m * * @param cookieName * name of the cookie * @param value - * value to be saved in the cookie * @param days - * number of days this cookie should be kept alive */ public static void setCookie(String cookieName, String value, int days) { Date date = new Date(); long dateLong = date.getTime(); dateLong += (1000 * 60 * 60 * 24 * days);// convert days to ms date.setTime(dateLong); // Set the new date Cookies.setCookie(cookieName, value, date); }
From source file:org.onecmdb.ui.gwt.toolkit.client.view.screen.BaseScreen.java
License:Apache License
/** * Helper function to save Cookie//from w w w .ja va2 s. c om * * @param cookieName * name of the cookie * @param value - * value to be saved in the cookie * @param days - * number of days this cookie should be kept alive */ public void setCookie(String cookieName, String value, int days) { Date date = new Date(); long dateLong = date.getTime(); dateLong += (1000 * 60 * 60 * 24 * days);// convert days to ms date.setTime(dateLong); // Set the new date Cookies.setCookie(cookieName, value, date); }