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     */
020    package org.apache.directory.shared.ldap.schema.normalizers;
021    
022    import javax.naming.NamingException;
023    
024    import org.apache.directory.shared.ldap.constants.SchemaConstants;
025    import org.apache.directory.shared.ldap.entry.Value;
026    import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
027    import org.apache.directory.shared.ldap.schema.Normalizer;
028    import org.apache.directory.shared.ldap.util.StringTools;
029    
030    
031    /**
032     * A normalizer which transforms an escape sequence into an internal 
033     * canonical form: into UTF-8 characters presuming the escape sequence
034     * fits that range.  This is used explicity for non-binary attribute
035     * types only.
036     *
037     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
038     * @version $Rev$, $Date$
039     */
040    public class DefaultStringNormalizer extends Normalizer
041    {
042        // The serial UID
043        private static final long serialVersionUID = 1L;
044        
045        /** A default String normalizer */
046        private static final DefaultStringNormalizer NORMALIZER = new DefaultStringNormalizer();
047        
048        protected DefaultStringNormalizer()
049        {
050            // TODO : This is probably not the correct OID ... 
051            super( SchemaConstants.CASE_IGNORE_MATCH_MR_OID );
052        }
053    
054    
055        /**
056         * {@inheritDoc}
057         */
058        public Value<?> normalize( Value<?> value ) throws NamingException
059        {
060            String str = value.getString();
061            
062            if ( StringTools.isEmpty( str ) )
063            {
064                return new ClientStringValue( str );
065            }
066            
067            return new ClientStringValue( str );
068        }
069    
070        
071        /**
072         * {@inheritDoc}
073         */
074        public String normalize( String value ) throws NamingException
075        {
076            if ( StringTools.isEmpty( value ) )
077            {
078                return value;
079            }
080            
081            return value;
082        }
083    
084        
085        /**
086         * Normalize the given String
087         *
088         * @param string The string to normalize
089         * @return The normalized object
090         * @throws NamingException If the normalization throws an error
091         */
092        public static String normalizeString( String string ) throws NamingException
093        {
094            return NORMALIZER.normalize( string );
095        }
096    }