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 /** 32 * A generic extension header for the stack. 33 * The input text of the header gets recorded here. 34 * 35 * @version 1.2 $Revision: 1.5 $ $Date: 2009/07/17 18:57:30 $ 36 * @since 1.1 37 * 38 * @author M. Ranganathan <br/> 39 * 40 * 41 */ 42 public class ExtensionHeaderImpl 43 extends SIPHeader 44 implements javax.sip.header.ExtensionHeader { 45 46 /** 47 * Comment for <code>serialVersionUID</code> 48 */ 49 private static final long serialVersionUID = -8693922839612081849L; 50 51 protected String value; 52 53 /** 54 * This was added to allow for automatic cloning of headers. 55 */ 56 public ExtensionHeaderImpl() { 57 } 58 59 public ExtensionHeaderImpl(String headerName) { 60 super(headerName); 61 } 62 63 /** 64 * Set the name of the header. 65 * @param headerName is the name of the header to set. 66 */ 67 68 public void setName(String headerName) { 69 this.headerName = headerName; 70 } 71 72 /** 73 * Set the value of the header. 74 */ 75 public void setValue(String value) { 76 this.value = value; 77 } 78 79 /** 80 * Get the value of the extension header. 81 * @return the value of the extension header. 82 */ 83 public String getHeaderValue() { 84 if (this.value != null) { 85 return this.value; 86 } else { 87 String encodedHdr = null; 88 try { 89 // Bug fix submitted by Lamine Brahimi 90 encodedHdr = this.encode(); 91 } catch (Exception ex) { 92 return null; 93 } 94 StringBuffer buffer = new StringBuffer(encodedHdr); 95 while (buffer.length() > 0 && buffer.charAt(0) != ':') { 96 buffer.deleteCharAt(0); 97 } 98 buffer.deleteCharAt(0); 99 this.value = buffer.toString().trim(); 100 return this.value; 101 } 102 } 103 104 /** 105 * Return the canonical encoding of this header. 106 */ 107 public String encode() { 108 return new StringBuffer(this.headerName) 109 .append(COLON) 110 .append(SP) 111 .append(this.value) 112 .append(NEWLINE) 113 .toString(); 114 } 115 116 /** 117 * Return just the body of this header encoded (leaving out the 118 * name and the CRLF at the end). 119 */ 120 public String encodeBody() { 121 return this.getHeaderValue(); 122 } 123 } 124