001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *  
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *  
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License. 
018 *  
019 */
020package org.apache.directory.shared.ldap.model.schema.normalizers;
021
022import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
023import org.apache.directory.shared.ldap.model.entry.StringValue;
024import org.apache.directory.shared.ldap.model.entry.Value;
025import org.apache.directory.shared.ldap.model.exception.LdapException;
026import org.apache.directory.shared.ldap.model.schema.Normalizer;
027import org.apache.directory.shared.util.Strings;
028
029
030/**
031 * A normalizer which transforms an escape sequence into an internal 
032 * canonical form: into UTF-8 characters presuming the escape sequence
033 * fits that range.  This is used explicity for non-binary attribute
034 * types only.
035 *
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 */
038@SuppressWarnings("serial")
039public class DefaultStringNormalizer extends Normalizer
040{
041    /** A default String normalizer */
042    private static final DefaultStringNormalizer NORMALIZER = new DefaultStringNormalizer();
043    
044    protected DefaultStringNormalizer()
045    {
046        // TODO : This is probably not the correct OID ... 
047        super( SchemaConstants.CASE_IGNORE_MATCH_MR_OID );
048    }
049
050
051    /**
052     * {@inheritDoc}
053     */
054    public Value<?> normalize( Value<?> value ) throws LdapException
055    {
056        String str = value.getString();
057        
058        if ( Strings.isEmpty(str) )
059        {
060            return new StringValue( str );
061        }
062        
063        return new StringValue( str );
064    }
065
066    
067    /**
068     * {@inheritDoc}
069     */
070    public String normalize( String value ) throws LdapException
071    {
072        if ( Strings.isEmpty(value) )
073        {
074            return value;
075        }
076        
077        return value;
078    }
079
080    
081    /**
082     * Normalize the given String
083     *
084     * @param string The string to normalize
085     * @return The normalized object
086     * @throws LdapException If the normalization throws an error
087     */
088    public static String normalizeString( String string ) throws LdapException
089    {
090        return NORMALIZER.normalize( string );
091    }
092}