001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: package gov.nist.siplite.header;
026:
027: import gov.nist.core.*;
028:
029: /** Use this class when there is no parser for parsing the given header. */
030: public class ExtensionHeader extends ParametersHeader {
031: /** Extension header label. */
032: public static final String NAME = Header.EXTENSION;
033:
034: /** Class handle. */
035: public static Class clazz;
036:
037: /** Header field value, without parameters. */
038: protected String valueWithoutParam;
039:
040: static {
041: clazz = new ExtensionHeader().getClass();
042: }
043:
044: /**
045: * Default constructor for a generic header.
046: */
047: public ExtensionHeader() {
048: }
049:
050: /**
051: * Constructor given the name and value.
052: * @param hdrName is the header name.
053: * @param hdrValue is the header value.
054: * @param pureHeaderValue is the header value without parameters.
055: */
056: public ExtensionHeader(String hdrName, String hdrValue,
057: String pureHeaderValue) {
058: super (hdrName);
059: headerValue = hdrValue;
060: valueWithoutParam = pureHeaderValue;
061: }
062:
063: /**
064: * Sets the header value field.
065: * Overloads the function from the base class.
066: * @param value is the value field to set
067: */
068: public void setHeaderValue(String value) {
069: headerValue = value;
070: valueWithoutParam = value;
071: }
072:
073: /**
074: * Sets the value without parameters for a generic header.
075: * @param value the new value to be set
076: */
077: public void setValue(String value) {
078: valueWithoutParam = value;
079: }
080:
081: /**
082: * Sets the name for a generic header.
083: * @param name the new name to be set
084: */
085: public void setName(String name) {
086: headerName = name;
087: }
088:
089: /**
090: * Gets the parameter list for this extension header.
091: * @return name value list for extension header field
092: */
093: public NameValueList getParameters() {
094: return parameters;
095: }
096:
097: /**
098: * Encodes the body as a textstring.
099: * @return encoded string of body contents
100: */
101: public String encodeBody() {
102: if (parameters != null && !parameters.isEmpty()) {
103: if (valueWithoutParam.equals("")) {
104: return parameters.encode();
105: } else {
106: String separator = Header.isAuthorization(headerName) ? Separators.SP
107: : Separators.SEMICOLON;
108: return valueWithoutParam + separator
109: + parameters.encode();
110: }
111: } else {
112: return headerValue;
113: }
114: }
115:
116: /**
117: * Gets the value of the header without parameters.
118: * @return value of extension header field
119: */
120: public Object getValue() {
121: return valueWithoutParam;
122: }
123:
124: }
|