Example usage for org.apache.http.impl.cookie BasicClientCookie2 setExpiryDate

List of usage examples for org.apache.http.impl.cookie BasicClientCookie2 setExpiryDate

Introduction

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

Prototype

public void setExpiryDate(final Date expiryDate) 

Source Link

Document

Sets expiration date.

Usage

From source file:org.geometerplus.android.fbreader.network.BearerAuthenticator.java

static boolean onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    final BearerAuthenticator ba = ourAuthenticators.get(activity);
    boolean processed = true;
    try {/*from  w  w w. j a v a2 s  .co  m*/
        switch (requestCode) {
        default:
            processed = false;
            break;
        case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER:
            if (resultCode == Activity.RESULT_OK && data != null) {
                ba.myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            }
            break;
        case NetworkLibraryActivity.REQUEST_AUTHORISATION:
            if (resultCode == Activity.RESULT_OK) {
                ba.myAuthorizationConfirmed = true;
            }
            break;
        case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN:
            if (resultCode == Activity.RESULT_OK && data != null) {
                final CookieStore store = ZLNetworkManager.Instance().cookieStore();
                final Map<String, String> cookies = (Map<String, String>) data
                        .getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY);
                if (cookies != null) {
                    for (Map.Entry<String, String> entry : cookies.entrySet()) {
                        final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue());
                        c.setDomain(data.getData().getHost());
                        c.setPath("/");
                        final Calendar expire = Calendar.getInstance();
                        expire.add(Calendar.YEAR, 1);
                        c.setExpiryDate(expire.getTime());
                        c.setSecure(true);
                        c.setDiscard(false);
                        store.addCookie(c);
                    }
                }
            }
            break;
        }
    } finally {
        if (processed) {
            synchronized (ba) {
                ba.notifyAll();
            }
        }
        return processed;
    }
}

From source file:org.tellervo.desktop.wsi.util.WSCookieWrapper.java

public Cookie toApacheCookie() {
    BasicClientCookie2 cookie = new BasicClientCookie2(name, value);

    cookie.setComment(cookieComment);//from   w  w  w  . j  a  va2s . c  o m
    cookie.setDomain(cookieDomain);
    cookie.setExpiryDate(cookieExpiryDate);
    cookie.setPath(cookiePath);
    cookie.setSecure(isSecure);
    cookie.setVersion(cookieVersion);
    cookie.setPorts(ports);

    // copy over attributes
    /*
    for(Entry<String, String> entry : attribs.entrySet()) {
       cookie.setAttribute(entry.getKey(), entry.getValue());
    }*/

    return cookie;
}

From source file:org.geometerplus.android.fbreader.network.auth.WebAuthorisationScreen.java

private void storeCookies(String host, Map<String, String> cookies) {
    final ZLNetworkManager.CookieStore store = myNetworkContext.cookieStore();

    for (Map.Entry<String, String> entry : cookies.entrySet()) {
        final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue());
        c.setDomain(host);//  ww w. java  2s. c  o m
        c.setPath("/");
        final Calendar expire = Calendar.getInstance();
        expire.add(Calendar.YEAR, 1);
        c.setExpiryDate(expire.getTime());
        c.setSecure(true);
        c.setDiscard(false);
        store.addCookie(c);
    }
}

From source file:org.geometerplus.android.fbreader.network.ActivityNetworkContext.java

public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
    boolean processed = true;
    try {/* w w w  .j a v a  2 s.  c  om*/
        switch (requestCode) {
        default:
            processed = false;
            break;
        case NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER:
            if (resultCode == Activity.RESULT_OK && data != null) {
                myAccount = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            }
            break;
        case NetworkLibraryActivity.REQUEST_AUTHORISATION:
            if (resultCode == Activity.RESULT_OK) {
                myAuthorizationConfirmed = true;
            }
            break;
        case NetworkLibraryActivity.REQUEST_WEB_AUTHORISATION_SCREEN:
            if (resultCode == Activity.RESULT_OK && data != null) {
                final CookieStore store = cookieStore();
                final Map<String, String> cookies = (Map<String, String>) data
                        .getSerializableExtra(NetworkLibraryActivity.COOKIES_KEY);
                if (cookies != null) {
                    for (Map.Entry<String, String> entry : cookies.entrySet()) {
                        final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue());
                        c.setDomain(data.getData().getHost());
                        c.setPath("/");
                        final Calendar expire = Calendar.getInstance();
                        expire.add(Calendar.YEAR, 1);
                        c.setExpiryDate(expire.getTime());
                        c.setSecure(true);
                        c.setDiscard(false);
                        store.addCookie(c);
                    }
                }
            }
            break;
        }
    } finally {
        if (processed) {
            synchronized (this) {
                notifyAll();
            }
        }
        return processed;
    }
}

