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