Class SipAddressUtil


  • public final class SipAddressUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      SipAddressUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String extractImeiFromAddress​(org.jainslee.resources.sip.Address address, javax.slee.facilities.Tracer tracer)
      Extract the IMEI from a SIP address if present
      static SipAddressString getAddressString​(java.lang.String digits)
      Extract an address string from a given string.
      static SipAddressString getAddressString​(org.jainslee.resources.sip.Address address)
      Extract an address string from an address header in a SIP message (such as From or To), or return null if this address is not a phone number
      static SipAddressString getAddressString​(org.jainslee.resources.sip.Address address, boolean forceSipUserEqualsPhone)
      Extract an address string from an address header in a SIP message (such as From or To), or return null if this address is not a phone number
      static SipAddressString getAddressString​(org.jainslee.resources.sip.URI uri)
      Extract an address string from a SIP URI, or return null if this URI is not a phone number
      static SipAddressString getAddressString​(org.jainslee.resources.sip.URI uri, boolean forceSipUserEqualsPhone)
      Extract an address string from a SIP URI, or return null if this URI is not a phone number
      static java.lang.String getDialString​(org.jainslee.resources.sip.URI uri)
      Extract the Dial String from a URI.
      static SipAddressString getDigits​(org.jainslee.resources.sip.URI uri)
      Extract an address string from a SIP or Tel URI, or return null if this URI is not a phone number.
      static java.lang.String getUserPartParameters​(org.jainslee.resources.sip.SipURI uri, boolean removePhoneContext)
      Gets any parameters with a SIP URI's user part optionally removing a phone-context parameter.
      static boolean isEquivalent​(org.jainslee.resources.sip.URI left, org.jainslee.resources.sip.URI right)
      Compare user part if both are tel URI or tel URI and SIP URI with user=phone; Otherwise compare user and host part
      static boolean isEquivalent​(org.jainslee.resources.sip.URI left, org.jainslee.resources.sip.URI right, boolean requireUserEqualsPhone)
      Compare user part if both are tel URI or tel URI and SIP URI (where the user-part is a phone number); Otherwise compare user and host part
      static boolean isPhoneNumber​(org.jainslee.resources.sip.SipURI uri)
      Test a SIP URI to see if it represents a phone number.
      static boolean isValidGlobalPhoneNumber​(java.lang.String digits)
      Checks that a digit string is a valid global phone number in accordance with RFC 2806.
      static boolean isValidLocalPhoneNumber​(java.lang.String digits)
      Checks that a digit string is a valid local phone number in accordance with RFC 2806.
      static java.lang.String percentDecodeHashChars​(java.lang.String dialstring)
      Decodes all instances of '%23' to the '#' character in the given dialstring.
      static java.lang.String percentEncodeHashChars​(java.lang.String dialstring)
      Encodes all instances of the '#' character to '%23' in the given dialstring.
      static org.jainslee.resources.sip.Address updateAddress​(org.jainslee.resources.sip.Address originalAddress, boolean international, java.lang.String newAddress)
      Updates a URI with a new address.
      static org.jainslee.resources.sip.Address updateAddress​(org.jainslee.resources.sip.Address originalAddress, SipAddressString extractedAddress, java.lang.String newAddress)
      Updates a URI with a new address.
      static org.jainslee.resources.sip.URI updateURI​(org.jainslee.resources.sip.URI originalURI, boolean international, java.lang.String newAddress)
      Updates a URI with a new address.
      static org.jainslee.resources.sip.URI updateURI​(org.jainslee.resources.sip.URI originalURI, SipAddressString extractedAddress, java.lang.String newAddress)
      Updates a URI with a new address.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SipAddressUtil

        public SipAddressUtil()
    • Method Detail

      • isPhoneNumber

        public static boolean isPhoneNumber​(org.jainslee.resources.sip.SipURI uri)
        Test a SIP URI to see if it represents a phone number.
        Parameters:
        uri - the SIP URI
        Returns:
        true, iff the user part of the SIP URI represents a phone number
      • getAddressString

        public static SipAddressString getAddressString​(org.jainslee.resources.sip.URI uri,
                                                        boolean forceSipUserEqualsPhone)
        Extract an address string from a SIP URI, or return null if this URI is not a phone number
        Parameters:
        uri - the URI
        forceSipUserEqualsPhone - force treating the URI user part as a potential phone number even when user=phone is not present
        Returns:
        a pair consisting of an (address string, true iff the address is international), or null if this URI is not a phone number
      • getAddressString

        public static SipAddressString getAddressString​(org.jainslee.resources.sip.Address address,
                                                        boolean forceSipUserEqualsPhone)
        Extract an address string from an address header in a SIP message (such as From or To), or return null if this address is not a phone number
        Parameters:
        address - the address
        forceSipUserEqualsPhone - force treating the URI user part as a potential phone number even when user=phone is not present
        Returns:
        a pair consisting of an (address string, true iff the address is international), or null if this Address is not a phone number
      • getAddressString

        public static SipAddressString getAddressString​(org.jainslee.resources.sip.Address address)
        Extract an address string from an address header in a SIP message (such as From or To), or return null if this address is not a phone number
        Parameters:
        address - the address
        Returns:
        a pair consisting of an (address string, true iff the address is international), or null if this Address is not a phone number
      • getAddressString

        public static SipAddressString getAddressString​(org.jainslee.resources.sip.URI uri)
        Extract an address string from a SIP URI, or return null if this URI is not a phone number
        Parameters:
        uri - the URI
        Returns:
        a pair consisting of an (address string, true iff the address is international), or null if this URI is not a phone number
      • getDigits

        public static SipAddressString getDigits​(org.jainslee.resources.sip.URI uri)
        Extract an address string from a SIP or Tel URI, or return null if this URI is not a phone number. Does not care about the presence or absence of certain URI parameters (e.g. user=phone), will try to get the digits regardless.
        Parameters:
        uri - the URI
        Returns:
        a pair consisting of an (address string, true iff the address is international), or null if this URI is not a phone number
      • getDialString

        public static java.lang.String getDialString​(org.jainslee.resources.sip.URI uri)
        Extract the Dial String from a URI. If the URI is a SIP URI return the user part, if the URI is a Tel URI return the phone number.
        Parameters:
        uri - the URI
        Returns:
        a string consisting of the user part of a SIP URI, the phone number of a Tel URI.
      • getAddressString

        public static SipAddressString getAddressString​(java.lang.String digits)
        Extract an address string from a given string. This will be a valid global or local phone number (RFC 2806) or otherwise null.
        Parameters:
        digits - string containing a potential phone number
        Returns:
        a pair consisting of an (address string, boolean representing whether address is international), or null if this string is not a phone number
      • updateURI

        public static org.jainslee.resources.sip.URI updateURI​(org.jainslee.resources.sip.URI originalURI,
                                                               boolean international,
                                                               java.lang.String newAddress)
        Updates a URI with a new address. Preserve the type of URI and whether the number is in international format.
        Parameters:
        originalURI - the received URI
        international - if the updated address is international
        newAddress - the new address to use
        Returns:
        updated URI
      • getUserPartParameters

        public static java.lang.String getUserPartParameters​(org.jainslee.resources.sip.SipURI uri,
                                                             boolean removePhoneContext)
        Gets any parameters with a SIP URI's user part optionally removing a phone-context parameter.
        Parameters:
        uri - the URI to extract parameters from
        removePhoneContext - whether to remove phone-context parameter if contained
        Returns:
        user part parameters or an empty string if there are none
      • updateURI

        public static org.jainslee.resources.sip.URI updateURI​(org.jainslee.resources.sip.URI originalURI,
                                                               SipAddressString extractedAddress,
                                                               java.lang.String newAddress)
        Updates a URI with a new address. Preserve the type of URI and whether the number is in international format.
        Parameters:
        originalURI - the received URI
        extractedAddress - the address extracted from the URI
        newAddress - the new address to use
        Returns:
        updated URI
      • updateAddress

        public static org.jainslee.resources.sip.Address updateAddress​(org.jainslee.resources.sip.Address originalAddress,
                                                                       boolean international,
                                                                       java.lang.String newAddress)
        Updates a URI with a new address. Preserve the type of URI and whether the number is in international format.
        Parameters:
        originalAddress - the received address
        international - if the updated address is international
        newAddress - the new address to use
        Returns:
        updated address
      • updateAddress

        public static org.jainslee.resources.sip.Address updateAddress​(org.jainslee.resources.sip.Address originalAddress,
                                                                       SipAddressString extractedAddress,
                                                                       java.lang.String newAddress)
        Updates a URI with a new address. Preserve the type of URI and whether the number is in international format.
        Parameters:
        originalAddress - the received address
        extractedAddress - the address extracted from the URI
        newAddress - the new address to use
        Returns:
        updated address
      • extractImeiFromAddress

        public static java.lang.String extractImeiFromAddress​(org.jainslee.resources.sip.Address address,
                                                              javax.slee.facilities.Tracer tracer)
        Extract the IMEI from a SIP address if present
        Parameters:
        address - the address to extract the imei from
        tracer - tracer
        Returns:
        extracted emei or null if not present
      • percentEncodeHashChars

        public static java.lang.String percentEncodeHashChars​(java.lang.String dialstring)
        Encodes all instances of the '#' character to '%23' in the given dialstring.
        Parameters:
        dialstring - The string to encode
        Returns:
        The dialstring with the '#' characters percent encoded, or null if the dialstring is null.
      • percentDecodeHashChars

        public static java.lang.String percentDecodeHashChars​(java.lang.String dialstring)
        Decodes all instances of '%23' to the '#' character in the given dialstring.
        Parameters:
        dialstring - The string to decode
        Returns:
        The dialstring with the '#' characters decoded, or null if the dialstring is null.
      • isEquivalent

        public static boolean isEquivalent​(org.jainslee.resources.sip.URI left,
                                           org.jainslee.resources.sip.URI right)
        Compare user part if both are tel URI or tel URI and SIP URI with user=phone; Otherwise compare user and host part
        Parameters:
        left - The first URI to compare
        right - The second URI to compare
        Returns:
        true if the URIs are equivalent
      • isEquivalent

        public static boolean isEquivalent​(org.jainslee.resources.sip.URI left,
                                           org.jainslee.resources.sip.URI right,
                                           boolean requireUserEqualsPhone)
        Compare user part if both are tel URI or tel URI and SIP URI (where the user-part is a phone number); Otherwise compare user and host part
        Parameters:
        left - The first URI to compare
        right - The second URI to compare
        requireUserEqualsPhone - if user=phone is required to treat sip URIs as phone numbers
        Returns:
        true if the URIs are equivalent
      • isValidGlobalPhoneNumber

        public static boolean isValidGlobalPhoneNumber​(java.lang.String digits)
        Checks that a digit string is a valid global phone number in accordance with RFC 2806.
        Parameters:
        digits - The digit string to check
        Returns:
        true if the digit string is a valid global phone number.
      • isValidLocalPhoneNumber

        public static boolean isValidLocalPhoneNumber​(java.lang.String digits)
        Checks that a digit string is a valid local phone number in accordance with RFC 2806.
        Parameters:
        digits - The digit string to check
        Returns:
        true if the digit string is a valid local phone number.