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:com.google.gwt.sample.healthyeatingapp.client.HealthyEatingApp.java

@Override
public void onModuleLoad() {
    String sessionID = Cookies.getCookie("sid");
    if (Window.Location.getHref().contains("http://127.0.0.1:8888")) {
        Window.Location.replace("http://localhost:8888/HealthyEatingApp.html?gwt.codesvr=127.0.0.1:9997");
    }// w  w w  . ja v a 2  s. c  o  m
    if (sessionID == null) {
        loginControl.loadLogin();

    }

    else {
        loginControl.loadHomepage();
    }

}

From source file:com.google.gwt.sample.healthyeatingapp.client.Homepage.java

public Homepage() {
    initWidget(tp);/*from   ww  w  . j  a  v a 2 s  . c  o  m*/
    // Add a home tab
    tp.add(new FoodLog(tp).onModuleLoad(), "Food Log");
    tp.add(new SocialMedia().SocialMediaWebPageLoad(), "Social Media");
    this.rpc = (DBConnectionServiceAsync) GWT.create(DBConnectionService.class);
    ServiceDefTarget target = (ServiceDefTarget) rpc;
    String moduleRelativeURL = GWT.getModuleBaseURL() + "DBConnectionServiceImpl";
    target.setServiceEntryPoint(moduleRelativeURL);

    Runnable onLoadCallBack = new Runnable() {
        @Override
        public void run() {
            String username = Cookies.getCookie("healthy_app_user");
            rpc.getUserCalories(username, new AsyncCallback<String>() {

                @Override
                public void onFailure(Throwable caught) {
                    // Show the RPC error message to the user
                    Window.alert("No log records for user:" + Cookies.getCookie("healthy_app_user"));
                }

                @Override
                public void onSuccess(String result) {
                    // TODO Auto-generated method stub
                    DataTable data = toDataTable(result);
                    tp.add(new Graph().returnGraph(data), "Graph");
                }
            });
        }
    };

    VisualizationUtils.loadVisualizationApi(onLoadCallBack, CoreChart.PACKAGE);
}

From source file:com.google.gwt.sample.showcase.client.content.other.CwCookies.java

License:Apache License

/**
 * Retrieve the value of the existing cookie and put it into to value label.
 *///from  ww  w. j a v a 2 s.c  o m
@ShowcaseSource
private void updateExstingCookie() {
    // Cannot update if there are no items
    if (existingCookiesBox.getItemCount() < 1) {
        cookieNameBox.setText("");
        cookieValueBox.setText("");
        return;
    }

    int selectedIndex = existingCookiesBox.getSelectedIndex();
    String cookieName = existingCookiesBox.getValue(selectedIndex);
    String cookieValue = Cookies.getCookie(cookieName);
    cookieNameBox.setText(cookieName);
    cookieValueBox.setText(cookieValue);
}

From source file:com.google.livingstories.client.lsp.LivingStory.java

License:Apache License

@Override
public void onModuleLoad() {
    // Inject the contents of the CSS file
    Resources.INSTANCE.css().ensureInjected();

    AjaxLoader.init();/*  ww  w  .j  a v  a2  s  .co  m*/

    String cookieName = Constants.getCookieName(LivingStoryData.getLivingStoryUrl());
    String cookieValue = Cookies.getCookie(cookieName);

    if (cookieValue != null) {
        try {
            LivingStoryData.setCookieBasedLastVisitDate(new Date(Long.valueOf(cookieValue)));
        } catch (NumberFormatException e) {
        }
    }

    // note the visit.
    Date now = new Date();
    Date cookieExpiry = new Date(now.getTime() + SIXTY_DAYS_IN_MILLISECONDS);
    Cookies.setCookie(cookieName, String.valueOf(now.getTime()), cookieExpiry);

    RootPanel.get("storyBody").add(new LivingStoryPage());

    HistoryManager.initialize();

    // Also set appropriate i18n text for a couple of constants:
    Document doc = Document.get();
    doc.getElementById("rssLink").setAttribute("title",
            LspMessageHolder.msgs.rssFeedTitle(LivingStoryData.getLivingStoryTitle()));
    doc.getElementById("readOtherStories").setInnerText(LspMessageHolder.consts.otherStories());
}

From source file:com.googlecode.gwtphonegap.client.device.DeviceBrowserImpl.java

License:Apache License

@Override
public String getUuid() {
    String value = Cookies.getCookie("gwt-phonegap-uuid");
    if (value == null) {
        long end = System.currentTimeMillis() + 60l * 60l * 24l * 356l * 1000l;
        value = getPseudoGUUID();/*from   www  . j av a 2 s .co  m*/
        Cookies.setCookie("gwt-phonegap-uuid", value, new Date(end));

    }
    return value;
}

From source file:com.googlecode.mgwt.examples.showcase.client.activities.button.BCFunctionButtonViewGwtImpl.java

