Search in sources :

Example 1 with BasicClientCookie2

use of org.apache.http.impl.cookie.BasicClientCookie2 in project FBReaderJ by geometer.

the class WebAuthorisationScreen method storeCookies.

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);
        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);
    }
}
Also used : BasicClientCookie2(org.apache.http.impl.cookie.BasicClientCookie2) ZLNetworkManager(org.geometerplus.zlibrary.core.network.ZLNetworkManager)

Example 2 with BasicClientCookie2

use of org.apache.http.impl.cookie.BasicClientCookie2 in project FBReaderJ by geometer.

the class SQLiteCookieDatabase method loadCookies.

@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);
        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;
}
Also used : Cookie(org.apache.http.cookie.Cookie) BasicClientCookie2(org.apache.http.impl.cookie.BasicClientCookie2) Cursor(android.database.Cursor)

Aggregations

BasicClientCookie2 (org.apache.http.impl.cookie.BasicClientCookie2)2 Cursor (android.database.Cursor)1 Cookie (org.apache.http.cookie.Cookie)1 ZLNetworkManager (org.geometerplus.zlibrary.core.network.ZLNetworkManager)1