From source file:org.geometerplus.zlibrary.ui.android.network.SQLiteCookieDatabase.java

@Override
protected List<Cookie> loadCookies() {
    final List<Cookie> list = new LinkedList<Cookie>();
    final Cursor cursor = myDatabase
            .rawQuery("SELECT cookie_id,host,path,name,value,date_of_expiration,secure FROM Cookie", null);
    while (cursor.moveToNext()) {
        final long id = cursor.getLong(0);
        final String host = cursor.getString(1);
        final String path = cursor.getString(2);
        final String name = cursor.getString(3);
        final String value = cursor.getString(4);
        final Date date = SQLiteUtil.getDate(cursor, 5);
        final boolean secure = cursor.getLong(6) == 1;
        Set<Integer> portSet = null;
        final Cursor portsCursor = myDatabase.rawQuery("SELECT port FROM CookiePort WHERE cookie_id = " + id,
                null);//from w  ww  . j  ava 2  s.  c  om
        while (portsCursor.moveToNext()) {
            if (portSet == null) {
                portSet = new HashSet<Integer>();
            }
            portSet.add((int) portsCursor.getLong(1));
        }
        portsCursor.close();
        final BasicClientCookie2 c = new BasicClientCookie2(name, value);
        c.setDomain(host);
        c.setPath(path);
        if (portSet != null) {
            final int ports[] = new int[portSet.size()];
            int index = 0;
            for (int p : portSet) {
                ports[index] = p;
                ++index;
            }
            c.setPorts(ports);
        }
        c.setExpiryDate(date);
        c.setSecure(secure);
        c.setDiscard(false);
        list.add(c);
    }
    cursor.close();
    return list;
}

From source file:org.geometerplus.android.fbreader.network.NetworkLibraryActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Connection.bindToService(this, new Runnable() {
        public void run() {
            getListView().invalidateViews();
        }/*from   w  w  w  . java 2s .  co m*/
    });
    if (resultCode != RESULT_OK || data == null) {
        return;
    }

    switch (requestCode) {
    case REQUEST_MANAGE_CATALOGS: {
        final ArrayList<String> myIds = data.getStringArrayListExtra(ENABLED_CATALOG_IDS_KEY);
        NetworkLibrary.Instance().setActiveIds(myIds);
        NetworkLibrary.Instance().synchronize();
        break;
    }
    case REQUEST_AUTHORISATION_SCREEN: {
        final CookieStore store = ZLNetworkManager.Instance().cookieStore();
        final Map<String, String> cookies = (Map<String, String>) data.getSerializableExtra(COOKIES_KEY);
        if (cookies == null) {
            break;
        }
        for (Map.Entry<String, String> entry : cookies.entrySet()) {
            final BasicClientCookie2 c = new BasicClientCookie2(entry.getKey(), entry.getValue());
            c.setDomain(data.getData().getHost());
            c.setPath("/");
            final Calendar expire = Calendar.getInstance();
            expire.add(Calendar.YEAR, 1);
            c.setExpiryDate(expire.getTime());
            c.setSecure(true);
            c.setDiscard(false);
            store.addCookie(c);
        }
        final NetworkTree tree = getTreeByKey((FBTree.Key) data.getSerializableExtra(TREE_KEY_KEY));
        new ReloadCatalogAction(this).run(tree);
        break;
    }
    }
}

From source file:com.google.corp.productivity.specialprojects.android.comm.SerializableCookieStore.java

