Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
28 package ch.boye.httpclientandroidlib.params;
30 import ch.boye.httpclientandroidlib.HttpVersion;
31 import ch.boye.httpclientandroidlib.ProtocolVersion;
32 import ch.boye.httpclientandroidlib.protocol.HTTP;
34 /**
35 * Utility class for accessing protocol parameters in {@link HttpParams}.
36 *
37 * @since 4.0
38 *
39 * @see CoreProtocolPNames
40 */
41 public final class HttpProtocolParams implements CoreProtocolPNames {
43 private HttpProtocolParams() {
44 super();
45 }
47 /**
48 * Obtains value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter.
49 * If not set, defaults to <code>US-ASCII</code>.
50 *
51 * @param params HTTP parameters.
52 * @return HTTP element charset.
53 */
54 public static String getHttpElementCharset(final HttpParams params) {
55 if (params == null) {
56 throw new IllegalArgumentException("HTTP parameters may not be null");
57 }
58 String charset = (String) params.getParameter
59 (CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
60 if (charset == null) {
61 charset = HTTP.DEFAULT_PROTOCOL_CHARSET;
62 }
63 return charset;
64 }
66 /**
67 * Sets value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter.
68 *
69 * @param params HTTP parameters.
70 * @param charset HTTP element charset.
71 */
72 public static void setHttpElementCharset(final HttpParams params, final String charset) {
73 if (params == null) {
74 throw new IllegalArgumentException("HTTP parameters may not be null");
75 }
76 params.setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, charset);
77 }
79 /**
80 * Obtains value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter.
81 * If not set, defaults to <code>ISO-8859-1</code>.
82 *
83 * @param params HTTP parameters.
84 * @return HTTP content charset.
85 */
86 public static String getContentCharset(final HttpParams params) {
87 if (params == null) {
88 throw new IllegalArgumentException("HTTP parameters may not be null");
89 }
90 String charset = (String) params.getParameter
91 (CoreProtocolPNames.HTTP_CONTENT_CHARSET);
92 if (charset == null) {
93 charset = HTTP.DEFAULT_CONTENT_CHARSET;
94 }
95 return charset;
96 }
98 /**
99 * Sets value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter.
100 *
101 * @param params HTTP parameters.
102 * @param charset HTTP content charset.
103 */
104 public static void setContentCharset(final HttpParams params, final String charset) {
105 if (params == null) {
106 throw new IllegalArgumentException("HTTP parameters may not be null");
107 }
108 params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, charset);
109 }
111 /**
112 * Obtains value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter.
113 * If not set, defaults to {@link HttpVersion#HTTP_1_1}.
114 *
115 * @param params HTTP parameters.
116 * @return HTTP protocol version.
117 */
118 public static ProtocolVersion getVersion(final HttpParams params) {
119 if (params == null) {
120 throw new IllegalArgumentException("HTTP parameters may not be null");
121 }
122 Object param = params.getParameter
123 (CoreProtocolPNames.PROTOCOL_VERSION);
124 if (param == null) {
125 return HttpVersion.HTTP_1_1;
126 }
127 return (ProtocolVersion)param;
128 }
130 /**
131 * Sets value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter.
132 *
133 * @param params HTTP parameters.
134 * @param version HTTP protocol version.
135 */
136 public static void setVersion(final HttpParams params, final ProtocolVersion version) {
137 if (params == null) {
138 throw new IllegalArgumentException("HTTP parameters may not be null");
139 }
140 params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, version);
141 }
143 /**
144 * Obtains value of the {@link CoreProtocolPNames#USER_AGENT} parameter.
145 * If not set, returns <code>null</code>.
146 *
147 * @param params HTTP parameters.
148 * @return User agent string.
149 */
150 public static String getUserAgent(final HttpParams params) {
151 if (params == null) {
152 throw new IllegalArgumentException("HTTP parameters may not be null");
153 }
154 return (String) params.getParameter(CoreProtocolPNames.USER_AGENT);
155 }
157 /**
158 * Sets value of the {@link CoreProtocolPNames#USER_AGENT} parameter.
159 *
160 * @param params HTTP parameters.
161 * @param useragent User agent string.
162 */
163 public static void setUserAgent(final HttpParams params, final String useragent) {
164 if (params == null) {
165 throw new IllegalArgumentException("HTTP parameters may not be null");
166 }
167 params.setParameter(CoreProtocolPNames.USER_AGENT, useragent);
168 }
170 /**
171 * Obtains value of the {@link CoreProtocolPNames#USE_EXPECT_CONTINUE} parameter.
172 * If not set, returns <code>false</code>.
173 *
174 * @param params HTTP parameters.
175 * @return User agent string.
176 */
177 public static boolean useExpectContinue(final HttpParams params) {
178 if (params == null) {
179 throw new IllegalArgumentException("HTTP parameters may not be null");
180 }
181 return params.getBooleanParameter
182 (CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
183 }
185 /**
186 * Sets value of the {@link CoreProtocolPNames#USE_EXPECT_CONTINUE} parameter.
187 *
188 * @param params HTTP parameters.
189 * @param b expect-continue flag.
190 */
191 public static void setUseExpectContinue(final HttpParams params, boolean b) {
192 if (params == null) {
193 throw new IllegalArgumentException("HTTP parameters may not be null");
194 }
195 params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, b);
196 }
198 }