001    /*
002     * TrimWordFormatter.java
003     * 
004     * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net) 
005     * 
006     * This program is free software; you can redistribute it and/or 
007     * modify it under the terms of the GNU General Public License 
008     * as published by the Free Software Foundation; either version 2 
009     * of the License, or (at your option) any later version. 
010     * 
011     * This program is distributed in the hope that it will be useful, 
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of 
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
014     * GNU General Public License for more details. 
015     * 
016     * You should have received a copy of the GNU General Public License
017     * along with this program; if not, write to the Free Software 
018     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 
019     *
020     * Version: $Revision: 1.3 $
021     */
022    package net.sf.anupam.csv.formatters;
023    
024    import org.apache.commons.lang.StringUtils;
025    
026    /**
027     * A {@link CSVFieldFormatter formatter} that returns the trimmed
028     * CSV value. This is useful in situations when the CSV field is
029     * known to have leading or trailing white-space.
030     *
031     * @author Anupam Sengupta
032     * @version $Revision: 1.3 $
033     * @csv.formatter-mapping name="trimWord"
034     * @since 1.5
035     */
036    final class TrimWordFormatter
037            implements CSVFieldFormatter {
038    
039        /**
040         * Constructor for FirstWordFormatter.
041         */
042        public TrimWordFormatter() {
043            super();
044        }
045    
046        /**
047         * Formats the specified value and returns a trimmed representation. All leading and
048         * trailing white space is trimmed.
049         *
050         * @param value the value to be trimmed
051         * @return the trimmed value
052         * @see CSVFieldFormatter#format(String)
053         */
054        public String format(final String value) {
055    
056            if (value == null) {
057                return null;
058            }
059            return StringUtils.trim(value);
060        }
061    
062    }