Java Code Examples for org.apache.http.cookie.Cookie#isExpired()

The following examples show how to use org.apache.http.cookie.Cookie#isExpired() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PersistentCookieStore.java    From Mobike with Apache License 2.0 6 votes vote down vote up
@Override
public void addCookie(Cookie cookie) {
    if (omitNonPersistentCookies && !cookie.isPersistent())
        return;
    String name = cookie.getName() + cookie.getDomain();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
        cookies.put(name, cookie);
    } else {
        cookies.remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();
}
 
Example 2
Source File: PersistentCookieStore.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public void addCookie(Cookie cookie)
{
    if (e && !cookie.isPersistent())
    {
        return;
    }
    String s = (new StringBuilder()).append(cookie.getName()).append(cookie.getDomain()).toString();
    android.content.SharedPreferences.Editor editor;
    if (!cookie.isExpired(new Date()))
    {
        f.put(s, cookie);
    } else
    {
        f.remove(s);
    }
    editor = g.edit();
    editor.putString("names", TextUtils.join(",", f.keySet()));
    editor.putString((new StringBuilder()).append("cookie_").append(s).toString(), encodeCookie(new SerializableCookie(cookie)));
    editor.commit();
}
 
Example 3
Source File: PersistentCookieStore.java    From bither-android with Apache License 2.0 6 votes vote down vote up
@Override
public void addCookie(Cookie cookie) {
	String name = cookie.getName();

	// Save cookie into local store, or remove if expired
	if (!cookie.isExpired(new Date())) {
		cookies.put(name, cookie);
	} else {
		cookies.remove(name);
	}

	// Save cookie into persistent store
	SharedPreferences.Editor prefsWriter = this.cookiePrefs.edit();
	prefsWriter.putString(COOKIE_NAME_STORE,
			TextUtils.join(",", cookies.keySet()));
	prefsWriter.putString(COOKIE_NAME_PREFIX + name,
			encodeCookie(new SerializableCookie(cookie)));
	prefsWriter.commit();
}
 
Example 4
Source File: PreferencesCookieStore.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
@Override
public void addCookie(Cookie cookie) {
    String name = cookie.getName();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
        cookies.put(name, cookie);
    } else {
        cookies.remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor editor = cookiePrefs.edit();
    editor.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    editor.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    editor.commit();
}
 
Example 5
Source File: PersistentCookieStore.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
@Override
public void addCookie(Cookie cookie) {
    if (omitNonPersistentCookies && !cookie.isPersistent())
        return;
    String name = cookie.getName() + cookie.getDomain();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
        cookies.put(name, cookie);
    } else {
        cookies.remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();
}
 
Example 6
Source File: PersistentCookieStore.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public void addCookie(Cookie cookie) {
    String name = cookie.getName();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
        cookies.put(name, cookie);
    } else {
        cookies.remove(name);
    }

    // Save cookie into persistent store

    Set<String> keySet = cookies.keySet();
    userPreferences.setProperty(COOKIE_NAME_STORE,
            join(",", keySet));
    userPreferences.setProperty(COOKIE_NAME_PREFIX + name,
            encodeCookie(new SerializableCookie(cookie)));
    UserPreference.getInstance().saveUserPreferences();
}
 
Example 7
Source File: PersistentCookieStore.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
@Override
public void addCookie(Cookie cookie) {
    if (omitNonPersistentCookies && !cookie.isPersistent())
        return;
    String name = cookie.getName() + cookie.getDomain();

    // Save cookie into local store, or remove if expired
    if (!cookie.isExpired(new Date())) {
        cookies.put(name, cookie);
    } else {
        cookies.remove(name);
    }

    // Save cookie into persistent store
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();
}
 
Example 8
Source File: PersistentCookieStore.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
 
Example 9
Source File: PreferencesCookieStore.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor editor = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.getExpiryDate() == null || cookie.isExpired(date)) {
            // Remove the cookie by name
            cookies.remove(name);

            // Clear cookies from persistent store
            editor.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        editor.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    editor.commit();

    return clearedAny;
}
 
Example 10
Source File: PersistentCookieStore.java    From sealtalk-android with MIT License 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
 
