Example usage for org.apache.http.impl.cookie BasicClientCookie getExpiryDate

List of usage examples for org.apache.http.impl.cookie BasicClientCookie getExpiryDate

Introduction

In this page you can find the example usage for org.apache.http.impl.cookie BasicClientCookie getExpiryDate.

Prototype

public Date getExpiryDate() 

Source Link

Document

Returns the expiration Date of the cookie, or null if none exists.

Usage

From source file:org.pluroid.pluroium.PlurkHelper.java

public boolean isLoginned() {
    boolean loginned = false;
    if (cookieStore != null) {
        List<Cookie> cookies = cookieStore.getCookies();
        if (cookies.size() > 0) {
            BasicClientCookie c = (BasicClientCookie) cookies.get(0);

            Date expiryDate = c.getExpiryDate();
            Date now = Calendar.getInstance().getTime();
            if (expiryDate.after(now)) {
                loginned = true;/*from ww w.  j  av  a2 s.  c  o  m*/
            }
        }
    }

    return loginned;
}

From source file:ti.modules.titanium.network.NetworkModule.java

/**
 * Adds a cookie to the system cookie store. Any existing cookie with the same domain, path and name will be replaced with
 * the new cookie. The cookie being set must not have expired, otherwise it will be ignored.
 * @param cookieProxy the cookie to add// ww w.  java 2  s. co  m
 */
@Kroll.method
public void addSystemCookie(CookieProxy cookieProxy) {
    BasicClientCookie cookie = cookieProxy.getHTTPCookie();
    String cookieString = cookie.getName() + "=" + cookie.getValue();
    String domain = cookie.getDomain();
    if (domain == null) {
        Log.w(TAG, "Unable to add system cookie. Need to provide domain.");
        return;
    }
    cookieString += "; domain=" + domain;

    String path = cookie.getPath();
    Date expiryDate = cookie.getExpiryDate();
    boolean secure = cookie.isSecure();
    boolean httponly = TiConvert.toBoolean(cookieProxy.getProperty(TiC.PROPERTY_HTTP_ONLY), false);
    if (path != null) {
        cookieString += "; path=" + path;
    }
    if (expiryDate != null) {
        cookieString += "; expires=" + CookieProxy.systemExpiryDateFormatter.format(expiryDate);
    }
    if (secure) {
        cookieString += "; secure";
    }
    if (httponly) {
        cookieString += " httponly";
    }
    CookieSyncManager.createInstance(TiApplication.getInstance().getRootOrCurrentActivity());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setCookie(domain, cookieString);
    CookieSyncManager.getInstance().sync();
}