Home | History | Annotate | Download | only in params
      1 /*
      2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpProtocolParams.java $
      3  * $Revision: 576089 $
      4  * $Date: 2007-09-16 05:39:56 -0700 (Sun, 16 Sep 2007) $
      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 
     32 package org.apache.http.params;
     33 
     34 import org.apache.http.HttpVersion;
     35 import org.apache.http.ProtocolVersion;
     36 import org.apache.http.protocol.HTTP;
     37 
     38 /**
     39  * This class implements an adaptor around the {@link HttpParams} interface
     40  * to simplify manipulation of the HTTP protocol specific parameters.
     41  * <br/>
     42  * Note that the <i>implements</i> relation to {@link CoreProtocolPNames}
     43  * is for compatibility with existing application code only. References to
     44  * the parameter names should use the interface, not this class.
     45  *
     46  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
     47  *
     48  * @version $Revision: 576089 $
     49  *
     50  * @since 4.0
     51  *
     52  * @see CoreProtocolPNames
     53  *
     54  * @deprecated Please use {@link java.net.URL#openConnection} instead.
     55  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
     56  *     for further details.
     57  */
     58 @Deprecated
     59 public final class HttpProtocolParams implements CoreProtocolPNames {
     60 
     61     /**
     62      */
     63     private HttpProtocolParams() {
     64         super();
     65     }
     66 
     67     /**
     68      * Returns the charset to be used for writing HTTP headers.
     69      * @return The charset
     70      */
     71     public static String getHttpElementCharset(final HttpParams params) {
     72         if (params == null) {
     73             throw new IllegalArgumentException("HTTP parameters may not be null");
     74         }
     75         String charset = (String) params.getParameter
     76             (CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
     77         if (charset == null) {
     78             charset = HTTP.DEFAULT_PROTOCOL_CHARSET;
     79         }
     80         return charset;
     81     }
     82 
     83     /**
     84      * Sets the charset to be used for writing HTTP headers.
     85      * @param charset The charset
     86      */
     87     public static void setHttpElementCharset(final HttpParams params, final String charset) {
     88         if (params == null) {
     89             throw new IllegalArgumentException("HTTP parameters may not be null");
     90         }
     91         params.setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, charset);
     92     }
     93 
     94     /**
     95      * Returns the default charset to be used for writing content body,
     96      * when no charset explicitly specified.
     97      * @return The charset
     98      */
     99     public static String getContentCharset(final HttpParams params) {
    100         if (params == null) {
    101             throw new IllegalArgumentException("HTTP parameters may not be null");
    102         }
    103         String charset = (String) params.getParameter
    104             (CoreProtocolPNames.HTTP_CONTENT_CHARSET);
    105         if (charset == null) {
    106             charset = HTTP.DEFAULT_CONTENT_CHARSET;
    107         }
    108         return charset;
    109     }
    110 
    111     /**
    112      * Sets the default charset to be used for writing content body,
    113      * when no charset explicitly specified.
    114      * @param charset The charset
    115      */
    116     public static void setContentCharset(final HttpParams params, final String charset) {
    117         if (params == null) {
    118             throw new IllegalArgumentException("HTTP parameters may not be null");
    119         }
    120         params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, charset);
    121     }
    122 
    123     /**
    124      * Returns {@link ProtocolVersion protocol version} to be used per default.
    125      *
    126      * @return {@link ProtocolVersion protocol version}
    127      */
    128     public static ProtocolVersion getVersion(final HttpParams params) {
    129         if (params == null) {
    130             throw new IllegalArgumentException("HTTP parameters may not be null");
    131         }
    132         Object param = params.getParameter
    133             (CoreProtocolPNames.PROTOCOL_VERSION);
    134         if (param == null) {
    135             return HttpVersion.HTTP_1_1;
    136         }
    137         return (ProtocolVersion)param;
    138     }
    139 
    140     /**
    141      * Assigns the {@link ProtocolVersion protocol version} to be used by the
    142      * HTTP methods that this collection of parameters applies to.
    143      *
    144      * @param version the {@link ProtocolVersion protocol version}
    145      */
    146     public static void setVersion(final HttpParams params, final ProtocolVersion version) {
    147         if (params == null) {
    148             throw new IllegalArgumentException("HTTP parameters may not be null");
    149         }
    150         params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, version);
    151     }
    152 
    153     public static String getUserAgent(final HttpParams params) {
    154         if (params == null) {
    155             throw new IllegalArgumentException("HTTP parameters may not be null");
    156         }
    157         return (String) params.getParameter(CoreProtocolPNames.USER_AGENT);
    158     }
    159 
    160     public static void setUserAgent(final HttpParams params, final String useragent) {
    161         if (params == null) {
    162             throw new IllegalArgumentException("HTTP parameters may not be null");
    163         }
    164         params.setParameter(CoreProtocolPNames.USER_AGENT, useragent);
    165     }
    166 
    167     public static boolean useExpectContinue(final HttpParams params) {
    168         if (params == null) {
    169             throw new IllegalArgumentException("HTTP parameters may not be null");
    170         }
    171         return params.getBooleanParameter
    172             (CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    173     }
    174 
    175     public static void setUseExpectContinue(final HttpParams params, boolean b) {
    176         if (params == null) {
    177             throw new IllegalArgumentException("HTTP parameters may not be null");
    178         }
    179         params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, b);
    180     }
    181 }
    182