From: <ssk...@vh...> - 2005-12-16 18:39:48
|
Author: sskracic Date: 2005-12-16 19:37:04 +0100 (Fri, 16 Dec 2005) New Revision: 1062 Added: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/VipSMSProvider.java Log: A class used only for testing, since I doubt that many Aplaws+ developers have a Vipnet mobile number. Added: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/VipSMSProvider.java =================================================================== --- contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/VipSMSProvider.java 2005-12-16 18:01:03 UTC (rev 1061) +++ contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/VipSMSProvider.java 2005-12-16 18:37:04 UTC (rev 1062) @@ -0,0 +1,52 @@ +package com.arsdigita.camden.cms.contenttypes; + +import com.arsdigita.bebop.parameters.ParameterData; +import com.arsdigita.util.Assert; + +/** + * Used for testing only, since it accepts only + * Vipnet customers in Croatia. + */ +public class VipSMSProvider implements SMSEmailProvider { + + // this will fail when number portability shows up :) + public static final String VIP_MOBILE_PREFIX = "38591"; + + /** + * Provides the email address that will be used as gateway + * to the SMS for the supplied mobile number. + */ + public String getEmail(String mobileNumber) { + // trim everything that is not a digit + String trimmedNumber = mobileNumber.replaceAll("[^0-9]", ""); + Assert.truth(trimmedNumber.startsWith(VIP_MOBILE_PREFIX), + "The number " + mobileNumber + " is not a VIP mobile number"); + return trimmedNumber + "@sms.vip.hr"; + } + + /** + * Performs a mobile number validation for the supplied number. + * Errors, if any, will be attached to the supplied ParameterData object. + * The number will be normalised, ie. will start with +385 + * @param data ParameterData for the mobile number UI widget + */ + public void validateNumber(ParameterData data) { + String number = data.getValue().toString().replaceAll("[^0-9]", ""); + // number is valid if it starts with VIP prefix + // First strip the leading country prefix, if exists + number = number.replaceFirst("^385", ""); + // then strip the leading zero + number = number.replaceFirst("^0", ""); + // We now have to have a number starting with 91 to denote Vipnet. + // It must be at least (or exactly?) 9 digits in length + // 91 xxx xx xx + if (!number.startsWith("91") || number.length() < 9) { + data.addError((String)ConsultationUtil. + globalize("invalid_mobile").localize()); + } else { + data.setValue("+385" + number); + } + } + +} + Property changes on: contrib/ccm-ldn-camden-consultation/trunk/src/com/arsdigita/camden/cms/contenttypes/VipSMSProvider.java ___________________________________________________________________ Name: svn:keywords + Id Author URL |