1 /* 2 * Conditions Of Use 3 * 4 * This software was developed by employees of the National Institute of 5 * Standards and Technology (NIST), an agency of the Federal Government. 6 * Pursuant to title 15 Untied States Code Section 105, works of NIST 7 * employees are not subject to copyright protection in the United States 8 * and are considered to be in the public domain. As a result, a formal 9 * license is not needed to use the software. 10 * 11 * This software is provided by NIST as a service and is expressly 12 * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED 13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF 14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT 15 * AND DATA ACCURACY. NIST does not warrant or make any representations 16 * regarding the use of the software or the results thereof, including but 17 * not limited to the correctness, accuracy, reliability or usefulness of 18 * the software. 19 * 20 * Permission to use this software is contingent upon your acceptance 21 * of the terms of this agreement 22 * 23 * . 24 * 25 */ 26 /******************************************************************************* 27 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * 28 *******************************************************************************/ 29 package gov.nist.javax.sip.header; 30 31 import java.util.*; 32 import java.text.ParseException; 33 import javax.sip.header.*; 34 35 /** 36 * the UserAgent SIPObject. 37 * 38 * @author Olivier Deruelle <br/> 39 * @version 1.2 $Revision: 1.8 $ $Date: 2009/07/17 18:57:40 $ 40 * 41 * 42 * 43 */ 44 public class UserAgent extends SIPHeader implements UserAgentHeader { 45 46 /** 47 * Comment for <code>serialVersionUID</code> 48 */ 49 private static final long serialVersionUID = 4561239179796364295L; 50 /** Product tokens. 51 */ 52 protected List productTokens; 53 54 /** 55 * Return canonical form. 56 * pmusgrave - put a space between products (preserves format of header) 57 * @return String 58 */ 59 private String encodeProduct() { 60 StringBuffer tokens = new StringBuffer(); 61 ListIterator it = productTokens.listIterator(); 62 63 while (it.hasNext()) { 64 tokens.append((String) it.next()); 65 66 } 67 return tokens.toString(); 68 } 69 70 /** set the productToken field 71 * @param pt String to set 72 */ 73 public void addProductToken(String pt) { 74 productTokens.add(pt); 75 } 76 77 /** 78 * Constructor. 79 */ 80 public UserAgent() { 81 super(NAME); 82 productTokens = new LinkedList(); 83 } 84 85 /** Encode only the body of this header. 86 *@return encoded value of the header. 87 */ 88 public String encodeBody() { 89 return encodeProduct(); 90 } 91 92 /** 93 * Returns the list value of the product parameter. 94 * 95 * @return the software of this UserAgentHeader 96 */ 97 public ListIterator getProduct() { 98 if (productTokens == null || productTokens.isEmpty()) 99 return null; 100 else 101 return productTokens.listIterator(); 102 } 103 104 /** 105 * Sets the product value of the UserAgentHeader. 106 * 107 * @param product - a List specifying the product value 108 * @throws ParseException which signals that an error has been reached 109 * unexpectedly while parsing the product value. 110 */ 111 public void setProduct(List product) throws ParseException { 112 if (product == null) 113 throw new NullPointerException( 114 "JAIN-SIP Exception, UserAgent, " 115 + "setProduct(), the " 116 + " product parameter is null"); 117 productTokens = product; 118 } 119 120 public Object clone() { 121 UserAgent retval = (UserAgent) super.clone(); 122 if (productTokens != null) 123 retval.productTokens = new LinkedList (productTokens); 124 return retval; 125 } 126 127 } 128 /* 129 * $Log: UserAgent.java,v $ 130 * Revision 1.8 2009/07/17 18:57:40 emcho 131 * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project. 132 * 133 * Revision 1.7 2008/07/30 14:36:06 mranga 134 * Issue number: 135 * Obtained from: 136 * Submitted by: mranga 137 * Reviewed by: mranga 138 * Fix minor issue in encoding of user-agent header. 139 * 140 * Revision 1.6 2006/10/12 11:57:55 pmusgrave 141 * Issue number: 79, 80 142 * Submitted by: pmusgrave (at) newheights.com 143 * Reviewed by: mranga 144 * 145 * Revision 1.5 2006/07/13 09:01:48 mranga 146 * Issue number: 147 * Obtained from: 148 * Submitted by: jeroen van bemmel 149 * Reviewed by: mranga 150 * Moved some changes from jain-sip-1.2 to java.net 151 * 152 * CVS: ---------------------------------------------------------------------- 153 * CVS: Issue number: 154 * CVS: If this change addresses one or more issues, 155 * CVS: then enter the issue number(s) here. 156 * CVS: Obtained from: 157 * CVS: If this change has been taken from another system, 158 * CVS: then name the system in this line, otherwise delete it. 159 * CVS: Submitted by: 160 * CVS: If this code has been contributed to the project by someone else; i.e., 161 * CVS: they sent us a patch or a set of diffs, then include their name/email 162 * CVS: address here. If this is your work then delete this line. 163 * CVS: Reviewed by: 164 * CVS: If we are doing pre-commit code reviews and someone else has 165 * CVS: reviewed your changes, include their name(s) here. 166 * CVS: If you have not had it reviewed then delete this line. 167 * 168 * Revision 1.3 2006/06/19 06:47:27 mranga 169 * javadoc fixups 170 * 171 * Revision 1.2 2006/06/16 15:26:28 mranga 172 * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak 173 * 174 * Revision 1.1.1.1 2005/10/04 17:12:35 mranga 175 * 176 * Import 177 * 178 * 179 * Revision 1.3 2005/04/16 20:38:51 dmuresan 180 * Canonical clone() implementations for the GenericObject and GenericObjectList hierarchies 181 * 182 * Revision 1.2 2004/01/22 13:26:30 sverker 183 * Issue number: 184 * Obtained from: 185 * Submitted by: sverker 186 * Reviewed by: mranga 187 * 188 * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags. 189 * 190 * CVS: ---------------------------------------------------------------------- 191 * CVS: Issue number: 192 * CVS: If this change addresses one or more issues, 193 * CVS: then enter the issue number(s) here. 194 * CVS: Obtained from: 195 * CVS: If this change has been taken from another system, 196 * CVS: then name the system in this line, otherwise delete it. 197 * CVS: Submitted by: 198 * CVS: If this code has been contributed to the project by someone else; i.e., 199 * CVS: they sent us a patch or a set of diffs, then include their name/email 200 * CVS: address here. If this is your work then delete this line. 201 * CVS: Reviewed by: 202 * CVS: If we are doing pre-commit code reviews and someone else has 203 * CVS: reviewed your changes, include their name(s) here. 204 * CVS: If you have not had it reviewed then delete this line. 205 * 206 */ 207