View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 1.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl1.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.service.impl;
17  
18  import org.kuali.ole.select.service.OleForiegnVendorPhoneNumberService;
19  import org.kuali.ole.vnd.VendorParameterConstants;
20  import org.kuali.ole.vnd.businessobject.VendorDetail;
21  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
22  import org.kuali.rice.krad.util.ObjectUtils;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.regex.Matcher;
27  import java.util.regex.Pattern;
28  
29  public class OleForiegnVendorPhoneNumberServiceImpl implements OleForiegnVendorPhoneNumberService {
30  
31      public ParameterService parameterService;
32      public List<String> phoneNumberFormats;
33  
34      public void setParameterService(ParameterService parameterService) {
35          this.parameterService = parameterService;
36      }
37  
38      @Override
39      public boolean isValidForiegnVendorPhoneNumber(String phoneNumber) {
40          // TODO Auto-generated method stub
41          String[] formats = parseFormats();
42          for (int i = 0; i < formats.length; i++) {
43              if (phoneNumber.matches(formats[i])) {
44                  return true;
45              }
46          }
47          return false;
48      }
49  
50      protected String[] parseFormats() {
51          if (ObjectUtils.isNull(phoneNumberFormats)) {
52              phoneNumberFormats = new ArrayList<String>(parameterService.getParameterValuesAsString(VendorDetail.class, VendorParameterConstants.FOREIGN_VENDOR_PHONE_NUMBER_FORMATS));
53          }
54          return phoneNumberFormats.toArray(new String[]{});
55      }
56  
57  }