Search in sources :

Example 1 with Cookie

use of com.laytonsmith.PureUtilities.Web.Cookie in project CommandHelper by EngineHub.

the class Web method getCookieJar.

private static void getCookieJar(CArray arrayJar, CookieJar cookieJar, Target t) {
    CArray ret = arrayJar;
    for (Cookie cookie : cookieJar.getAllCookies()) {
        boolean update = false;
        CArray aCookie = null;
        for (Construct ac : arrayJar.asList()) {
            aCookie = Static.getArray(ac, t);
            if (cookie.getName().equals(aCookie.get("name", t).val()) && cookie.getDomain().equals(aCookie.get("domain", t).val()) && cookie.getPath().equals(aCookie.get("path", t).val())) {
                // This is just an update, not a new cookie
                update = true;
                break;
            }
        }
        CArray c;
        if (!update) {
            c = CArray.GetAssociativeArray(t);
        } else {
            c = aCookie;
        }
        c.set("name", cookie.getName());
        c.set("value", cookie.getValue());
        c.set("domain", cookie.getDomain());
        c.set("path", cookie.getPath());
        c.set("expiration", new CInt(cookie.getExpiration(), t), t);
        c.set("httpOnly", CBoolean.get(cookie.isHttpOnly()), t);
        c.set("secureOnly", CBoolean.get(cookie.isSecureOnly()), t);
        if (!update) {
            ret.push(c, t);
        }
    }
}
Also used : Cookie(com.laytonsmith.PureUtilities.Web.Cookie) CInt(com.laytonsmith.core.constructs.CInt) CArray(com.laytonsmith.core.constructs.CArray) Construct(com.laytonsmith.core.constructs.Construct)

Example 2 with Cookie

use of com.laytonsmith.PureUtilities.Web.Cookie in project CommandHelper by EngineHub.

the class Web method getCookieJar.

private static CookieJar getCookieJar(CArray cookieJar, Target t) {
    CookieJar ret = new CookieJar();
    for (String key : cookieJar.stringKeySet()) {
        CArray cookie = Static.getArray(cookieJar.get(key, t), t);
        String name;
        String value;
        String domain;
        String path;
        long expiration = 0;
        boolean httpOnly = false;
        boolean secureOnly = false;
        if (cookie.containsKey("name") && cookie.containsKey("value") && cookie.containsKey("domain") && cookie.containsKey("path")) {
            name = cookie.get("name", t).val();
            value = cookie.get("value", t).val();
            domain = cookie.get("domain", t).val();
            path = cookie.get("path", t).val();
        } else {
            throw new CREFormatException("The name, value, domain, and path keys are required" + " in all cookies.", t);
        }
        if (cookie.containsKey("expiration")) {
            expiration = Static.getInt(cookie.get("expiration", t), t);
        }
        if (cookie.containsKey("httpOnly")) {
            httpOnly = Static.getBoolean(cookie.get("httpOnly", t), t);
        }
        if (cookie.containsKey("secureOnly")) {
            secureOnly = Static.getBoolean(cookie.get("secureOnly", t), t);
        }
        Cookie c = new Cookie(name, value, domain, path, expiration, httpOnly, secureOnly);
        ret.addCookie(c);
    }
    return ret;
}
Also used : Cookie(com.laytonsmith.PureUtilities.Web.Cookie) CArray(com.laytonsmith.core.constructs.CArray) CookieJar(com.laytonsmith.PureUtilities.Web.CookieJar) CString(com.laytonsmith.core.constructs.CString) CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException)

Aggregations

Cookie (com.laytonsmith.PureUtilities.Web.Cookie)2 CArray (com.laytonsmith.core.constructs.CArray)2 CookieJar (com.laytonsmith.PureUtilities.Web.CookieJar)1 CInt (com.laytonsmith.core.constructs.CInt)1 CString (com.laytonsmith.core.constructs.CString)1 Construct (com.laytonsmith.core.constructs.Construct)1 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)1