📄 xcookie.java
字号:
/****************************************************************
* XBrowser - eXtended web Browser *
* *
* Copyright (c) 2000-2001 Armond Avanes *
* Refer to ReadMe & License files for more information *
* *
* *
* By: Armond Avanes *
* Armond555@yahoo.com & Armond333@yahoo.com *
* http://xbrowser.sourceforge.net/ *
*****************************************************************/
package xbrowser.cookie;
import java.awt.*;
import java.util.*;
import java.text.*;
import java.beans.*;
import xbrowser.*;
public class XCookie
{
public XCookie()
{
propChangeSupport = new PropertyChangeSupport(this);
}
public String toString()
{
String result = getName() + "=" + getValue();
if( maxAge != 0)
result += ";Expires=" + df.format( new Date( maxAge));
if( getDomain() != null && !getDomain().equals(""))
result += ";Domain=" + getDomain();
if( getPath() != null && ! getPath().equals( ""))
result += ";Path=" + getPath();
return result;
}
public String toSendString()
{
return getName() + "=" + getValue();
}
public boolean equals(Object obj)
{
if( obj == null || !(obj instanceof XCookie) )
return false;
XCookie cookie = (XCookie)obj;
return( cookie.getName().equalsIgnoreCase(getName()) &&
cookie.getDomain().equalsIgnoreCase(getDomain()) &&
cookie.getPath().equalsIgnoreCase(getPath())
);
}
public boolean sameData( XCookie c)
{
return this.equals(c) && value.equals( c.getValue()) &&
( comment == null || c == null || comment.equals( c.getComment())) &&
maxAge == c.getMaxAge() && version == c.getVersion() &&
secure == c.isSecure();
}
public String getName()
{
return name;
}
public void setName(String new_name)
{
String old_name = name;
name = new_name;
propChangeSupport.firePropertyChange("Name", old_name, name);
}
public String getValue()
{
return value;
}
public void setValue(String new_value)
{
String old_value = value;
value = new_value;
propChangeSupport.firePropertyChange("Value", old_value, value);
}
public String getPath()
{
return path;
}
public void setPath(String new_path)
{
String old_path = path;
path = new_path;
propChangeSupport.firePropertyChange("Path", old_path, path);
}
public String getDomain()
{
return domain;
}
public void setDomain(String new_domain)
{
String old_domain = domain;
domain = new_domain;
propChangeSupport.firePropertyChange("Domain", old_domain, domain);
}
public String getComment()
{
return comment;
}
public void setComment(String new_comment)
{
String old_comment = comment;
comment = new_comment;
propChangeSupport.firePropertyChange("Comment", old_comment, comment);
}
public double getVersion()
{
return version;
}
public void setVersion(double new_version)
{
double old_version = version;
version = new_version;
propChangeSupport.firePropertyChange("Version", ""+old_version, ""+version);
}
public void setVersion(String new_version)
{
setVersion( Double.parseDouble(new_version) );
}
public boolean isSecure()
{
return secure;
}
public void setSecure(boolean new_secure)
{
boolean old_secure = secure;
secure = new_secure;
propChangeSupport.firePropertyChange("Secure", old_secure, secure);
}
public boolean isValid()
{
return( maxAge!=0 );
}
public long getMaxAge()
{
return maxAge;
}
public void setMaxAge(long new_max_age)
{
long old_max_age = maxAge;
maxAge = new_max_age;
propChangeSupport.firePropertyChange("MaxAge", (int)old_max_age, (int)maxAge);
}
public void setMaxAge(String new_max_age)
{
setVersion( Double.parseDouble(new_max_age) );
}
public void setExpires(String expire_date)
{
try
{
expire_date = expire_date.replace( '-', ' '); // Sometimes happens
setMaxAge( df.parse(expire_date).getTime() );
}
catch( ParseException pex )
{
XRepository.getLogger().error(this, "Bad date !!");
XRepository.getLogger().error(this, pex);
}
}
// Attributes:
private String name;
private String value;
private String path;
private String domain;
private String comment;
private double version;
private long maxAge;
private boolean secure = false;
private PropertyChangeSupport propChangeSupport = null;
private final static String pattern = "EEE, d MMM yyyy hh:mm:ss z";
private static SimpleDateFormat df = new SimpleDateFormat( pattern, Locale.ENGLISH);
static
{
df.setTimeZone( TimeZone.getTimeZone("GMT") );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -