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: /*
026: */
027: package gov.nist.siplite.header;
028:
029: import gov.nist.siplite.address.*;
030: import gov.nist.core.*;
031:
032: /**
033: * Contact Item. There can be several (strung together in a ContactList).
034: *
035: *
036: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
037: *
038: */
039: public final class ContactHeader extends AddressParametersHeader {
040: /** Class handle. */
041: public static Class clazz;
042:
043: /** Contact header field label. */
044: public static final String NAME = Header.CONTACT;
045:
046: /** 'expires' parameter label. */
047: public static final String PARAM_EXPIRES = "expires";
048:
049: /** 'action' parameter label. */
050: public static final String PARAM_ACTION = "action";
051:
052: /** 'q' parameter label. */
053: public static final String PARAM_Q = "q";
054:
055: /**
056: * Static initializer.
057: */
058: static {
059: clazz = new ContactHeader().getClass();
060: }
061:
062: /**
063: * wildCardFlag field.
064: */
065: protected boolean wildCardFlag;
066:
067: /**
068: * comment field.
069: */
070: protected String comment;
071:
072: /**
073: * Default constructor.
074: */
075: public ContactHeader() {
076: super (CONTACT);
077: wildCardFlag = false;
078: }
079:
080: /**
081: * Encode this into a cannonical String.
082: * @return String
083: */
084: public String encodeBody() {
085: String encoding = "";
086:
087: if (wildCardFlag) {
088: return encoding + "*";
089: }
090:
091: if (address != null) {
092: // RFC 3261, p. 223, 228
093: // addr-spec = SIP-URI / SIPS-URI / absoluteURI
094: // SIP-URI = "sip:" [ userinfo ] hostport
095: // uri-parameters [ headers ]
096: encoding += address.encode();
097:
098: /*
099: if (address.getAddressType() == Address.NAME_ADDR) {
100: encoding += address.encode();
101: } else {
102: // Encoding in canonical form must have <> around address.
103: encoding += "<" + address.encode() + ">";
104: }
105: */
106: }
107:
108: encoding += encodeWithSep();
109:
110: if (comment != null) {
111: encoding += "(" + comment + ")";
112: }
113:
114: return encoding;
115: }
116:
117: /**
118: * get the WildCardFlag field
119: * @return boolean
120: */
121: public boolean getWildCardFlag() {
122: return wildCardFlag;
123: }
124:
125: /**
126: * get the Action field.
127: * @return String
128: */
129: public String getAction() {
130: return getParameter(PARAM_ACTION);
131: }
132:
133: /**
134: * get the address field.
135: * @return Address
136: */
137: public Object getValue() {
138: return address;
139: }
140:
141: /**
142: * get the comment field
143: * @return String
144: */
145: public String getComment() {
146: return comment;
147: }
148:
149: /**
150: * get Expires field
151: * @return String
152: */
153: public String getExpires() {
154: return getParameter(PARAM_EXPIRES);
155: }
156:
157: /**
158: * Set the expiry time in seconds.
159: * @param expires to set.
160: */
161: public void setExpires(String expires) {
162: setParameter(PARAM_EXPIRES, expires);
163: }
164:
165: /**
166: * Set the expiry time in seconds.
167: * @param expires to set.
168: */
169: public void setExpires(int expires) {
170: setParameter(PARAM_EXPIRES, new Integer(expires).toString());
171: }
172:
173: /**
174: * get the Q-value
175: * @return String
176: */
177: public String getQValue() {
178: return getParameter(PARAM_Q);
179: }
180:
181: /**
182: * Returns true if Q-value is present.
183: * @return true if this header has a Q-value, false otherwise.
184: */
185: public boolean hasQValue() {
186: return hasParameter(PARAM_Q);
187: }
188:
189: /**
190: * Sets the wildCardFlag member.
191: * @param w boolean to set
192: */
193: public void setWildCardFlag(boolean w) {
194: wildCardFlag = w;
195: }
196:
197: /**
198: * Sets the address member.
199: * @param newAddress Address to set
200: */
201: public void setAddress(Address newAddress) {
202: if (newAddress != null) {
203: address = newAddress;
204: }
205: }
206:
207: /**
208: * Sets the comment member.
209: * @param newComment String to set
210: */
211: public void setComment(String newComment) {
212: if (newComment != null) {
213: comment = newComment;
214: }
215: }
216:
217: /**
218: * Clone - do a deep copy.
219: * @return Object Contact
220: */
221: public Object clone() {
222: ContactHeader retval = new ContactHeader();
223: retval.wildCardFlag = this .wildCardFlag;
224: if (this .comment != null)
225: retval.comment = new String(this .comment);
226: if (this .parameters != null)
227: retval.parameters = (NameValueList) parameters.clone();
228: if (this .address != null)
229: retval.address = (Address) address.clone();
230: return retval;
231: }
232: }
|