⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cookie.java

📁 这是个爬虫和lucece相结合最好了
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Header$ * $Revision: 4672 $ * $Date: 2006-09-27 00:03:16 +0000 (Wed, 27 Sep 2006) $ * * ==================================================================== * *  Copyright 1999-2004 The Apache Software Foundation * *  Licensed 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. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */package org.apache.commons.httpclient;import java.io.Serializable;import java.text.RuleBasedCollator;import java.util.Comparator;import java.util.Date;import java.util.Locale;import org.apache.commons.httpclient.cookie.CookiePolicy;import org.apache.commons.httpclient.cookie.CookieSpec;import org.apache.commons.httpclient.util.LangUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * <p> * HTTP "magic-cookie" represents a piece of state information * that the HTTP agent and the target server can exchange to maintain  * a session. * </p> *  * @author B.C. Holmes * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a> * @author <a href="mailto:dsale@us.britannica.com">Doug Sale</a> * @author Rod Waldhoff * @author dIon Gillard * @author Sean C. Sullivan * @author <a href="mailto:JEvans@Cyveillance.com">John Evans</a> * @author Marc A. Saegesser * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a> * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> *  * @version $Revision: 4672 $ $Date: 2006-09-27 00:03:16 +0000 (Wed, 27 Sep 2006) $ */@SuppressWarnings("serial")public class Cookie extends NameValuePair implements Serializable, Comparator {    // ----------------------------------------------------------- Constructors    /**     * Default constructor. Creates a blank cookie      */    public Cookie() {        this(null, "noname", null, null, null, false);    }    /**     * Creates a cookie with the given name, value and domain attribute.     *     * @param name    the cookie name     * @param value   the cookie value     * @param domain  the domain this cookie can be sent to     */    public Cookie(String domain, String name, String value) {        this(domain, name, value, null, null, false);    }    /**     * Creates a cookie with the given name, value, domain attribute,     * path attribute, expiration attribute, and secure attribute      *     * @param name    the cookie name     * @param value   the cookie value     * @param domain  the domain this cookie can be sent to     * @param path    the path prefix for which this cookie can be sent     * @param expires the {@link Date} at which this cookie expires,     *                or <tt>null</tt> if the cookie expires at the end     *                of the session     * @param secure if true this cookie can only be sent over secure     * connections     * @throws IllegalArgumentException If cookie name is null or blank,     *   cookie name contains a blank, or cookie name starts with character $     *        */    public Cookie(String domain, String name, String value,         String path, Date expires, boolean secure) {                    super(name, value);        LOG.trace("enter Cookie(String, String, String, String, Date, boolean)");        if (name == null) {            throw new IllegalArgumentException("Cookie name may not be null");        }        if (name.trim().equals("")) {            throw new IllegalArgumentException("Cookie name may not be blank");        }        this.setPath(path);        this.setDomain(domain);        this.setExpiryDate(expires);        this.setSecure(secure);    }    /**     * Creates a cookie with the given name, value, domain attribute,     * path attribute, maximum age attribute, and secure attribute      *     * @param name   the cookie name     * @param value  the cookie value     * @param domain the domain this cookie can be sent to     * @param path   the path prefix for which this cookie can be sent     * @param maxAge the number of seconds for which this cookie is valid.     *               maxAge is expected to be a non-negative number.      *               <tt>-1</tt> signifies that the cookie should never expire.     * @param secure if <tt>true</tt> this cookie can only be sent over secure     * connections     */    public Cookie(String domain, String name, String value, String path,         int maxAge, boolean secure) {                    this(domain, name, value, path, null, secure);        if (maxAge < -1) {            throw new IllegalArgumentException("Invalid max age:  " + Integer.toString(maxAge));        }                    if (maxAge >= 0) {            setExpiryDate(new Date(System.currentTimeMillis() + maxAge * 1000L));        }    }    /**     * Returns the comment describing the purpose of this cookie, or     * <tt>null</tt> if no such comment has been defined.     *      * @return comment      *     * @see #setComment(String)     */    public String getComment() {        return cookieComment;    }    /**     * If a user agent (web browser) presents this cookie to a user, the     * cookie's purpose will be described using this comment.     *      * @param comment     *       * @see #getComment()     */    public void setComment(String comment) {        cookieComment = comment;    }    /**     * Returns the expiration {@link Date} of the cookie, or <tt>null</tt>     * if none exists.     * <p><strong>Note:</strong> the object returned by this method is      * considered immutable. Changing it (e.g. using setTime()) could result     * in undefined behaviour. Do so at your peril. </p>     * @return Expiration {@link Date}, or <tt>null</tt>.     *     * @see #setExpiryDate(java.util.Date)     *     */    public Date getExpiryDate() {        return cookieExpiryDate;    }    /**     * Sets expiration date.     * <p><strong>Note:</strong> the object returned by this method is considered     * immutable. Changing it (e.g. using setTime()) could result in undefined      * behaviour. Do so at your peril.</p>     *     * @param expiryDate the {@link Date} after which this cookie is no longer valid.     *     * @see #getExpiryDate     *     */    public void setExpiryDate (Date expiryDate) {        cookieExpiryDate = expiryDate;    }    /**     * Returns <tt>false</tt> if the cookie should be discarded at the end     * of the "session"; <tt>true</tt> otherwise.     *     * @return <tt>false</tt> if the cookie should be discarded at the end     *         of the "session"; <tt>true</tt> otherwise     */    public boolean isPersistent() {        return (null != cookieExpiryDate);    }    /**     * Returns domain attribute of the cookie.     *      * @return the value of the domain attribute     *     * @see #setDomain(java.lang.String)     */    public String getDomain() {        return cookieDomain;    }    /**     * Sets the domain attribute.     *      * @param domain The value of the domain attribute     *     * @see #getDomain     */    public void setDomain(String domain) {        if (domain != null) {            int ndx = domain.indexOf(":");            if (ndx != -1) {              domain = domain.substring(0, ndx);            }            cookieDomain = domain.toLowerCase();        }    }    /**     * Returns the path attribute of the cookie     *      * @return The value of the path attribute.     *      * @see #setPath(java.lang.String)     */    public String getPath() {        return cookiePath;    }    /**     * Sets the path attribute.     *     * @param path The value of the path attribute     *     * @see #getPath     *     */    public void setPath(String path) {        cookiePath = path;    }    /**     * @return <code>true</code> if this cookie should only be sent over secure connections.     * @see #setSecure(boolean)     */    public boolean getSecure() {        return isSecure;    }    /**     * Sets the secure attribute of the cookie.     * <p>     * When <tt>true</tt> the cookie should only be sent     * using a secure protocol (https).  This should only be set when     * the cookie's originating server used a secure protocol to set the     * cookie's value.     *     * @param secure The value of the secure attribute     *      * @see #getSecure()     */    public void setSecure (boolean secure) {        isSecure = secure;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -