org.nervousync.http.cookie.CookieEntity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils-jdk11 Show documentation
Show all versions of utils-jdk11 Show documentation
Java utility collections, development by Nervousync Studio (NSYC)
/*
* Licensed to the Nervousync Studio (NSYC) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nervousync.http.cookie;
import java.text.ParseException;
import org.nervousync.commons.Globals;
import org.nervousync.utils.DateTimeUtils;
import org.nervousync.utils.StringUtils;
/**
* Cookie information Define
* Cookie信息定义
*
* @author Steven Wee [email protected]
* @version $Revision: 1.0.0 $ $Date: Jan 4, 2018 13:01:35 $
*/
public final class CookieEntity {
/**
* Cookie name
* Cookie名
*/
private String name = null;
/**
* Cookie value
* Cookie值
*/
private String value = null;
/**
* Cookie path
* Cookie目录
*/
private String path = null;
/**
* Cookie domain name
* Cookie域名
*/
private String domain = null;
/**
* Cookie expire time
* Cookie过期时间
*/
private long expires = Globals.DEFAULT_VALUE_LONG;
/**
* Cookie maximum age
* Cookie最大生命周期
*/
private long maxAge = Globals.DEFAULT_VALUE_LONG;
/**
* Cookie secure status
* Cookie是否用于加密传输
*/
private boolean secure = Boolean.FALSE;
/**
* Cookie version value
* Cookie版本号
*/
private int version = 0;
/**
* Constructor method for CookieEntity
* CookieEntity构造方法
*
* @param cookieValue Cookie value from response header
* 来自响应头的Cookie值
*/
public CookieEntity(String cookieValue) {
if (cookieValue != null && cookieValue.length() > 0) {
String[] cookieItems = StringUtils.delimitedListToStringArray(cookieValue, ";");
for (String cookieItem : cookieItems) {
String[] cookieInfo = StringUtils.delimitedListToStringArray(cookieItem, "=");
if (cookieInfo.length == 2) {
if ("path".equalsIgnoreCase(cookieInfo[0])) {
this.path = cookieInfo[1];
} else if ("domain".equalsIgnoreCase(cookieInfo[0])) {
this.domain = cookieInfo[1];
} else if ("expires".equalsIgnoreCase(cookieInfo[0])) {
try {
this.expires = DateTimeUtils.parseGMTDate(cookieInfo[1]).getTime();
} catch (ParseException e) {
this.expires = Globals.DEFAULT_VALUE_LONG;
}
} else if ("max-age".equalsIgnoreCase(cookieInfo[0])) {
this.maxAge = Long.parseLong(cookieInfo[1]);
} else if ("version".equalsIgnoreCase(cookieInfo[0])) {
this.version = Integer.parseInt(cookieInfo[1]);
} else {
this.name = cookieInfo[0];
this.value = cookieInfo[1];
}
} else if (cookieInfo.length == 1
&& "secure".equalsIgnoreCase(cookieInfo[0])) {
this.secure = true;
}
}
}
}
/**
* Getter method for cookie name
* Cookie名的Getter方法
*
* @return Cookie name
* Cookie名
*/
public String getName() {
return name;
}
/**
* Getter method for cookie value
* Cookie值的Getter方法
*
* @return Cookie value
* Cookie值
*/
public String getValue() {
return value;
}
/**
* Getter method for cookie path
* Cookie目录的Getter方法
*
* @return Cookie path
* Cookie目录
*/
public String getPath() {
return path;
}
/**
* Getter method for cookie domain name
* Cookie域名的Getter方法
*
* @return Cookie domain name
* Cookie域名
*/
public String getDomain() {
return domain;
}
/**
* Getter method for cookie expires
* Cookie过期时间的Getter方法
*
* @return Cookie expire time
* Cookie过期时间
*/
public long getExpires() {
return expires;
}
/**
* Getter method for cookie maximum age
* Cookie最大生命周期的Getter方法
*
* @return Cookie maximum age
* Cookie最大生命周期
*/
public long getMaxAge() {
return maxAge;
}
/**
* Getter method for cookie secure status
* Cookie加密传输的Getter方法
*
* @return Cookie secure status
* Cookie是否用于加密传输
*/
public boolean isSecure() {
return secure;
}
/**
* Getter method for cookie version
* Cookie版本号的Getter方法
*
* @return Cookie version value
* Cookie版本号
*/
public int getVersion() {
return version;
}
}