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 org.apache.directory.api.ldap.model.constants.SchemaConstants;
24 import org.apache.directory.api.ldap.model.entry.StringValue;
25 import org.apache.directory.api.ldap.model.entry.Value;
26 import org.apache.directory.api.ldap.model.exception.LdapException;
27 import org.apache.directory.api.ldap.model.schema.Normalizer;
28 import org.apache.directory.api.util.Strings;
29
30
31 /**
32 * A normalizer which transforms an escape sequence into an internal
33 * canonical form: into UTF-8 characters presuming the escape sequence
34 * fits that range. This is used explicity for non-binary attribute
35 * types only.
36 *
37 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38 */
39 @SuppressWarnings("serial")
40 public class DefaultStringNormalizer extends Normalizer
41 {
42 /** A default String normalizer */
43 private static final DefaultStringNormalizer NORMALIZER = new DefaultStringNormalizer();
44
45
46 protected DefaultStringNormalizer()
47 {
48 // TODO : This is probably not the correct OID ...
49 super( SchemaConstants.CASE_IGNORE_MATCH_MR_OID );
50 }
51
52
53 /**
54 * {@inheritDoc}
55 */
56 public Value<?> normalize( Value<?> value ) throws LdapException
57 {
58 String str = value.getString();
59
60 if ( Strings.isEmpty( str ) )
61 {
62 return new StringValue( str );
63 }
64
65 return new StringValue( str );
66 }
67
68
69 /**
70 * {@inheritDoc}
71 */
72 public String normalize( String value ) throws LdapException
73 {
74 if ( Strings.isEmpty( value ) )
75 {
76 return value;
77 }
78
79 return value;
80 }
81
82
83 /**
84 * Normalize the given String
85 *
86 * @param string The string to normalize
87 * @return The normalized object
88 * @throws LdapException If the normalization throws an error
89 */
90 public static String normalizeString( String string ) throws LdapException
91 {
92 return NORMALIZER.normalize( string );
93 }
94 }