Ejemplo n.º 1
0
        /**
         * Normalizes a phone number and indicates that operation's success/failure.
         * <br /><br />
         * Determines the country code dialing prefix through {@link com.skype.api.Skype#getIsoCountryInfo()}
         * by matching the default Locale country with an entry in the
         * {@link com.skype.api.Skype.GetIsoCountryInfoResponse#countryCodeList}.
         * Writes a message to the console indicating success/failure reason.
         *
         * @param pstn
         *  Phone number to normalize.
         *
         * @return
         *   The normalization result, which includes:
         *   <ul>
         *     <li>an Enum instance detailing success/failure reason.</li>
         *     <li>the normalized string (success) or error message string (failure)</li>
         *   </ul>
         *
         * @see com.skype.api.Skype#normalizePstnWithCountry(String, int)
         * @see com.skype.api.Skype#getIsoCountryInfo()
         *
         * @since 1.0
         */
        public static Skype.NormalizeIdentityResponse getNormalizationStr(String pstn)
        {
            Skype.NormalizeIdentityResponse nrmlResponseReturn = new com.skype.api.Skype.NormalizeIdentityResponse((mySession.mySkype));

            Skype.GetIsoCountryInfoResponse isoInfo = mySession.mySkype.getIsoCountryInfo();
            int    availCountryCodes = isoInfo.countryCodeList.Length;
            int    isoInfoIdx;
            String ourCountryCode = Locale.getDefault().getCountry();

            for (isoInfoIdx = 0; isoInfoIdx < availCountryCodes; isoInfoIdx++)
            {
                if (ourCountryCode.Equals(isoInfo.countryCodeList[isoInfoIdx], StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }
            }
            if (isoInfoIdx >= availCountryCodes)
            {
                nrmlResponseReturn.result     = Skype.NormalizeResult.IDENTITY_EMPTY; // Anything but IDENTITY_OK...
                nrmlResponseReturn.normalized = "Couldn't match Locale!";
                MySession.myConsole.printf("%s: Error! Couldn't match Locale %s in Skype.getIsoCountryInfo results%n",
                                           mySession.myTutorialTag, ourCountryCode);
                return(nrmlResponseReturn);
            }
            MySession.myConsole.printf("%n%s ISOInfo match (%d of %d):%n\tCode: %s%n\tDialExample: %s%n\tName: %s%n\tPrefix: %s%nLocale: %s%n%n",
                                       mySession.myTutorialTag, (isoInfoIdx + 1),
                                       mySession.mySkype.getIsoCountryInfo().countryCodeList.Length,
                                       mySession.mySkype.getIsoCountryInfo().countryCodeList[isoInfoIdx],
                                       mySession.mySkype.getIsoCountryInfo().countryDialExampleList[isoInfoIdx],
                                       mySession.mySkype.getIsoCountryInfo().countryNameList[isoInfoIdx],
                                       mySession.mySkype.getIsoCountryInfo().countryPrefixList[isoInfoIdx],
                                       Locale.getDefault().getCountry());

            Skype.NormalizePstnWithCountryResponse nrmlResponse =
                mySession.mySkype.normalizePstnWithCountry(pstn, isoInfo.countryPrefixList[isoInfoIdx]);

            if (nrmlResponse.result == Skype.NormalizeResult.IDENTITY_OK)
            {
                nrmlResponseReturn.normalized = nrmlResponse.normalized;
            }
            else if (nrmlResponse.result == Skype.NormalizeResult.IDENTITY_EMPTY)
            {
                nrmlResponseReturn.normalized = "Identity input was empty";
            }
            else if (nrmlResponse.result == Skype.NormalizeResult.IDENTITY_TOO_LONG)
            {
                nrmlResponseReturn.normalized = "Identity string too long";
            }
            else if (nrmlResponse.result == Skype.NormalizeResult.IDENTITY_CONTAINS_INVALID_CHAR)
            {
                nrmlResponseReturn.normalized = "Invalid character(s) found in identity string";
            }
            else if (nrmlResponse.result == Skype.NormalizeResult.PSTN_NUMBER_TOO_SHORT)
            {
                nrmlResponseReturn.normalized = "PSTN number too short";
            }
            else if (nrmlResponse.result == Skype.NormalizeResult.PSTN_NUMBER_HAS_INVALID_PREFIX)
            {
                nrmlResponseReturn.normalized = "Invalid character(s) found in PSTN prefix";
            }
            else if (nrmlResponse.result == Skype.NormalizeResult.SKYPENAME_STARTS_WITH_NONALPHA)
            {
                nrmlResponseReturn.normalized = "Skype Name string starts with non-alphanumeric character";
            }
            else if (nrmlResponse.result == Skype.NormalizeResult.SKYPENAME_SHORTER_THAN_6_CHARS)
            {
                nrmlResponseReturn.normalized = "Skype Name too short";
            }
            else
            {
                nrmlResponseReturn.normalized = "Cannot determine Skype.NORMALIZATION ?!?";
            }

            if (nrmlResponse.result != Skype.NormalizeResult.IDENTITY_OK)
            {
                MySession.myConsole.printf("%s: Error! Raw PSTN: %s - Normalized PSTN: %s.%n",
                                           mySession.myTutorialTag, pstn, nrmlResponseReturn.normalized);
            }
            else
            {
                MySession.myConsole.printf("%s: Raw PSTN: %s / Normalized PSTN: %s.%n",
                                           mySession.myTutorialTag, pstn, nrmlResponseReturn.normalized);
            }

            nrmlResponseReturn.result = nrmlResponse.result;
            return(nrmlResponseReturn);
        }
Ejemplo n.º 2
0
        /**
         * Normalizes a phone number and indicates that operation's success/failure.
         * <br /><br />
         * Determines the country code dialing prefix through {@link com.skype.api.Skype#getIsoCountryInfo()}
         * by matching the default Locale country with an entry in the
         * {@link com.skype.api.Skype.GetIsoCountryInfoResponse#countryCodeList}.
         * Writes a message to the console indicating success/failure reason.
         *
         * @param pstn
         * 	Phone number to normalize.
         *
         * @return
         *   The normalization result, which includes:
         *   <ul>
         *     <li>an Enum instance detailing success/failure reason.</li>
         *     <li>the normalized string (success) or error message string (failure)</li>
         *   </ul>
         *
         * @see com.skype.api.Skype#normalizePstnWithCountry(String, int)
         * @see com.skype.api.Skype#getIsoCountryInfo()
         *
         * @since 1.0
         */
        public static Skype.NormalizeIdentityResponse getNormalizationStr(String pstn)
        {
            Skype.NormalizeIdentityResponse nrmlResponseReturn = new com.skype.api.Skype.NormalizeIdentityResponse((mySession.mySkype));

            Skype.GetIsoCountryInfoResponse isoInfo = mySession.mySkype.getIsoCountryInfo();
            int availCountryCodes = isoInfo.countryCodeList.Length;
            int isoInfoIdx;
            String ourCountryCode = Locale.getDefault().getCountry();
            for (isoInfoIdx = 0; isoInfoIdx < availCountryCodes; isoInfoIdx++)
            {
                if (ourCountryCode.Equals(isoInfo.countryCodeList[isoInfoIdx], StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }
            }
            if (isoInfoIdx >= availCountryCodes)
            {
                nrmlResponseReturn.result = Skype.NormalizeResult.IDENTITY_EMPTY; // Anything but IDENTITY_OK...
                nrmlResponseReturn.normalized = "Couldn't match Locale!";
                MySession.myConsole.printf("%s: Error! Couldn't match Locale %s in Skype.getIsoCountryInfo results%n",
                        mySession.myTutorialTag, ourCountryCode);
                return (nrmlResponseReturn);
            }
            MySession.myConsole.printf("%n%s ISOInfo match (%d of %d):%n\tCode: %s%n\tDialExample: %s%n\tName: %s%n\tPrefix: %s%nLocale: %s%n%n",
                    mySession.myTutorialTag, (isoInfoIdx + 1),
                    mySession.mySkype.getIsoCountryInfo().countryCodeList.Length,
                    mySession.mySkype.getIsoCountryInfo().countryCodeList[isoInfoIdx],
                    mySession.mySkype.getIsoCountryInfo().countryDialExampleList[isoInfoIdx],
                    mySession.mySkype.getIsoCountryInfo().countryNameList[isoInfoIdx],
                    mySession.mySkype.getIsoCountryInfo().countryPrefixList[isoInfoIdx],
                    Locale.getDefault().getCountry());

            Skype.NormalizePstnWithCountryResponse nrmlResponse =
                mySession.mySkype.normalizePstnWithCountry(pstn, isoInfo.countryPrefixList[isoInfoIdx]);

            if (nrmlResponse.result == Skype.NormalizeResult.IDENTITY_OK)
                nrmlResponseReturn.normalized = nrmlResponse.normalized;
            else if (nrmlResponse.result == Skype.NormalizeResult.IDENTITY_EMPTY)
                nrmlResponseReturn.normalized = "Identity input was empty";
            else if (nrmlResponse.result == Skype.NormalizeResult.IDENTITY_TOO_LONG)
                nrmlResponseReturn.normalized = "Identity string too long";
            else if (nrmlResponse.result == Skype.NormalizeResult.IDENTITY_CONTAINS_INVALID_CHAR)
                nrmlResponseReturn.normalized = "Invalid character(s) found in identity string";
            else if (nrmlResponse.result == Skype.NormalizeResult.PSTN_NUMBER_TOO_SHORT)
                nrmlResponseReturn.normalized = "PSTN number too short";
            else if (nrmlResponse.result == Skype.NormalizeResult.PSTN_NUMBER_HAS_INVALID_PREFIX)
                nrmlResponseReturn.normalized = "Invalid character(s) found in PSTN prefix";
            else if (nrmlResponse.result == Skype.NormalizeResult.SKYPENAME_STARTS_WITH_NONALPHA)
                nrmlResponseReturn.normalized = "Skype Name string starts with non-alphanumeric character";
            else if (nrmlResponse.result == Skype.NormalizeResult.SKYPENAME_SHORTER_THAN_6_CHARS)
                nrmlResponseReturn.normalized = "Skype Name too short";
            else
                nrmlResponseReturn.normalized = "Cannot determine Skype.NORMALIZATION ?!?";

            if (nrmlResponse.result != Skype.NormalizeResult.IDENTITY_OK)
            {
                MySession.myConsole.printf("%s: Error! Raw PSTN: %s - Normalized PSTN: %s.%n",
                                        mySession.myTutorialTag, pstn, nrmlResponseReturn.normalized);
            }
            else
            {
                MySession.myConsole.printf("%s: Raw PSTN: %s / Normalized PSTN: %s.%n",
                                        mySession.myTutorialTag, pstn, nrmlResponseReturn.normalized);
            }

            nrmlResponseReturn.result = nrmlResponse.result;
            return nrmlResponseReturn;
        }