1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/message/AbstractHttpMessage.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,158 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * ==================================================================== 1.23 + * 1.24 + * This software consists of voluntary contributions made by many 1.25 + * individuals on behalf of the Apache Software Foundation. For more 1.26 + * information on the Apache Software Foundation, please see 1.27 + * <http://www.apache.org/>. 1.28 + * 1.29 + */ 1.30 + 1.31 +package ch.boye.httpclientandroidlib.message; 1.32 + 1.33 +import java.util.Iterator; 1.34 + 1.35 +import ch.boye.httpclientandroidlib.Header; 1.36 +import ch.boye.httpclientandroidlib.HeaderIterator; 1.37 +import ch.boye.httpclientandroidlib.HttpMessage; 1.38 +import ch.boye.httpclientandroidlib.params.HttpParams; 1.39 +import ch.boye.httpclientandroidlib.params.BasicHttpParams; 1.40 + 1.41 +/** 1.42 + * Basic implementation of {@link HttpMessage}. 1.43 + * 1.44 + * @since 4.0 1.45 + */ 1.46 +public abstract class AbstractHttpMessage implements HttpMessage { 1.47 + 1.48 + protected HeaderGroup headergroup; 1.49 + 1.50 + protected HttpParams params; 1.51 + 1.52 + protected AbstractHttpMessage(final HttpParams params) { 1.53 + super(); 1.54 + this.headergroup = new HeaderGroup(); 1.55 + this.params = params; 1.56 + } 1.57 + 1.58 + protected AbstractHttpMessage() { 1.59 + this(null); 1.60 + } 1.61 + 1.62 + // non-javadoc, see interface HttpMessage 1.63 + public boolean containsHeader(String name) { 1.64 + return this.headergroup.containsHeader(name); 1.65 + } 1.66 + 1.67 + // non-javadoc, see interface HttpMessage 1.68 + public Header[] getHeaders(final String name) { 1.69 + return this.headergroup.getHeaders(name); 1.70 + } 1.71 + 1.72 + // non-javadoc, see interface HttpMessage 1.73 + public Header getFirstHeader(final String name) { 1.74 + return this.headergroup.getFirstHeader(name); 1.75 + } 1.76 + 1.77 + // non-javadoc, see interface HttpMessage 1.78 + public Header getLastHeader(final String name) { 1.79 + return this.headergroup.getLastHeader(name); 1.80 + } 1.81 + 1.82 + // non-javadoc, see interface HttpMessage 1.83 + public Header[] getAllHeaders() { 1.84 + return this.headergroup.getAllHeaders(); 1.85 + } 1.86 + 1.87 + // non-javadoc, see interface HttpMessage 1.88 + public void addHeader(final Header header) { 1.89 + this.headergroup.addHeader(header); 1.90 + } 1.91 + 1.92 + // non-javadoc, see interface HttpMessage 1.93 + public void addHeader(final String name, final String value) { 1.94 + if (name == null) { 1.95 + throw new IllegalArgumentException("Header name may not be null"); 1.96 + } 1.97 + this.headergroup.addHeader(new BasicHeader(name, value)); 1.98 + } 1.99 + 1.100 + // non-javadoc, see interface HttpMessage 1.101 + public void setHeader(final Header header) { 1.102 + this.headergroup.updateHeader(header); 1.103 + } 1.104 + 1.105 + // non-javadoc, see interface HttpMessage 1.106 + public void setHeader(final String name, final String value) { 1.107 + if (name == null) { 1.108 + throw new IllegalArgumentException("Header name may not be null"); 1.109 + } 1.110 + this.headergroup.updateHeader(new BasicHeader(name, value)); 1.111 + } 1.112 + 1.113 + // non-javadoc, see interface HttpMessage 1.114 + public void setHeaders(final Header[] headers) { 1.115 + this.headergroup.setHeaders(headers); 1.116 + } 1.117 + 1.118 + // non-javadoc, see interface HttpMessage 1.119 + public void removeHeader(final Header header) { 1.120 + this.headergroup.removeHeader(header); 1.121 + } 1.122 + 1.123 + // non-javadoc, see interface HttpMessage 1.124 + public void removeHeaders(final String name) { 1.125 + if (name == null) { 1.126 + return; 1.127 + } 1.128 + for (Iterator i = this.headergroup.iterator(); i.hasNext(); ) { 1.129 + Header header = (Header) i.next(); 1.130 + if (name.equalsIgnoreCase(header.getName())) { 1.131 + i.remove(); 1.132 + } 1.133 + } 1.134 + } 1.135 + 1.136 + // non-javadoc, see interface HttpMessage 1.137 + public HeaderIterator headerIterator() { 1.138 + return this.headergroup.iterator(); 1.139 + } 1.140 + 1.141 + // non-javadoc, see interface HttpMessage 1.142 + public HeaderIterator headerIterator(String name) { 1.143 + return this.headergroup.iterator(name); 1.144 + } 1.145 + 1.146 + // non-javadoc, see interface HttpMessage 1.147 + public HttpParams getParams() { 1.148 + if (this.params == null) { 1.149 + this.params = new BasicHttpParams(); 1.150 + } 1.151 + return this.params; 1.152 + } 1.153 + 1.154 + // non-javadoc, see interface HttpMessage 1.155 + public void setParams(final HttpParams params) { 1.156 + if (params == null) { 1.157 + throw new IllegalArgumentException("HTTP parameters may not be null"); 1.158 + } 1.159 + this.params = params; 1.160 + } 1.161 +}