Example 11
Source File: PreferencesCookieStore.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor editor = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.getExpiryDate() == null || cookie.isExpired(date)) {
            // Remove the cookie by name
            cookies.remove(name);

            // Clear cookies from persistent store
            editor.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        editor.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    editor.commit();

    return clearedAny;
}
 
Example 12
Source File: PersistentCookieStore.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
 
Example 13
Source File: PersistentCookieStore.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
	boolean clearedAny = false;
	SharedPreferences.Editor prefsWriter = this.cookiePrefs.edit();

	for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
		String name = entry.getKey();
		Cookie cookie = entry.getValue();
		if (cookie.isExpired(date)) {
			// Clear cookies from local store
			cookies.remove(name);

			// Clear cookies from persistent store
			prefsWriter.remove(COOKIE_NAME_PREFIX + name);

			// We've cleared at least one
			clearedAny = true;
		}
	}

	// Update names in persistent store
	if (clearedAny) {
		prefsWriter.putString(COOKIE_NAME_STORE,
				TextUtils.join(",", cookies.keySet()));
	}
	prefsWriter.commit();
	return clearedAny;
}
 
Example 14
Source File: PersistentCookieStore.java    From Mobike with Apache License 2.0 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
 
Example 15
Source File: PersistentCookieStore.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
 
Example 16
Source File: PersistentCookieStore.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if (cookie.isExpired(date)) {
            // Clear cookies from local store
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if (clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
 
Example 17
Source File: PreferencesCookieStore.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
@Override
public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for(ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
        String name = entry.getKey();
        Cookie cookie = entry.getValue();
        if(cookie.isExpired(date)) {
            // 清除cookies
            cookies.remove(name);

            // Clear cookies from persistent store
            prefsWriter.remove(COOKIE_NAME_PREFIX + name);

            // We've cleared at least one
            clearedAny = true;
        }
    }

    // Update names in persistent store
    if(clearedAny) {
        prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
}
 
Example 18
Source File: PersistentCookieStore.java    From letv with Apache License 2.0 5 votes vote down vote up
public void addCookie(Cookie cookie) {
    String name = cookie.getName() + cookie.getDomain();
    if (cookie.isExpired(new Date())) {
        this.cookies.remove(name);
    } else {
        this.cookies.put(name, cookie);
    }
    Editor prefsWriter = this.cookiePrefs.edit();
    prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", this.cookies.keySet()));
    prefsWriter.putString(new StringBuilder(COOKIE_NAME_PREFIX).append(name).toString(), encodeCookie(new SerializableCookie(cookie)));
    prefsWriter.commit();
}
 
Example 19
Source File: GlobalCookieStore.java    From ache with Apache License 2.0 3 votes vote down vote up
/**
 * Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent
 * cookies. If the given ookie has already expired it will not be added, but
 * existing values will still be removed.
 * 
 * @param cookie
 *            the {@link Cookie cookie} to be added
 * 
 * @see #addCookies(Cookie[])
 * 
 */
public void addCookie(Cookie cookie) {
    if (cookie != null) {
        // first remove any old cookie that is equivalent
        cookies.remove(cookie.getDomain()+"__"+cookie.getName()+"__"+cookie.getPath());
        if (!cookie.isExpired(new Date())) {
        	cookies.put(cookie.getDomain()+"__"+cookie.getName()+"__"+cookie.getPath(), cookie);
        }
    }
}
 
Example 20
Source File: LocalCookieStore.java    From ache with Apache License 2.0 3 votes vote down vote up
/**
 * Adds an {@link Cookie HTTP cookie}, replacing any existing equivalent
 * cookies. If the given ookie has already expired it will not be added, but
 * existing values will still be removed.
 * 
 * @param cookie
 *            the {@link Cookie cookie} to be added
 * 
 * @see #addCookies(Cookie[])
 * 
 */
public void addCookie(Cookie cookie) {
    if (cookie != null) {
        // first remove any old cookie that is equivalent
        cookies.remove(cookie);
        if (!cookie.isExpired(new Date())) {
            cookies.add(cookie);
        }
    }
}