001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/message/BasicHeader.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.Header;
035: import org.apache.http.HeaderElement;
036: import org.apache.http.ParseException;
037:
038: /**
039: * Represents an HTTP header field.
040: *
041: * <p>The HTTP header fields follow the same generic format as
042: * that given in Section 3.1 of RFC 822. Each header field consists
043: * of a name followed by a colon (":") and the field value. Field names
044: * are case-insensitive. The field value MAY be preceded by any amount
045: * of LWS, though a single SP is preferred.
046: *
047: *<pre>
048: * message-header = field-name ":" [ field-value ]
049: * field-name = token
050: * field-value = *( field-content | LWS )
051: * field-content = <the OCTETs making up the field-value
052: * and consisting of either *TEXT or combinations
053: * of token, separators, and quoted-string>
054: *</pre>
055: *
056: * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
057: * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
058: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
059: *
060: *
061: * <!-- empty lines above to avoid 'svn diff' context problems -->
062: * @version $Revision: 604625 $ $Date: 2007-12-16 15:11:11 +0100 (Sun, 16 Dec 2007) $
063: *
064: * @since 4.0
065: */
066: public class BasicHeader implements Header, Cloneable {
067:
068: /**
069: * Header name.
070: */
071: private final String name;
072:
073: /**
074: * Header value.
075: */
076: private final String value;
077:
078: /**
079: * Constructor with name and value
080: *
081: * @param name the header name
082: * @param value the header value
083: */
084: public BasicHeader(final String name, final String value) {
085: super ();
086: if (name == null) {
087: throw new IllegalArgumentException("Name may not be null");
088: }
089: this .name = name;
090: this .value = value;
091: }
092:
093: /**
094: * Returns the header name.
095: *
096: * @return String name The name
097: */
098: public String getName() {
099: return this .name;
100: }
101:
102: /**
103: * Returns the header value.
104: *
105: * @return String value The current value.
106: */
107: public String getValue() {
108: return this .value;
109: }
110:
111: /**
112: * Returns a {@link String} representation of the header.
113: *
114: * @return a string
115: */
116: public String toString() {
117: // no need for non-default formatting in toString()
118: return BasicLineFormatter.DEFAULT.formatHeader(null, this )
119: .toString();
120: }
121:
122: /**
123: * Returns an array of {@link HeaderElement}s constructed from my value.
124: *
125: * @see BasicHeaderValueParser#parseElements
126: *
127: * @return an array of header elements
128: *
129: * @throws ParseException in case of a parse error
130: */
131: public HeaderElement[] getElements() throws ParseException {
132: if (this .value != null) {
133: // result intentionally not cached, it's probably not used again
134: return BasicHeaderValueParser.parseElements(this .value,
135: null);
136: } else {
137: return new HeaderElement[] {};
138: }
139: }
140:
141: public Object clone() throws CloneNotSupportedException {
142: return super.clone();
143: }
144:
145: }
|