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 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      @Override
57      public Value<?> normalize( Value<?> value ) throws LdapException
58      {
59          String str = value.getString();
60  
61          if ( Strings.isEmpty( str ) )
62          {
63              return new StringValue( str );
64          }
65  
66          return new StringValue( str );
67      }
68  
69  
70      /**
71       * {@inheritDoc}
72       */
73      @Override
74      public String normalize( String value ) throws LdapException
75      {
76          if ( Strings.isEmpty( value ) )
77          {
78              return value;
79          }
80  
81          return value;
82      }
83  
84  
85      /**
86       * Normalize the given String
87       *
88       * @param string The string to normalize
89       * @return The normalized object
90       * @throws LdapException If the normalization throws an error
91       */
92      public static String normalizeString( String string ) throws LdapException
93      {
94          return NORMALIZER.normalize( string );
95      }
96  }