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 package gov.nist.javax.sip.address; 27 28 import gov.nist.core.NameValueList; 29 30 import java.text.ParseException; 31 import java.util.Iterator; 32 33 /** 34 * Implementation of the TelURL interface. 35 * 36 * @version 1.2 $Revision: 1.10 $ $Date: 2009/11/15 19:50:45 $ 37 * 38 * @author M. Ranganathan 39 * 40 */ 41 public class TelURLImpl 42 extends GenericURI 43 implements javax.sip.address.TelURL { 44 45 46 private static final long serialVersionUID = 5873527320305915954L; 47 48 protected TelephoneNumber telephoneNumber; 49 50 /** Creates a new instance of TelURLImpl */ 51 public TelURLImpl() { 52 this.scheme = "tel"; 53 } 54 55 /** Set the telephone number. 56 *@param telephoneNumber -- telephone number to set. 57 */ 58 59 public void setTelephoneNumber(TelephoneNumber telephoneNumber) { 60 this.telephoneNumber = telephoneNumber; 61 } 62 63 /** Returns the value of the <code>isdnSubAddress</code> parameter, or null 64 * if it is not set. 65 * 66 * @return the value of the <code>isdnSubAddress</code> parameter 67 */ 68 public String getIsdnSubAddress() { 69 return telephoneNumber.getIsdnSubaddress(); 70 } 71 72 /** Returns the value of the <code>postDial</code> parameter, or null if it 73 * is not set. 74 * 75 * @return the value of the <code>postDial</code> parameter 76 */ 77 public String getPostDial() { 78 return telephoneNumber.getPostDial(); 79 } 80 81 /** Returns the value of the "scheme" of this URI, for example "sip", "sips" 82 * or "tel". 83 * 84 * @return the scheme paramter of the URI 85 */ 86 public String getScheme() { 87 return this.scheme; 88 } 89 90 /** Returns <code>true</code> if this TelURL is global i.e. if the TelURI 91 * has a global phone user. 92 * 93 * @return <code>true</code> if this TelURL represents a global phone user, 94 * and <code>false</code> otherwise. 95 */ 96 public boolean isGlobal() { 97 return telephoneNumber.isGlobal(); 98 } 99 100 /** This method determines if this is a URI with a scheme of "sip" or "sips". 101 * 102 * @return true if the scheme is "sip" or "sips", false otherwise. 103 */ 104 public boolean isSipURI() { 105 return false; 106 } 107 108 /** Sets phone user of this TelURL to be either global or local. The default 109 * value is false, hence the TelURL is defaulted to local. 110 * 111 * @param global - the boolean value indicating if the TelURL has a global 112 * phone user. 113 */ 114 public void setGlobal(boolean global) { 115 this.telephoneNumber.setGlobal(global); 116 } 117 118 /** Sets ISDN subaddress of this TelURL. If a subaddress is present, it is 119 * appended to the phone number after ";isub=". 120 * 121 * @param isdnSubAddress - new value of the <code>isdnSubAddress</code> 122 * parameter 123 */ 124 public void setIsdnSubAddress(String isdnSubAddress) { 125 this.telephoneNumber.setIsdnSubaddress(isdnSubAddress); 126 } 127 128 /** Sets post dial of this TelURL. The post-dial sequence describes what and 129 * when the local entity should send to the phone line. 130 * 131 * @param postDial - new value of the <code>postDial</code> parameter 132 */ 133 public void setPostDial(String postDial) { 134 this.telephoneNumber.setPostDial(postDial); 135 } 136 137 /** 138 * Set the telephone number. 139 * @param telephoneNumber long phone number to set. 140 */ 141 public void setPhoneNumber(String telephoneNumber) { 142 this.telephoneNumber.setPhoneNumber(telephoneNumber); 143 } 144 145 /** Get the telephone number. 146 * 147 *@return -- the telephone number. 148 */ 149 public String getPhoneNumber() { 150 return this.telephoneNumber.getPhoneNumber(); 151 } 152 153 /** Return the string encoding. 154 * 155 *@return -- the string encoding. 156 */ 157 public String toString() { 158 return this.scheme + ":" + telephoneNumber.encode(); 159 } 160 161 public String encode() { 162 return encode(new StringBuffer()).toString(); 163 } 164 165 public StringBuffer encode(StringBuffer buffer) { 166 buffer.append(this.scheme).append(':'); 167 telephoneNumber.encode(buffer); 168 return buffer; 169 } 170 171 /** Deep copy clone operation. 172 * 173 *@return -- a cloned version of this telephone number. 174 */ 175 public Object clone() { 176 TelURLImpl retval = (TelURLImpl) super.clone(); 177 if (this.telephoneNumber != null) 178 retval.telephoneNumber = (TelephoneNumber) this.telephoneNumber.clone(); 179 return retval; 180 } 181 182 public String getParameter(String parameterName) { 183 return telephoneNumber.getParameter(parameterName); 184 } 185 186 public void setParameter(String name, String value) { 187 telephoneNumber.setParameter(name, value); 188 } 189 190 public Iterator<String> getParameterNames() { 191 return telephoneNumber.getParameterNames(); 192 } 193 194 public NameValueList getParameters() { 195 return telephoneNumber.getParameters(); 196 } 197 198 public void removeParameter(String name) { 199 telephoneNumber.removeParameter(name); 200 } 201 202 /* (non-Javadoc) 203 * @see javax.sip.address.TelURL#setPhoneContext(java.lang.String) 204 */ 205 public void setPhoneContext(String phoneContext) throws ParseException { 206 207 // JvB: set (null) should be interpreted as 'remove' 208 if (phoneContext==null) { 209 this.removeParameter("phone-context"); 210 } else { 211 this.setParameter("phone-context",phoneContext); 212 } 213 } 214 215 /* (non-Javadoc) 216 * @see javax.sip.address.TelURL#getPhoneContext() 217 */ 218 public String getPhoneContext() { 219 220 return this.getParameter("phone-context"); 221 } 222 } 223