public SerializableCookieStore(SharedPreferences preferences) {
    String cookiesString = preferences.getString(UserPreferences.COOKIE_PREFERENCE_KEY, null);
    if (cookiesString != null) {
        try {//  w ww.  j  a va 2s.  c o  m
            JSONArray cookies = new JSONArray(cookiesString);
            int n = cookies.length();
            for (int i = 0; i < n; i++) {
                JSONObject json = cookies.optJSONObject(i);
                if (!JSONObject.NULL.equals(json)) {
                    BasicClientCookie2 cookie = new BasicClientCookie2(json.optString(ATTR_NAME),
                            json.optString(ATTR_VALUE));
                    if (json.has(ATTR_COMMENT)) {
                        cookie.setComment(json.optString(ATTR_COMMENT));
                    }
                    if (json.has(ATTR_COMMENT_URL)) {
                        cookie.setCommentURL(json.optString(ATTR_COMMENT_URL));
                    }
                    if (json.has(ATTR_DOMAIN)) {
                        cookie.setDomain(json.optString(ATTR_DOMAIN));
                    }
                    if (json.has(ATTR_EXPIRY_DATE)) {
                        cookie.setExpiryDate(new Date(json.optLong(ATTR_EXPIRY_DATE)));
                    }
                    if (json.has(ATTR_PATH)) {
                        cookie.setPath(json.optString(ATTR_PATH));
                    }
                    if (json.has(ATTR_SECURE)) {
                        cookie.setSecure(json.optBoolean(ATTR_SECURE));
                    }
                    if (json.has(ATTR_VERSION)) {
                        cookie.setVersion(json.optInt(ATTR_VERSION));
                    }
                    if (json.has(ATTR_PORTS)) {
                        JSONArray arr = json.optJSONArray(ATTR_PORTS);
                        if (arr != null) {
                            int m = arr.length();
                            int[] ports = new int[m];
                            for (int j = 0; j < m; j++) {
                                ports[j] = arr.optInt(j);
                            }
                            cookie.setPorts(ports);
                        }
                    }
                    super.addCookie(cookie);
                }
            }
        } catch (JSONException x) {
            // Invalid string format, no cookies can be read.
        }
    }
    dirty = false;
}

From source file:org.apache.manifoldcf.crawler.connectors.webcrawler.CookieManager.java

/** Read cookies from database, uncached.
*@param sessionKey is the session key./* ww w  .j  a va 2  s  .co  m*/
*@return the login cookies object.
*/
protected LoginCookies readCookiesUncached(String sessionKey) throws ManifoldCFException {
    ArrayList list = new ArrayList();
    list.add(sessionKey);
    IResultSet result = performQuery(
            "SELECT * FROM " + getTableName() + " WHERE " + keyField + "=? ORDER BY " + ordinalField + " ASC",
            list, null, null);
    DynamicCookieSet dcs = new DynamicCookieSet();
    int i = 0;
    while (i < result.getRowCount()) {
        IResultRow row = result.getRow(i++);
        String name = (String) row.getValue(nameField);
        String value = (String) row.getValue(valueField);
        BasicClientCookie2 c = new BasicClientCookie2(name, value);
        String domain = (String) row.getValue(domainField);
        if (domain != null && domain.length() > 0)
            c.setDomain(domain);
        //c.setDomainAttributeSpecified(stringToBoolean((String)row.getValue(domainSpecifiedField)));
        String path = (String) row.getValue(pathField);
        if (path != null && path.length() > 0)
            c.setPath(path);
        //c.setPathAttributeSpecified(stringToBoolean((String)row.getValue(pathSpecifiedField)));
        Long version = (Long) row.getValue(versionField);
        if (version != null)
            c.setVersion((int) version.longValue());
        //c.setVersionAttributeSpecified(stringToBoolean((String)row.getValue(versionSpecifiedField)));
        String comment = (String) row.getValue(commentField);
        if (comment != null)
            c.setComment(comment);
        c.setSecure(stringToBoolean((String) row.getValue(secureField)));
        Long expirationDate = (Long) row.getValue(expirationDateField);
        if (expirationDate != null)
            c.setExpiryDate(new Date(expirationDate.longValue()));
        c.setDiscard(stringToBoolean((String) row.getValue(discardField)));
        String commentURL = (String) row.getValue(commentURLField);
        if (commentURL != null && commentURL.length() > 0)
            c.setCommentURL(commentURL);
        String ports = (String) row.getValue(portField);
        // Ports are comma-separated
        if (ports != null && ports.length() > 0)
            c.setPorts(stringToPorts(ports));
        //c.setPortAttributeBlank(stringToBoolean((String)row.getValue(portBlankField)));
        //c.setPortAttributeSpecified(stringToBoolean((String)row.getValue(portSpecifiedField)));

        dcs.addCookie(c);
    }
    return dcs;
}