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 import java.text.ParseException;
28 
29 import javax.sip.address.URI;
30 
31 /**
32  * Implementation of the URI class. This relies on the 1.4 URI class.
33  *
34  * @author M. Ranganathan   <br/>
35  * @version 1.2 $Revision: 1.10 $ $Date: 2009/11/15 19:50:45 $
36  *
37  *
38  */
39 public class GenericURI extends NetObject implements javax.sip.address.URI {
40     /**
41      *
42      */
43     private static final long serialVersionUID = 3237685256878068790L;
44     public static final String SIP = ParameterNames.SIP_URI_SCHEME;
45     public static final String SIPS = ParameterNames.SIPS_URI_SCHEME;
46     public static final String TEL = ParameterNames.TEL_URI_SCHEME;
47     public static final String POSTDIAL = ParameterNames.POSTDIAL;
48     public static final String PHONE_CONTEXT_TAG =
49         ParameterNames.PHONE_CONTEXT_TAG;
50     public static final String ISUB = ParameterNames.ISUB;
51     public static final String PROVIDER_TAG = ParameterNames.PROVIDER_TAG;
52 
53     /** Imbedded URI
54      */
55     protected String uriString;
56 
57     /**
58      * The URI Scheme.
59      */
60     protected String scheme;
61 
62     /** Consturctor
63      */
GenericURI()64     protected GenericURI() {
65     }
66 
67     /** Constructor given the URI string
68      * @param uriString The imbedded URI string.
69      * @throws java.net.URISyntaxException When there is a syntaz error in the imbedded URI.
70      */
GenericURI(String uriString)71     public GenericURI(String uriString) throws ParseException {
72         try {
73             this.uriString = uriString;
74             int i = uriString.indexOf(":");
75             scheme = uriString.substring(0, i);
76         } catch (Exception e) {
77             throw new ParseException("GenericURI, Bad URI format", 0);
78         }
79     }
80 
81     /** Encode the URI.
82      * @return The encoded URI
83      */
encode()84     public String encode() {
85         return uriString;
86     }
87 
encode(StringBuffer buffer)88     public StringBuffer encode(StringBuffer buffer) {
89         return buffer.append(uriString);
90     }
91 
92     /** Encode this URI.
93      * @return The encoded URI
94      */
toString()95     public String toString() {
96         return this.encode();
97 
98     }
99 
100     /** Returns the value of the "scheme" of
101      * this URI, for example "sip", "sips" or "tel".
102      *
103      * @return the scheme paramter of the URI
104      */
getScheme()105     public String getScheme() {
106         return scheme;
107     }
108 
109     /** This method determines if this is a URI with a scheme of
110      * "sip" or "sips".
111      *
112      * @return true if the scheme is "sip" or "sips", false otherwise.
113      */
isSipURI()114     public boolean isSipURI() {
115         return this instanceof SipUri;
116     }
117 
118     // @Override
equals(Object that)119     public boolean equals(Object that) {
120         if (this==that) return true;
121         else if (that instanceof URI) {
122             final URI o = (URI) that;
123 
124             // This is not sufficient for equality; revert to String equality...
125             // return this.getScheme().equalsIgnoreCase( o.getScheme() )
126             return this.toString().equalsIgnoreCase( o.toString() );
127         }
128         return false;
129     }
130 
hashCode()131     public int hashCode() {
132         return this.toString().hashCode();
133     }
134 }
135