1600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang/* 2600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Conditions Of Use 3600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 4600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* This software was developed by employees of the National Institute of 5600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Standards and Technology (NIST), an agency of the Federal Government. 6600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Pursuant to title 15 Untied States Code Section 105, works of NIST 7600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* employees are not subject to copyright protection in the United States 8600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* and are considered to be in the public domain. As a result, a formal 9600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* license is not needed to use the software. 10600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 11600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* This software is provided by NIST as a service and is expressly 12600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED 13600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF 14600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT 15600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* AND DATA ACCURACY. NIST does not warrant or make any representations 16600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* regarding the use of the software or the results thereof, including but 17600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* not limited to the correctness, accuracy, reliability or usefulness of 18600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* the software. 19600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 20600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Permission to use this software is contingent upon your acceptance 21600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* of the terms of this agreement 22600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 23600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* . 24600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* 25600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang*/ 26600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang/******************************************************************************* 27600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang* Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * 28600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang*******************************************************************************/ 29600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangpackage gov.nist.javax.sip.header; 30600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 31600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangimport javax.sip.InvalidArgumentException; 32600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 33600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang/** 34600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Accept header : The top level header is actually AcceptList which is a list of 35600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Accept headers. 36600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 37600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @version 1.2 $Revision: 1.9 $ $Date: 2009/07/17 18:57:24 $ 38600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 39600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @since 1.1 40600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 41600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @author M. Ranganathan <br/> 42600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 43600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 44600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * 45600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 46600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wangpublic final class Accept 47600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang extends ParametersHeader 48600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang implements javax.sip.header.AcceptHeader { 49600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 50600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 51600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Comment for <code>serialVersionUID</code> 52600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 53600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang private static final long serialVersionUID = -7866187924308658151L; 54600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 55600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** mediaRange field 56600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 57600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang protected MediaRange mediaRange; 58600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 59600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** default constructor 60600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 61600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public Accept() { 62600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang super(NAME); 63600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 64600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 65600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** returns true if this header allows all ContentTypes, 66600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * false otherwise. 67600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @return Boolean 68600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 69600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public boolean allowsAllContentTypes() { 70600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (mediaRange == null) 71600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return false; 72600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else 73600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return mediaRange.type.compareTo(STAR) == 0; 74600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 75600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 76600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 77600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * returns true if this header allows all ContentSubTypes, 78600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * false otherwise. 79600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @return boolean 80600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 81600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public boolean allowsAllContentSubTypes() { 82600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (mediaRange == null) { 83600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return false; 84600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } else 85600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return mediaRange.getSubtype().compareTo(STAR) == 0; 86600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 87600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 88600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** Encode the value of this header into cannonical form. 89600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *@return encoded value of the header as a string. 90600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 91600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang protected String encodeBody() { 92600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return encodeBody(new StringBuffer()).toString(); 93600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 94600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 95600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang protected StringBuffer encodeBody(StringBuffer buffer) { 96600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (mediaRange != null) 97600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang mediaRange.encode(buffer); 98600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (parameters != null && !parameters.isEmpty()) { 99600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang buffer.append(';'); 100600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang parameters.encode(buffer); 101600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 102600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return buffer; 103600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 104600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 105600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** get the MediaRange field 106600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @return MediaRange 107600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 108600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public MediaRange getMediaRange() { 109600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return mediaRange; 110600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 111600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 112600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** get the contentType field 113600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @return String 114600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 115600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String getContentType() { 116600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (mediaRange == null) 117600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return null; 118600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else 119600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return mediaRange.getType(); 120600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 121600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 122600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** get the ContentSubType fiels 123600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @return String 124600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 125600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public String getContentSubType() { 126600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (mediaRange == null) 127600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return null; 128600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang else 129600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return mediaRange.getSubtype(); 130600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 131600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 132600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 133600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Get the q value. 134600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @return float 135600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 136600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public float getQValue() { 137600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return getParameterAsFloat(ParameterNames.Q); 138600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 139600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 140600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 141600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Return true if the q value has been set. 142600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @return boolean 143600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 144600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public boolean hasQValue() { 145600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return super.hasParameter(ParameterNames.Q); 146600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 147600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 148600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 149600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 150600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang *Remove the q value. 151600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 152600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void removeQValue() { 153600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang super.removeParameter(ParameterNames.Q); 154600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 155600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 156600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** set the ContentSubType field 157600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param subtype String to set 158600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 159600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void setContentSubType(String subtype) { 160600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (mediaRange == null) 161600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang mediaRange = new MediaRange(); 162600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang mediaRange.setSubtype(subtype); 163600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 164600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 165600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** set the ContentType field 166600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param type String to set 167600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 168600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void setContentType(String type) { 169600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (mediaRange == null) 170600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang mediaRange = new MediaRange(); 171600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang mediaRange.setType(type); 172600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 173600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 174600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 175600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Set the q value 176600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param qValue float to set 177600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @throws IllegalArgumentException if qValue is <0.0 or >1.0 178600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 179600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void setQValue(float qValue) throws InvalidArgumentException { 180600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (qValue == -1) 181600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang super.removeParameter(ParameterNames.Q); 182600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang super.setParameter(ParameterNames.Q, qValue); 183600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 184600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 185600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 186600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang /** 187600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * Set the mediaRange member 188600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang * @param m MediaRange field 189600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang */ 190600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public void setMediaRange(MediaRange m) { 191600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang mediaRange = m; 192600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 193600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 194600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang public Object clone() { 195600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang Accept retval = (Accept) super.clone(); 196600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang if (this.mediaRange != null) 197600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang retval.mediaRange = (MediaRange) this.mediaRange.clone(); 198600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang return retval; 199600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang } 200600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang 201600c7a4bbc7348167293eac928192e695b4ad5baChung-yih Wang} 202