All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.gwt.test.internal.patchers.CookiesPatcher Maven / Gradle / Ivy

There is a newer version: 0.63
Show newest version
package com.googlecode.gwt.test.internal.patchers;

import com.google.gwt.user.client.Cookies;
import com.googlecode.gwt.test.patchers.PatchClass;
import com.googlecode.gwt.test.patchers.PatchMethod;
import com.googlecode.gwt.test.utils.GwtReflectionUtils;

import java.util.HashMap;
import java.util.Map;

@PatchClass(Cookies.class)
class CookiesPatcher {

    @PatchMethod
    static void loadCookies(HashMap m) {
    }

    @PatchMethod
    static boolean needsRefresh() {
        return false;
    }

    @PatchMethod
    static void removeCookieNative(String name) {
        Map cachedCookies = getCookiesMap();

        if (cachedCookies != null) {
            cachedCookies.remove(name);
        }
    }

    @PatchMethod
    static void setCookieImpl(String name, String value, double expires, String domain, String path,
                              boolean secure) {

        Map cachedCookies = getCookiesMap();
        if (cachedCookies == null) {
            cachedCookies = new HashMap();
            GwtReflectionUtils.setStaticField(Cookies.class, "cachedCookies", cachedCookies);
        }

        cachedCookies.put(name, value);
    }

    @PatchMethod
    static String uriEncode(String s) {
        return s;
    }

    private static Map getCookiesMap() {
        Map cachedCookies = GwtReflectionUtils.getStaticFieldValue(Cookies.class,
                "cachedCookies");
        return cachedCookies;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy