Home | History | Annotate | Download | only in cookie
      1 /*
      2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/cookie/CookieOrigin.java $
      3  * $Revision: 653041 $
      4  * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 May 2008) $
      5  *
      6  * ====================================================================
      7  * Licensed to the Apache Software Foundation (ASF) under one
      8  * or more contributor license agreements.  See the NOTICE file
      9  * distributed with this work for additional information
     10  * regarding copyright ownership.  The ASF licenses this file
     11  * to you under the Apache License, Version 2.0 (the
     12  * "License"); you may not use this file except in compliance
     13  * with the License.  You may obtain a copy of the License at
     14  *
     15  *   http://www.apache.org/licenses/LICENSE-2.0
     16  *
     17  * Unless required by applicable law or agreed to in writing,
     18  * software distributed under the License is distributed on an
     19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     20  * KIND, either express or implied.  See the License for the
     21  * specific language governing permissions and limitations
     22  * under the License.
     23  * ====================================================================
     24  *
     25  * This software consists of voluntary contributions made by many
     26  * individuals on behalf of the Apache Software Foundation.  For more
     27  * information on the Apache Software Foundation, please see
     28  * <http://www.apache.org/>.
     29  *
     30  */
     31 package org.apache.http.cookie;
     32 
     33 import java.util.Locale;
     34 
     35 /**
     36  * CookieOrigin class incapsulates details of an origin server that
     37  * are relevant when parsing, validating or matching HTTP cookies.
     38  *
     39  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
     40  *
     41  * @since 4.0
     42  *
     43  * @deprecated Please use {@link java.net.URL#openConnection} instead.
     44  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
     45  *     for further details.
     46  */
     47 @Deprecated
     48 public final class CookieOrigin {
     49 
     50     private final String host;
     51     private final int port;
     52     private final String path;
     53     private final boolean secure;
     54 
     55     public CookieOrigin(final String host, int port, final String path, boolean secure) {
     56         super();
     57         if (host == null) {
     58             throw new IllegalArgumentException(
     59                     "Host of origin may not be null");
     60         }
     61         if (host.trim().length() == 0) {
     62             throw new IllegalArgumentException(
     63                     "Host of origin may not be blank");
     64         }
     65         if (port < 0) {
     66             throw new IllegalArgumentException("Invalid port: " + port);
     67         }
     68         if (path == null) {
     69             throw new IllegalArgumentException(
     70                     "Path of origin may not be null.");
     71         }
     72         this.host = host.toLowerCase(Locale.ENGLISH);
     73         this.port = port;
     74         if (path.trim().length() != 0) {
     75             this.path = path;
     76         } else {
     77             this.path = "/";
     78         }
     79         this.secure = secure;
     80     }
     81 
     82     public String getHost() {
     83         return this.host;
     84     }
     85 
     86     public String getPath() {
     87         return this.path;
     88     }
     89 
     90     public int getPort() {
     91         return this.port;
     92     }
     93 
     94     public boolean isSecure() {
     95         return this.secure;
     96     }
     97 
     98     @Override
     99     public String toString() {
    100         StringBuilder buffer = new StringBuilder();
    101         buffer.append('[');
    102         if (this.secure) {
    103             buffer.append("(secure)");
    104         }
    105         buffer.append(this.host);
    106         buffer.append(':');
    107         buffer.append(Integer.toString(this.port));
    108         buffer.append(this.path);
    109         buffer.append(']');
    110         return buffer.toString();
    111     }
    112 
    113 }
    114