KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > Header


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Header.java,v 1.10.2.3 2004/02/22 18:21:13 olegk Exp $
3  * $Revision: 1.10.2.3 $
4  * $Date: 2004/02/22 18:21:13 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ====================================================================
22  *
23  * This software consists of voluntary contributions made by many
24  * individuals on behalf of the Apache Software Foundation. For more
25  * information on the Apache Software Foundation, please see
26  * <http://www.apache.org/>.
27  *
28  * [Additional notices, if required by prior licensing conditions]
29  *
30  */

31
32 package org.apache.commons.httpclient;
33
34 /**
35  * <p>An HTTP header.</p>
36  *
37  * @author <a HREF="mailto:remm@apache.org">Remy Maucherat</a>
38  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
39  * @version $Revision: 1.10.2.3 $ $Date: 2004/02/22 18:21:13 $
40  */

41 public class Header extends NameValuePair {
42
43     // ----------------------------------------------------------- Constructors
44

45     /**
46      * Default constructor.
47      */

48     public Header() {
49         this(null, null);
50     }
51
52     /**
53      * Constructor with name and value
54      *
55      * @param name the header name
56      * @param value the header value
57      */

58     public Header(String JavaDoc name, String JavaDoc value) {
59         super(name, value);
60     }
61
62     // --------------------------------------------------------- Public Methods
63

64     /**
65      * Returns a {@link String} representation of the header in the form:
66      * <pre>
67      * Name: valueCRLF
68      * </pre>
69      * The string is terminated by CRLF.
70      *
71      * @return stringHEAD
72      */

73     public String JavaDoc toExternalForm() {
74         return ((null == getName() ? "" : getName())
75             + ": "
76             + (null == getValue() ? "" : getValue())
77             + "\r\n");
78     }
79
80     /**
81      * Returns a {@link String} representation of the header.
82      *
83      * @return stringHEAD
84      */

85     public String JavaDoc toString() {
86         return toExternalForm();
87     }
88
89     /**
90      * Returns an array of {@link HeaderElement}s
91      * constructed from my value.
92      *
93      * @see HeaderElement#parse
94      * @throws HttpException if the header cannot be parsed
95      * @return an array of header elements
96      */

97     public HeaderElement[] getValues() throws HttpException {
98         return HeaderElement.parse(getValue());
99     }
100
101 }
102
Popular Tags