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.opennms.features.node.list.gwt.client.ErrorDialogBox.java
License:Open Source License
private Widget createWidget() { m_errorLabel.setText("hello"); Button ok = new Button("OK"); ok.addClickHandler(new ClickHandler() { @Override// w w w.j av a 2 s.com public void onClick(ClickEvent event) { ErrorDialogBox.this.hide(); } }); final CheckBox check = new CheckBox(); check.setText("Don't show again for 24hours"); check.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (check.getValue()) { Cookies.setCookie(PageableNodeList.COOKIE, "true", new Date(new Date().getTime() + 86400000)); } } }); m_layoutPanel = new DockLayoutPanel(Unit.EM); m_layoutPanel.setWidth("100%"); m_layoutPanel.setHeight("125px"); m_caption.getElement().getStyle().setBackgroundColor("#ebebeb"); m_caption.setText("Error"); m_layoutPanel.addNorth(m_caption, 2); m_layoutPanel.addSouth(ok, 2); m_layoutPanel.addSouth(check, 2); m_layoutPanel.add(m_errorLabel); return m_layoutPanel; }
From source file:org.openremote.web.console.service.LocalDataServiceImpl.java
License:Open Source License
private void setData(String dataName, String data) { String oldData = getObjectString(dataName); if (oldData == null || !data.equals(oldData)) { String dataNamePath = buildPathString(dataName); try {/*w ww . ja va2 s. c o m*/ if (dataStore != null) { dataStore.removeItem(dataNamePath); dataStore.setItem(dataNamePath, data); } else { Cookies.setCookie(dataNamePath, data, new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 365 * 100))); } } catch (Exception e) { } HandlerManager eventBus = ConsoleUnitEventManager.getInstance().getEventBus(); BindingDataChangeEvent event = new BindingDataChangeEvent(dataName); eventBus.fireEvent(event); } }
From source file:org.pentaho.mantle.login.client.MantleLoginDialog.java
License:Open Source License
public MantleLoginDialog() { super(Messages.getString("login"), Messages.getString("login"), Messages.getString("cancel"), false, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ IDialogCallback myCallback = new IDialogCallback() { public void cancelPressed() { }/*w ww . j av a 2 s . co m*/ @SuppressWarnings("deprecation") public void okPressed() { String path = Window.Location.getPath(); if (!path.endsWith("/")) { //$NON-NLS-1$ path = path.substring(0, path.lastIndexOf("/") + 1); //$NON-NLS-1$ } RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, path + "j_spring_security_check"); //$NON-NLS-1$ builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); //$NON-NLS-1$ //$NON-NLS-2$ builder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); RequestCallback callback = new RequestCallback() { public void onError(Request request, Throwable exception) { outerCallback.onFailure(exception); } public void onResponseReceived(Request request, Response response) { try { final String url = ScheduleHelper.getFullyQualifiedURL() + "api/mantle/isAuthenticated"; //$NON-NLS-1$ RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, url); requestBuilder.setHeader("accept", "text/plain"); requestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT"); requestBuilder.sendRequest(null, new RequestCallback() { public void onError(Request request, final Throwable caught) { MessageDialogBox errBox = new MessageDialogBox(Messages.getString("loginError"), //$NON-NLS-1$ Messages.getString("authFailed"), false, false, true); //$NON-NLS-1$ errBox.setCallback(new IDialogCallback() { public void cancelPressed() { } public void okPressed() { outerCallback.onFailure(caught); } }); errBox.show(); } public void onResponseReceived(Request request, Response response) { if ("true".equalsIgnoreCase(response.getText())) { long year = 1000 * 60 * 60 * 24 * 365; // one year into the future Date expirationDate = new Date(System.currentTimeMillis() + year); Cookies.setCookie("loginNewWindowChecked", "" + newWindowChk.getValue(), //$NON-NLS-1$//$NON-NLS-2$ expirationDate); outerCallback.onSuccess(newWindowChk != null && newWindowChk.getValue()); } else { outerCallback.onFailure(new Throwable(Messages.getString("authFailed"))); //$NON-NLS-1$ } } }); } catch (final RequestException e) { MessageDialogBox errBox = new MessageDialogBox(Messages.getString("loginError"), //$NON-NLS-1$ Messages.getString("authFailed"), false, false, true); //$NON-NLS-1$ errBox.setCallback(new IDialogCallback() { public void cancelPressed() { } public void okPressed() { outerCallback.onFailure(e); } }); errBox.show(); } } }; try { String username = userTextBox.getText(); String password = passwordTextBox.getText(); builder.sendRequest("j_username=" + URL.encodeComponent(username) + "&j_password=" + URL.encodeComponent(password), callback); //$NON-NLS-1$ //$NON-NLS-2$ } catch (RequestException e) { e.printStackTrace(); } } }; setCallback(myCallback); super.setStylePrimaryName("pentaho-dialog"); }
From source file:org.rebioma.client.ApplicationView.java
License:Apache License
public static void refreshSession() { if (sessionId != null) { Cookies.setCookie(SESSION_ID_NAME, getSessionId(), new Date(System.currentTimeMillis() + 86400000)); }/*from w w w. j a v a2s.c o m*/ }
From source file:org.rebioma.client.Portal.java
License:Apache License
/** * Checks the current session via RPC. Updates application state. Updates all * tab widgets with new application state. *//*from ww w . jav a 2 s. c o m*/ private void checkCurrentSession() { final String dev = Window.Location.getParameter("gwt.codesvr") == null ? "" : "Portal.html?gwt.codesvr=" + Window.Location.getParameter("gwt.codesvr"); String from = Window.Location.getParameter("from"); String sign = Window.Location.getParameter("signinc"); if (from != null) { String family = Window.Location.getParameter("family"); family = (family == null || family.isEmpty()) ? "" : "&asearch=AcceptedFamily like " + family.trim(); String genus = Window.Location.getParameter("genus"); String m_search = genus == null ? "" : genus; genus = (genus == null || genus.isEmpty()) ? "" : "&asearch=AcceptedGenus like " + genus.trim(); String species = Window.Location.getParameter("species"); m_search = (species == null || species.trim().isEmpty()) ? m_search : species; species = (species == null || species.isEmpty()) ? "" : "&asearch=AcceptedSpecies like " + species.trim(); String year = Window.Location.getParameter("year"); year = (year == null || year.isEmpty()) ? "" : "&asearch=YearCollected = " + year.trim(); Window.Location.replace(GWT.getHostPageBaseURL() + dev + "#tab=occ&view=Map&zoom=5¢er=-19,47&map_type=terrain&left_tab=1&m_search=" + m_search + "&asearch=AcceptedOrder = PRIMATES&m_page=1&page=1" + family + genus + species + "&error_type=all&type=all occurrences"); } else if (sign != null) { String email = Window.Location.getParameter("emailc"); final String id = Window.Location.getParameter("id"); Cookies.removeCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().signInC(email, sign, new AsyncCallback<User>() { @Override public void onFailure(Throwable caught) { // TODO Auto-generated method stub } @Override public void onSuccess(User result) { // TODO Auto-generated method stub if (result.getSessionId() == null) initApplication(null); else { Cookies.setCookie(ApplicationView.SESSION_ID_NAME, result.getSessionId(), new Date(System.currentTimeMillis() + 86400000)); Window.Location.replace(GWT.getHostPageBaseURL() + dev + "#tab=occ&view=Detail&id=" + id + "&p=false&page=1&asearch=Id = " + id + "&type=all occurrences"); } } }); } else if (!isSessionIdInBrowser()) { // links.showLinks(HOME_UNAUTHENTICATED_LINKS); initApplication(null); return; } else { String sid = Cookies.getCookie(ApplicationView.SESSION_ID_NAME); DataSwitch.get().isSessionIdValid(sid, new AsyncCallback<User>() { public void onFailure(Throwable caught) { GWT.log(caught.getMessage(), caught); initApplication(null); } public void onSuccess(User result) { if (result != null) { ApplicationView.setSessionId(result.getSessionId()); ApplicationView.refreshSession(); } initApplication(result); } }); } }
From source file:org.sigmah.client.HistoryManager.java
License:Open Source License
private void onNavigationCompleted(PageState place) { String token = placeSerializer.serialize(place); /*/*from w ww.j a v a 2 s . c o m*/ * If it's a duplicate, we're not totally interested */ if (!token.equals(History.getToken())) { /* * Lodge in the browser's history */ History.newItem(token, false); /* * ... And save as a cookie so we know where to pick up next time */ Cookies.setCookie("lastPlace", token, (new DateWrapper()).addDays(30).asDate()); } }
From source file:org.sigmah.client.offline.AuthTokenUtil.java
License:Open Source License
public static void ensurePersistentCookie(Authentication auth) { // unless the user requests to stay logged in, the authToken is // set to expire at the end of the user's session, which // means that it won't be available if the user opens the app via // the appcache later on. // Since BootstrapScriptServlet relies on the token to select the // appropriate locale, without the cookie set, trying to retrieve // the latest manifest will fail Cookies.setCookie(org.sigmah.shared.Cookies.AUTH_TOKEN_COOKIE, auth.getAuthToken(), oneYearLater()); }
From source file:org.sigmah.client.offline.install.CacheUserDetails.java
License:Open Source License
@Override public void execute(AsyncCallback<Void> callback) { Date now = new Date(); Date expires = new Date(now.getTime() + ONE_YEAR); Cookies.setCookie("authToken", authentication.getAuthToken(), expires); Cookies.setCookie("userId", Integer.toString(authentication.getUserId()), expires); Cookies.setCookie("email", authentication.getEmail(), expires); callback.onSuccess(null);//from w w w .j a v a 2 s. c o m }
From source file:org.sigmah.client.offline.OfflineStatus.java
License:Open Source License
public void setOfflineEnabled(boolean enabled) { Date expires = new Date(); expires.setTime(expires.getTime() + 31536000l); Cookies.setCookie(offlineCookieName, enabled ? "enabled" : "installed", expires); }
From source file:org.sonatype.nexus.ext.gwt.ui.client.ApplicationContext.java
License:Open Source License
public void setCookie(String name, String value) { Date expires = new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 365)); Cookies.setCookie("st-" + name, value, expires); }