View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.directory.api.ldap.model.schema.normalizers;
21  
22  
23  import java.io.IOException;
24  
25  import org.apache.directory.api.i18n.I18n;
26  import org.apache.directory.api.ldap.model.constants.SchemaConstants;
27  import org.apache.directory.api.ldap.model.entry.StringValue;
28  import org.apache.directory.api.ldap.model.entry.Value;
29  import org.apache.directory.api.ldap.model.exception.LdapException;
30  import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException;
31  import org.apache.directory.api.ldap.model.schema.Normalizer;
32  import org.apache.directory.api.ldap.model.schema.PrepareString;
33  
34  
35  /**
36   * Normalize Telephone Number Strings
37   *
38   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
39   */
40  @SuppressWarnings("serial")
41  public class TelephoneNumberNormalizer extends Normalizer
42  {
43      /**
44       * Creates a new instance of TelephoneNumberNormalizer.
45       */
46      public TelephoneNumberNormalizer()
47      {
48          super( SchemaConstants.TELEPHONE_NUMBER_MATCH_MR_OID );
49      }
50  
51  
52      /**
53       * {@inheritDoc}
54       */
55      @Override
56      public Value<?> normalize( Value<?> value ) throws LdapException
57      {
58          try
59          {
60              String normalized = PrepareString.normalize( value.getString(),
61                  PrepareString.StringType.TELEPHONE_NUMBER );
62  
63              return new StringValue( normalized );
64          }
65          catch ( IOException ioe )
66          {
67              throw new LdapInvalidDnException( I18n.err( I18n.ERR_04224, value ), ioe );
68          }
69      }
70  
71  
72      /**
73       * {@inheritDoc}
74       */
75      @Override
76      public String normalize( String value ) throws LdapException
77      {
78          try
79          {
80              return PrepareString.normalize( value,
81                  PrepareString.StringType.TELEPHONE_NUMBER );
82          }
83          catch ( IOException ioe )
84          {
85              throw new LdapInvalidDnException( I18n.err( I18n.ERR_04224, value ), ioe );
86          }
87      }
88  }