License:Apache License

public BCFunctionButtonViewGwtImpl(final ClientFactory clientFactory) {
    this.clientFactory = clientFactory;
    ctx = (ClientContext) RPCClientContext.get();
    String sessionID = Cookies.getCookie("sid");
    Log.info("sessionID: " + sessionID + " ctx: " + ctx);
    if (sessionID != null) {
        if (ctx != null) {
            //Set the current user context
            currentUser = ctx.getCurrentUser();

            headerBackButton.removeFromParent();
            FlowPanel content = new FlowPanel();
            content.getElement().getStyle().setMargin(20, Unit.PX);

            scrollPanel.setScrollingEnabledX(false);
            scrollPanel.setWidget(content);
            // workaround for android formfields jumping around when using
            // -webkit-transform
            scrollPanel.setUsePos(MGWT.getOsDetection().isAndroid());

            ChromeWorkaround.maybeUpdateScroller(scrollPanel);

            WidgetList widgetList = new WidgetList();
            content.add(widgetList);/*  w  w  w  .  j av a  2  s.  c  om*/

            Button identifyButton = new Button("Identify");
            widgetList.add(identifyButton);

            identifyButton.addTapHandler(new TapHandler() {
                public void onTap(TapEvent event) {

                    clientFactory.getPlaceController().goTo(new IdentifyImgUploadPlace());
                }

            });

            Button historyButton = new Button("History");
            widgetList.add(historyButton);

            historyButton.addTapHandler(new TapHandler() {
                public void onTap(TapEvent event) {

                    clientFactory.getPlaceController().goTo(new JobHistoryPlace());
                }

            });

            Button enrollButton = new Button("Enroll");
            widgetList.add(enrollButton);
            enrollButton.addTapHandler(new TapHandler() {
                @Override
                public void onTap(TapEvent event) {
                    clientFactory.getPlaceController().goTo(new EnrollImgUploadPlace());
                }
            });

            Button generateModelButton = new Button("Regenerate templates");
            widgetList.add(generateModelButton);
            generateModelButton.addTapHandler(new TapHandler() {
                @Override
                public void onTap(TapEvent event) {
                    clientFactory.getPlaceController().goTo(new GenerateModelPlace());
                }
            });

            Button changePasswordButton = new Button("Change password");
            widgetList.add(changePasswordButton);

            changePasswordButton.addTapHandler(new TapHandler() {
                public void onTap(TapEvent event) {

                    clientFactory.getPlaceController().goTo(new ChangePasswordPlace());
                }

            });

            Button signOutButton = new Button("Sign out");
            widgetList.add(signOutButton);
            signOutButton.addTapHandler(new TapHandler() {
                @Override
                public void onTap(TapEvent event) {
                    resetContext();
                    UserValidationServiceAsync service = UserValidationService.Util.getInstance();
                    service.clearSession(sessionCallback);
                }
            });
        } else {
            clientFactory.getPlaceController().goTo(new ElementsPlace());
        }
    } else {
        clientFactory.getPlaceController().goTo(new ElementsPlace());
    }
}

From source file:com.griddynamics.jagger.facade.client.JaggerFacade.java

License:Open Source License

/**
 * This is the entry point method.//  w  w  w  .  j  a  va 2s .  c o  m
 */
public void onModuleLoad() {
    userId = Cookies.getCookie("jagger_facade_user_id");
    if (userId == null) {
        JaggerFacadeService.App.getInstance().getUserId(new AsyncCallback<String>() {
            @Override
            public void onFailure(Throwable caught) {
            }

            @Override
            public void onSuccess(String result) {
                userId = result;
                Cookies.setCookie("jagger_facade_user_id", result,
                        new Date(System.currentTimeMillis() + 157680000000L));
                init();
            }
        });
    } else {
        init();
    }
}

From source file:com.gwtmodel.table.Utils.java

License:Apache License

public static String getCookie(String cName) {
    return Cookies.getCookie(jPrefix() + cName);
}

From source file:com.gwtmodel.table.Utils.java

License:Apache License

public static List<IMapEntry> getCookies() {
    List<IMapEntry> cList = new ArrayList<IMapEntry>();
    Collection<String> cookies = Cookies.getCookieNames();
    final String p = jPrefix();
    for (final String s : cookies) {
        if (!s.startsWith(p))
            continue;
        final String value = Cookies.getCookie(s);
        IMapEntry i = new IMapEntry() {

            @Override//from  w ww.ja  v a  2  s.  co m
            public String getKey() {
                return s.substring(p.length());
            }

            @Override
            public String getValue() {
                return value;
            }

        };
        cList.add(i);
    }
    return cList;
}

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

License:Apache License

private String getLoggedInCookie() {
    return Cookies.getCookie(LOGIN_COOKIE_NAME);
}