Source Code Cross Referenced for BasicHeaderElement.java in  » Net » httpcomponents-core-4.0-beta1 » org » apache » http » message » 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 » httpcomponents core 4.0 beta1 » org.apache.http.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/message/BasicHeaderElement.java $
003:         * $Revision: 604625 $
004:         * $Date: 2007-12-16 15:11:11 +0100 (Sun, 16 Dec 2007) $
005:         *
006:         * ====================================================================
007:         * Licensed to the Apache Software Foundation (ASF) under one
008:         * or more contributor license agreements.  See the NOTICE file
009:         * distributed with this work for additional information
010:         * regarding copyright ownership.  The ASF licenses this file
011:         * to you under the Apache License, Version 2.0 (the
012:         * "License"); you may not use this file except in compliance
013:         * with 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,
018:         * software distributed under the License is distributed on an
019:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020:         * KIND, either express or implied.  See the License for the
021:         * specific language governing permissions and limitations
022:         * under the License.
023:         * ====================================================================
024:         *
025:         * This software consists of voluntary contributions made by many
026:         * individuals on behalf of the Apache Software Foundation.  For more
027:         * information on the Apache Software Foundation, please see
028:         * <http://www.apache.org/>.
029:         *
030:         */
031:
032:        package org.apache.http.message;
033:
034:        import org.apache.http.HeaderElement;
035:        import org.apache.http.NameValuePair;
036:        import org.apache.http.util.CharArrayBuffer;
037:        import org.apache.http.util.LangUtils;
038:
039:        /**
040:         * One element of an HTTP header's value.
041:         * <p>
042:         * Some HTTP headers (such as the set-cookie header) have values that
043:         * can be decomposed into multiple elements.  Such headers must be in the
044:         * following form:
045:         * </p>
046:         * <pre>
047:         * header  = [ element ] *( "," [ element ] )
048:         * element = name [ "=" [ value ] ] *( ";" [ param ] )
049:         * param   = name [ "=" [ value ] ]
050:         *
051:         * name    = token
052:         * value   = ( token | quoted-string )
053:         *
054:         * token         = 1*&lt;any char except "=", ",", ";", &lt;"&gt; and
055:         *                       white space&gt;
056:         * quoted-string = &lt;"&gt; *( text | quoted-char ) &lt;"&gt;
057:         * text          = any char except &lt;"&gt;
058:         * quoted-char   = "\" char
059:         * </pre>
060:         * <p>
061:         * Any amount of white space is allowed between any part of the
062:         * header, element or param and is ignored. A missing value in any
063:         * element or param will be stored as the empty {@link String};
064:         * if the "=" is also missing <var>null</var> will be stored instead.
065:         * </p>
066:         * <p>
067:         * This class represents an individual header element, containing
068:         * both a name/value pair (value may be <tt>null</tt>) and optionally
069:         * a set of additional parameters.
070:         * </p>
071:         *
072:         * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
073:         * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>
074:         * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
075:         * @author <a href="mailto:oleg at ural.com">Oleg Kalnichevski</a>
076:         *
077:         *
078:         * <!-- empty lines above to avoid 'svn diff' context problems -->
079:         * @version $Revision: 604625 $ $Date: 2007-12-16 15:11:11 +0100 (Sun, 16 Dec 2007) $
080:         * 
081:         * @since 4.0
082:         */
083:        public class BasicHeaderElement implements  HeaderElement, Cloneable {
084:
085:            private final String name;
086:            private final String value;
087:            private final NameValuePair[] parameters;
088:
089:            /**
090:             * Constructor with name, value and parameters.
091:             *
092:             * @param name header element name
093:             * @param value header element value. May be <tt>null</tt>
094:             * @param parameters header element parameters. May be <tt>null</tt>.
095:             *   Parameters are copied by reference, not by value
096:             */
097:            public BasicHeaderElement(final String name, final String value,
098:                    final NameValuePair[] parameters) {
099:                super ();
100:                if (name == null) {
101:                    throw new IllegalArgumentException("Name may not be null");
102:                }
103:                this .name = name;
104:                this .value = value;
105:                if (parameters != null) {
106:                    this .parameters = parameters;
107:                } else {
108:                    this .parameters = new NameValuePair[] {};
109:                }
110:            }
111:
112:            /**
113:             * Constructor with name and value.
114:             * 
115:             * @param name header element name
116:             * @param value header element value. May be <tt>null</tt>
117:             */
118:            public BasicHeaderElement(final String name, final String value) {
119:                this (name, value, null);
120:            }
121:
122:            /**
123:             * Returns the name.
124:             *
125:             * @return String name The name
126:             */
127:            public String getName() {
128:                return this .name;
129:            }
130:
131:            /**
132:             * Returns the value.
133:             *
134:             * @return String value The current value.
135:             */
136:            public String getValue() {
137:                return this .value;
138:            }
139:
140:            /**
141:             * Get parameters, if any.
142:             * The returned array is created for each invocation and can
143:             * be modified by the caller without affecting this header element.
144:             *
145:             * @return parameters as an array of {@link NameValuePair}s
146:             */
147:            public NameValuePair[] getParameters() {
148:                return (NameValuePair[]) this .parameters.clone();
149:            }
150:
151:            /**
152:             * Obtains the number of parameters.
153:             *
154:             * @return  the number of parameters
155:             */
156:            public int getParameterCount() {
157:                return this .parameters.length;
158:            }
159:
160:            /**
161:             * Obtains the parameter with the given index.
162:             *
163:             * @param index     the index of the parameter, 0-based
164:             *
165:             * @return  the parameter with the given index
166:             */
167:            public NameValuePair getParameter(int index) {
168:                // ArrayIndexOutOfBoundsException is appropriate
169:                return this .parameters[index];
170:            }
171:
172:            /**
173:             * Returns parameter with the given name, if found. Otherwise null 
174:             * is returned
175:             *
176:             * @param name The name to search by.
177:             * @return NameValuePair parameter with the given name
178:             */
179:            public NameValuePair getParameterByName(final String name) {
180:                if (name == null) {
181:                    throw new IllegalArgumentException("Name may not be null");
182:                }
183:                NameValuePair found = null;
184:                for (int i = 0; i < this .parameters.length; i++) {
185:                    NameValuePair current = this .parameters[i];
186:                    if (current.getName().equalsIgnoreCase(name)) {
187:                        found = current;
188:                        break;
189:                    }
190:                }
191:                return found;
192:            }
193:
194:            public boolean equals(final Object object) {
195:                if (object == null)
196:                    return false;
197:                if (this  == object)
198:                    return true;
199:                if (object instanceof  HeaderElement) {
200:                    BasicHeaderElement that = (BasicHeaderElement) object;
201:                    return this .name.equals(that.name)
202:                            && LangUtils.equals(this .value, that.value)
203:                            && LangUtils.equals(this .parameters,
204:                                    that.parameters);
205:                } else {
206:                    return false;
207:                }
208:            }
209:
210:            public int hashCode() {
211:                int hash = LangUtils.HASH_SEED;
212:                hash = LangUtils.hashCode(hash, this .name);
213:                hash = LangUtils.hashCode(hash, this .value);
214:                for (int i = 0; i < this .parameters.length; i++) {
215:                    hash = LangUtils.hashCode(hash, this .parameters[i]);
216:                }
217:                return hash;
218:            }
219:
220:            public String toString() {
221:                CharArrayBuffer buffer = new CharArrayBuffer(64);
222:                buffer.append(this .name);
223:                if (this .value != null) {
224:                    buffer.append("=");
225:                    buffer.append(this .value);
226:                }
227:                for (int i = 0; i < this .parameters.length; i++) {
228:                    buffer.append("; ");
229:                    buffer.append(this .parameters[i]);
230:                }
231:                return buffer.toString();
232:            }
233:
234:            public Object clone() throws CloneNotSupportedException {
235:                // parameters array is considered immutable
236:                // no need to make a copy of it
237:                return super.clone();
238:            }
239:
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.