Example usage for org.apache.http.cookie ClientCookie EXPIRES_ATTR

List of usage examples for org.apache.http.cookie ClientCookie EXPIRES_ATTR

Introduction

In this page you can find the example usage for org.apache.http.cookie ClientCookie EXPIRES_ATTR.

Prototype

String EXPIRES_ATTR

To view the source code for org.apache.http.cookie ClientCookie EXPIRES_ATTR.

Click Source Link

Usage

From source file:com.github.tmyroadctfig.icloud4j.json.SerializableClientCookie.java

public SerializableClientCookie(Cookie cookie) {
    this.name = cookie.getName();
    this.value = cookie.getValue();
    this.cookieComment = cookie.getComment();
    this.cookieDomain = cookie.getDomain();
    this.cookieExpiryDate = cookie.getExpiryDate() != null ? cookie.getExpiryDate().getTime() : null;
    this.cookiePath = cookie.getPath();
    this.isSecure = cookie.isSecure();
    this.cookieVersion = cookie.getVersion();

    if (cookie instanceof ClientCookie) {
        ClientCookie c = (ClientCookie) cookie;
        copyAttribute(ClientCookie.COMMENT_ATTR, c);
        copyAttribute(ClientCookie.COMMENTURL_ATTR, c);
        copyAttribute(ClientCookie.DISCARD_ATTR, c);
        copyAttribute(ClientCookie.DOMAIN_ATTR, c);
        copyAttribute(ClientCookie.EXPIRES_ATTR, c);
        copyAttribute(ClientCookie.MAX_AGE_ATTR, c);
        copyAttribute(ClientCookie.PATH_ATTR, c);
        copyAttribute(ClientCookie.PORT_ATTR, c);
        copyAttribute(ClientCookie.SECURE_ATTR, c);
        copyAttribute(ClientCookie.DOMAIN_ATTR, c);
    }/*w  w w. j  a va  2  s . c  o m*/
}

From source file:org.esxx.js.protocol.CookieJar.java

/** Purges cookies from the cookie jar.
 *
 *  @param cx     A Context//from   w w  w.  ja v  a  2s .  c  o  m
 *  @param jar    The Scriptable cookie jar
 *  @param date   If not null, expired cookies (given this Date) will be purged
 *  @param name   If not null, all cookies matching name and domain will be purged
 *  @param domain The cookie domain. Domain names are case insensitive and null equals ""
 *
 *  @returns true if one or more cookies were purged
 */

private boolean purge(Context cx, Scriptable jar, Date date, String name, String domain) {
    boolean purged = false;

    if (domain == null) {
        domain = "";
    }

    if (jar != null) {
        Object len = jar.get("length", jar);

        if (len != Scriptable.NOT_FOUND) {
            int length = (int) Context.toNumber(len);
            int j = 0;

            for (int i = 0; i < length; ++i) {
                Object o = jar.get(i, jar);

                if (o instanceof Scriptable) {
                    Scriptable cookie = (Scriptable) o;
                    Object edate = cookie.get(ClientCookie.EXPIRES_ATTR, cookie);
                    Object cname = cookie.get("name", cookie);
                    Object cdomain = cookie.get("domain", cookie);

                    if (cdomain == Scriptable.NOT_FOUND) {
                        cdomain = "";
                    } else {
                        cdomain = Context.toString(cdomain);
                    }

                    if (date != null && edate != Scriptable.NOT_FOUND
                            && Context.toNumber(edate) <= date.getTime()) {
                        // Cookie has expired
                        purged = true;
                    } else if (name != null && cname != Scriptable.NOT_FOUND
                            && Context.toString(cname).equals(name)
                            && domain.equalsIgnoreCase((String) cdomain)) {
                        // Cookie matches the name/domain parameters
                        purged = true;
                    } else {
                        if (i != j) {
                            jar.put(j, jar, o);
                        }

                        ++j;
                    }
                }
            }

            jar.put("length", jar, j);
        }
    }

    return purged;
}

From source file:org.esxx.js.protocol.CookieJar.java

private Scriptable cookieToScriptable(Context cx, Cookie cookie) {
    Scriptable js = cx.newObject(jsuri);
    Scriptable raw = cx.newObject(js);//from  w w  w.  jav  a  2 s .  com

    js.put("raw", js, raw);

    setValue(cx, cookie, js, raw, "name", cookie.getName());
    setValue(cx, cookie, js, raw, "value", cookie.getValue());

    setValue(cx, cookie, js, raw, ClientCookie.COMMENT_ATTR, cookie.getComment());
    setValue(cx, cookie, js, raw, ClientCookie.COMMENTURL_ATTR, cookie.getCommentURL());
    setValue(cx, cookie, js, raw, ClientCookie.DISCARD_ATTR, null);
    setValue(cx, cookie, js, raw, ClientCookie.DOMAIN_ATTR, cookie.getDomain());
    setValue(cx, cookie, js, raw, ClientCookie.EXPIRES_ATTR, cookie.getExpiryDate());
    setValue(cx, cookie, js, raw, ClientCookie.MAX_AGE_ATTR, null);
    setValue(cx, cookie, js, raw, ClientCookie.PATH_ATTR, cookie.getPath());
    setValue(cx, cookie, js, raw, ClientCookie.PORT_ATTR, cookie.getPorts());
    setValue(cx, cookie, js, raw, ClientCookie.SECURE_ATTR, cookie.isSecure());
    setValue(cx, cookie, js, raw, ClientCookie.VERSION_ATTR, cookie.getVersion());

    return js;
}

From source file:org.esxx.js.protocol.CookieJar.java

private Cookie scriptableToCookie(Context cx, Scriptable js) {
    String name = Context.toString(js.get("name", js));
    String value = Context.toString(js.get("value", js));
    Object raw = js.get("raw", js);

    BasicClientCookie cookie;/*from ww w. j a v a  2 s.  c  o m*/

    if (js.has(ClientCookie.COMMENTURL_ATTR, js) || js.has(ClientCookie.DISCARD_ATTR, js)
            || js.has(ClientCookie.PORT_ATTR, js)) {
        BasicClientCookie2 cookie2 = new BasicClientCookie2(name, value);

        cookie2.setCommentURL(stringValue(cx, js, raw, cookie2, ClientCookie.COMMENTURL_ATTR));
        cookie2.setDiscard(booleanValue(cx, js, raw, cookie2, ClientCookie.DISCARD_ATTR));
        cookie2.setPorts(intArrayValue(cx, js, raw, cookie2, ClientCookie.PORT_ATTR));
        cookie = cookie2;
    } else {
        cookie = new BasicClientCookie(name, value);
    }

    cookie.setComment(stringValue(cx, js, raw, cookie, ClientCookie.COMMENT_ATTR));
    cookie.setDomain(stringValue(cx, js, raw, cookie, ClientCookie.DOMAIN_ATTR));
    cookie.setExpiryDate(dateValue(cx, js, raw, cookie, ClientCookie.EXPIRES_ATTR));
    cookie.setPath(stringValue(cx, js, raw, cookie, ClientCookie.PATH_ATTR));
    cookie.setSecure(booleanValue(cx, js, raw, cookie, ClientCookie.SECURE_ATTR));
    cookie.setVersion(intValue(cx, js, raw, cookie, ClientCookie.VERSION_ATTR));

    setRawValue(raw, cookie, ClientCookie.MAX_AGE_ATTR);

    return cookie;
}