Source Code Cross Referenced for HeaderGroup.java in  » Net » Apache-common-HttpClient » org » apache » commons » httpclient » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache common HttpClient » org.apache.commons.httpclient 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/HeaderGroup.java,v 1.8 2004/05/13 04:03:25 mbecke Exp $
003:         * $Revision: 480424 $
004:         * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005:         *
006:         * ====================================================================
007:         *
008:         *  Licensed to the Apache Software Foundation (ASF) under one or more
009:         *  contributor license agreements.  See the NOTICE file distributed with
010:         *  this work for additional information regarding copyright ownership.
011:         *  The ASF licenses this file to You under the Apache License, Version 2.0
012:         *  (the "License"); you may not use this file except in compliance with
013:         *  the License.  You may obtain a copy of the License at
014:         *
015:         *      http://www.apache.org/licenses/LICENSE-2.0
016:         *
017:         *  Unless required by applicable law or agreed to in writing, software
018:         *  distributed under the License is distributed on an "AS IS" BASIS,
019:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020:         *  See the License for the specific language governing permissions and
021:         *  limitations under the License.
022:         * ====================================================================
023:         *
024:         * This software consists of voluntary contributions made by many
025:         * individuals on behalf of the Apache Software Foundation.  For more
026:         * information on the Apache Software Foundation, please see
027:         * <http://www.apache.org/>.
028:         *
029:         */
030:
031:        package org.apache.commons.httpclient;
032:
033:        import java.util.ArrayList;
034:        import java.util.Iterator;
035:        import java.util.List;
036:
037:        /**
038:         * A class for combining a set of headers.  This class allows for multiple
039:         * headers with the same name and keeps track of the order in which headers were
040:         * added.
041:         * 
042:         * @author Michael Becke
043:         * 
044:         * @since 2.0beta1
045:         */
046:        public class HeaderGroup {
047:
048:            /** The list of headers for this group, in the order in which they were added */
049:            private List headers;
050:
051:            /**
052:             * Constructor for HeaderGroup.
053:             */
054:            public HeaderGroup() {
055:                this .headers = new ArrayList();
056:            }
057:
058:            /**
059:             * Removes any contained headers.
060:             */
061:            public void clear() {
062:                headers.clear();
063:            }
064:
065:            /**
066:             * Adds the given header to the group.  The order in which this header was
067:             * added is preserved.
068:             * 
069:             * @param header the header to add
070:             */
071:            public void addHeader(Header header) {
072:                headers.add(header);
073:            }
074:
075:            /**
076:             * Removes the given header.
077:             *
078:             * @param header the header to remove
079:             */
080:            public void removeHeader(Header header) {
081:                headers.remove(header);
082:            }
083:
084:            /**
085:             * Sets all of the headers contained within this group overriding any
086:             * existing headers. The headers are added in the order in which they appear
087:             * in the array.
088:             * 
089:             * @param headers the headers to set
090:             */
091:            public void setHeaders(Header[] headers) {
092:                clear();
093:
094:                for (int i = 0; i < headers.length; i++) {
095:                    addHeader(headers[i]);
096:                }
097:            }
098:
099:            /**
100:             * Gets a header representing all of the header values with the given name.
101:             * If more that one header with the given name exists the values will be
102:             * combined with a "," as per RFC 2616.
103:             * 
104:             * <p>Header name comparison is case insensitive.
105:             * 
106:             * @param name the name of the header(s) to get
107:             * @return a header with a condensed value or <code>null</code> if no
108:             * headers by the given name are present
109:             */
110:            public Header getCondensedHeader(String name) {
111:                Header[] headers = getHeaders(name);
112:
113:                if (headers.length == 0) {
114:                    return null;
115:                } else if (headers.length == 1) {
116:                    return new Header(headers[0].getName(), headers[0]
117:                            .getValue());
118:                } else {
119:                    StringBuffer valueBuffer = new StringBuffer(headers[0]
120:                            .getValue());
121:
122:                    for (int i = 1; i < headers.length; i++) {
123:                        valueBuffer.append(", ");
124:                        valueBuffer.append(headers[i].getValue());
125:                    }
126:
127:                    return new Header(name.toLowerCase(), valueBuffer
128:                            .toString());
129:                }
130:            }
131:
132:            /**
133:             * Gets all of the headers with the given name.  The returned array
134:             * maintains the relative order in which the headers were added.  
135:             * 
136:             * <p>Header name comparison is case insensitive.
137:             * 
138:             * @param name the name of the header(s) to get
139:             * 
140:             * @return an array of length >= 0
141:             */
142:            public Header[] getHeaders(String name) {
143:                ArrayList headersFound = new ArrayList();
144:
145:                for (Iterator headerIter = headers.iterator(); headerIter
146:                        .hasNext();) {
147:                    Header header = (Header) headerIter.next();
148:                    if (header.getName().equalsIgnoreCase(name)) {
149:                        headersFound.add(header);
150:                    }
151:                }
152:
153:                return (Header[]) headersFound.toArray(new Header[headersFound
154:                        .size()]);
155:            }
156:
157:            /**
158:             * Gets the first header with the given name.
159:             * 
160:             * <p>Header name comparison is case insensitive.
161:             * 
162:             * @param name the name of the header to get
163:             * @return the first header or <code>null</code>
164:             */
165:            public Header getFirstHeader(String name) {
166:                for (Iterator headerIter = headers.iterator(); headerIter
167:                        .hasNext();) {
168:                    Header header = (Header) headerIter.next();
169:                    if (header.getName().equalsIgnoreCase(name)) {
170:                        return header;
171:                    }
172:                }
173:
174:                return null;
175:            }
176:
177:            /**
178:             * Gets the last header with the given name.
179:             *
180:             * <p>Header name comparison is case insensitive.
181:             *
182:             * @param name the name of the header to get
183:             * @return the last header or <code>null</code>
184:             */
185:            public Header getLastHeader(String name) {
186:                // start at the end of the list and work backwards
187:                for (int i = headers.size() - 1; i >= 0; i--) {
188:                    Header header = (Header) headers.get(i);
189:                    if (header.getName().equalsIgnoreCase(name)) {
190:                        return header;
191:                    }
192:                }
193:
194:                return null;
195:            }
196:
197:            /**
198:             * Gets all of the headers contained within this group.
199:             * 
200:             * @return an array of length >= 0
201:             */
202:            public Header[] getAllHeaders() {
203:                return (Header[]) headers.toArray(new Header[headers.size()]);
204:            }
205:
206:            /**
207:             * Tests if headers with the given name are contained within this group.
208:             * 
209:             * <p>Header name comparison is case insensitive.
210:             * 
211:             * @param name the header name to test for
212:             * @return <code>true</code> if at least one header with the name is
213:             * contained, <code>false</code> otherwise
214:             */
215:            public boolean containsHeader(String name) {
216:                for (Iterator headerIter = headers.iterator(); headerIter
217:                        .hasNext();) {
218:                    Header header = (Header) headerIter.next();
219:                    if (header.getName().equalsIgnoreCase(name)) {
220:                        return true;
221:                    }
222:                }
223:
224:                return false;
225:            }
226:
227:            /**
228:             * Returns an iterator over this group of headers.
229:             * 
230:             * @return iterator over this group of headers.
231:             * 
232:             * @since 3.0
233:             */
234:            public Iterator getIterator() {
235:                return this.headers.iterator();
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.