本文整理汇总了Java中com.codename1.io.Cookie类的典型用法代码示例。如果您正苦于以下问题:Java Cookie类的具体用法?Java Cookie怎么用?Java Cookie使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cookie类属于com.codename1.io包,在下文中一共展示了Cookie类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeCookiesForDomain
import com.codename1.io.Cookie; //导入依赖的package包/类
protected final void removeCookiesForDomain(String domain) {
if(cookies == null || domain==null){
return;
}
Hashtable h = (Hashtable)cookies.get(domain);
if (h == null) {
return;
}
h.clear();
if(Cookie.isAutoStored()){
if(Storage.getInstance().exists(Cookie.STORAGE_NAME)){
Storage.getInstance().deleteStorageFile(Cookie.STORAGE_NAME);
}
Storage.getInstance().writeObject(Cookie.STORAGE_NAME, cookies);
}
}
示例2: addCookie
import com.codename1.io.Cookie; //导入依赖的package包/类
/**
* Adds/replaces a cookie to be sent to the given domain
*
* @param c cookie to add
*/
public void addCookie(Cookie c) {
if(cookies == null){
cookies = new Hashtable();
}
Hashtable h = (Hashtable)cookies.get(c.getDomain());
if(h == null){
h = new Hashtable();
cookies.put(c.getDomain(), h);
}
h.put(c.getName(), c);
if(Cookie.isAutoStored()){
if(Storage.getInstance().exists(Cookie.STORAGE_NAME)){
Storage.getInstance().deleteStorageFile(Cookie.STORAGE_NAME);
}
Storage.getInstance().writeObject(Cookie.STORAGE_NAME, cookies);
}
}
示例3: addCookie
import com.codename1.io.Cookie; //导入依赖的package包/类
public void addCookie(Cookie [] cookiesArray) {
if(cookies == null){
cookies = new Hashtable();
}
for (int i = 0; i < cookiesArray.length; i++) {
Cookie cookie = cookiesArray[i];
Hashtable h = (Hashtable)cookies.get(cookie.getDomain());
if(h == null){
h = new Hashtable();
cookies.put(cookie.getDomain(), h);
}
h.put(cookie.getName(), cookie);
}
if(Cookie.isAutoStored()){
if(Storage.getInstance().exists(Cookie.STORAGE_NAME)){
Storage.getInstance().deleteStorageFile(Cookie.STORAGE_NAME);
}
Storage.getInstance().writeObject(Cookie.STORAGE_NAME, cookies);
}
}
示例4: show
import com.codename1.io.Cookie; //导入依赖的package包/类
public void show(Command cmd)
{
Cookie.clearCookiesFromStorage();
Api.getInstance().logout();
ui.setHomeForm(FORM_NAME);
ui.showForm(FORM_NAME, cmd);
}
示例5: addCookie
import com.codename1.io.Cookie; //导入依赖的package包/类
@Override
public void addCookie(Cookie c) {
if(isUseNativeCookieStore()) {
nativeInstance.addCookie(c.getName(), c.getValue(), c.getDomain(), c.getPath(), c.isSecure(), c.isHttpOnly(), c.getExpires());
} else {
super.addCookie(c);
}
}
示例6: purgeOldCookies
import com.codename1.io.Cookie; //导入依赖的package包/类
private void purgeOldCookies(Map<String,Cookie> cookies) {
long now = System.currentTimeMillis();
for (Map.Entry<String,Cookie> e : cookies.entrySet()) {
if (e.getValue().getExpires() != 0 && e.getValue().getExpires() < now) {
cookies.remove(e.getKey());
}
}
}
示例7: getCookiesForURL
import com.codename1.io.Cookie; //导入依赖的package包/类
/**
* Returns the cookies for this URL
*
* @param url the url on which we are checking for cookies
* @return the cookies to submit to the given URL
*/
public Vector getCookiesForURL(String url) {
Vector response = null;
if (Cookie.isAutoStored()) {
cookies = (Hashtable) Storage.getInstance().readObject(Cookie.STORAGE_NAME);
}
String protocol = "";
int pos = -1;
if ( (pos = url.indexOf(":")) >= 0 ){
protocol = url.substring(0, pos);
}
boolean isHttp = ("http".equals(protocol) || "https".equals(protocol) );
boolean isSecure = "https".equals(protocol);
String path = getURLPath(url);
if(cookies != null && cookies.size() > 0) {
String domain = getURLDomain(url);
Enumeration e = cookies.keys();
while (e.hasMoreElements()) {
String domainKey = (String) e.nextElement();
if (domain.indexOf(domainKey) > -1) {
Hashtable h = (Hashtable) cookies.get(domainKey);
if (h != null) {
Enumeration enumCookies = h.elements();
if(response == null){
response = new Vector();
}
while (enumCookies.hasMoreElements()) {
Cookie nex = (Cookie)enumCookies.nextElement();
if ( nex.isHttpOnly() && !isHttp ){
continue;
}
if ( nex.isSecure() && !isSecure ){
continue;
}
if ( path.indexOf(nex.getPath()) != 0 ){
continue;
}
response.addElement(nex);
}
}
}
}
}
return response;
}