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 * https://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 org.apache.directory.api.ldap.model.constants.SchemaConstants;
24 import org.apache.directory.api.ldap.model.entry.Value;
25 import org.apache.directory.api.ldap.model.exception.LdapException;
26 import org.apache.directory.api.ldap.model.schema.Normalizer;
27 import org.apache.directory.api.ldap.model.schema.PrepareString;
28 import org.apache.directory.api.ldap.model.schema.PreparedNormalizer;
29
30
31 /**
32 * Normalize Numeric Strings
33 *
34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35 */
36 @SuppressWarnings("serial")
37 public class NumericNormalizer extends Normalizer implements PreparedNormalizer
38 {
39 /**
40 * Creates a new instance of NumericNormalizer.
41 */
42 public NumericNormalizer()
43 {
44 super( SchemaConstants.NUMERIC_STRING_MATCH_MR_OID );
45 }
46
47
48 /**
49 * Normalize a Value
50 *
51 * @param value The value to normalize
52 * @return The normalized value
53 * @exception LdapException If teh value cannot be normalized or is invalid
54 */
55 public Value normalize( Value value ) throws LdapException
56 {
57 String normalized = normalize( value.getString() );
58
59 return new Value( normalized );
60 }
61
62
63 /**
64 * {@inheritDoc}
65 */
66 @Override
67 public String normalize( String value ) throws LdapException
68 {
69 return normalize( value, PrepareString.AssertionType.ATTRIBUTE_VALUE );
70 }
71
72
73 /**
74 * {@inheritDoc}
75 */
76 @Override
77 public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException
78 {
79 if ( value == null )
80 {
81 return null;
82 }
83
84 char[] chars = value.toCharArray();
85
86 // Insignificant Characters Handling
87 return PrepareString.insignificantNumericStringHandling( chars );
88 }
89 }