View Javadoc

1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/Header.java,v 1.17 2004/09/15 20:42:17 olegk Exp $
3    * $Revision: 155418 $
4    * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
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   */
29  
30  package org.apache.commons.httpclient;
31  
32  /***
33   * <p>An HTTP header.</p>
34   *
35   * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
36   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
37   * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
38   * @version $Revision: 155418 $ $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
39   */
40  public class Header extends NameValuePair {
41  
42      // ----------------------------------------------------------- Constructors
43  
44      /***
45       * Autogenerated header flag.
46       */
47      private boolean isAutogenerated = false;
48      
49      /***
50       * Default constructor.
51       */
52      public Header() {
53          this(null, null);
54      }
55  
56      /***
57       * Constructor with name and value
58       *
59       * @param name the header name
60       * @param value the header value
61       */
62      public Header(String name, String value) {
63          super(name, value);
64      }
65  
66      /***
67       * Constructor with name and value
68       *
69       * @param name the header name
70       * @param value the header value
71       * @param isAutogenerated <tt>true</tt> if the header is autogenerated,
72       *  <tt>false</tt> otherwise.
73       * 
74       * @since 3.0
75       */
76      public Header(String name, String value, boolean isAutogenerated) {
77          super(name, value);
78          this.isAutogenerated = isAutogenerated;
79      }
80  
81      // --------------------------------------------------------- Public Methods
82  
83      /***
84       * Returns a {@link String} representation of the header.
85       *
86       * @return stringHEAD
87       */
88      public String toExternalForm() {
89          return ((null == getName() ? "" : getName()) 
90              + ": " 
91              + (null == getValue() ? "" : getValue()) 
92              + "\r\n");
93      }
94  
95      /***
96       * Returns a {@link String} representation of the header.
97       *
98       * @return stringHEAD
99       */
100     public String toString() {
101         return toExternalForm();
102     }
103 
104     /***
105      * Returns an array of {@link HeaderElement}s
106      * constructed from my value.
107      *
108      * @see HeaderElement#parse
109      * @throws HttpException if the header cannot be parsed
110      * @return an array of header elements
111      * 
112      * @deprecated Use #getElements
113      */
114     public HeaderElement[] getValues() throws HttpException {
115         return HeaderElement.parse(getValue());
116     }
117 
118     /***
119      * Returns an array of {@link HeaderElement}s
120      * constructed from my value.
121      *
122      * @see HeaderElement#parseElements(String)
123      * 
124      * @return an array of header elements
125      * 
126      * @since 3.0
127      */
128     public HeaderElement[] getElements() {
129         return HeaderElement.parseElements(getValue());
130     }
131 
132     /***
133      * Returns the value of the auto-generated header flag.
134      * 
135      * @return <tt>true</tt> if the header is autogenerated,
136      *  <tt>false</tt> otherwise.
137      * 
138      * @since 3.0
139      */
140     public boolean isAutogenerated() {
141         return isAutogenerated;
142     }
143 
144 }