Cookie Cache
/** * */ //package org.alldroid.forum.net; import java.util.List; import org.apache.http.client.CookieStore; import org.apache.http.cookie.Cookie; import org.apache.http.impl.client.BasicCookieStore; /** * @author trr4rac * */ public class CookieCache { private CookieStore store; private LoginCookie cookie; private CookieCache ( ) { setCookieStore ( new BasicCookieStore () ); } public String get ( String name ) { List<Cookie> cookies = this.getCookieStore ().getCookies (); for ( int i = 0; i < cookies.size (); i++ ) { Cookie c = cookies.get ( i ); if ( c.getName ().equals ( name ) ) { return c.getValue (); } } return null; } /** * @param store the store to set */ private void setCookieStore ( CookieStore store ) { this.store = store; } /** * @return the store */ public CookieStore getCookieStore ( ) { return store; } private static CookieCache instance; public static CookieCache getInstance ( ) { if ( instance == null ) { instance = new CookieCache (); } return instance; } /** * @param cookie the cookie to set */ public void setCookie ( LoginCookie cookie ) { this.cookie = cookie; } /** * @return the cookie */ public LoginCookie getCookie ( ) { return cookie; } } class LoginCookie { private String sessionHash; private long lastAvctivity; private long lastVisit; private String passwordHash; private String userId; /** * @param sessionHash the sessionHash to set */ public void setSessionHash ( String sessionHash ) { this.sessionHash = sessionHash; } /** * @return the sessionHash */ public String getSessionHash ( ) { return sessionHash; } /** * @param lastAvctivity the lastAvctivity to set */ public void setLastAvctivity ( long lastAvctivity ) { this.lastAvctivity = lastAvctivity; } /** * @return the lastAvctivity */ public long getLastAvctivity ( ) { return lastAvctivity; } /** * @param lastVisit the lastVisit to set */ public void setLastVisit ( long lastVisit ) { this.lastVisit = lastVisit; } /** * @return the lastVisit */ public long getLastVisit ( ) { return lastVisit; } /** * @param passwordHash the passwordHash to set */ public void setPasswordHash ( String passwordHash ) { this.passwordHash = passwordHash; } /** * @return the passwordHash */ public String getPasswordHash ( ) { return passwordHash; } /** * @param userId the userId to set */ public void setUserId ( String userId ) { this.userId = userId; } /** * @return the userId */ public String getUserId ( ) { return userId; } }