KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > anupam > csv > formatters > TrimWordFormatter


1 /*
2  * TrimWordFormatter.java
3  *
4  * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Version: $Revision: 1.3 $
21  */

22 package net.sf.anupam.csv.formatters;
23
24 import org.apache.commons.lang.StringUtils;
25
26 /**
27  * A {@link CSVFieldFormatter formatter} that returns the trimmed
28  * CSV value. This is useful in situations when the CSV field is
29  * known to have leading or trailing white-space.
30  *
31  * @author Anupam Sengupta
32  * @version $Revision: 1.3 $
33  * @csv.formatter-mapping name="trimWord"
34  * @since 1.5
35  */

36 final class TrimWordFormatter
37         implements CSVFieldFormatter {
38
39     /**
40      * Constructor for FirstWordFormatter.
41      */

42     public TrimWordFormatter() {
43         super();
44     }
45
46     /**
47      * Formats the specified value and returns a trimmed representation. All leading and
48      * trailing white space is trimmed.
49      *
50      * @param value the value to be trimmed
51      * @return the trimmed value
52      * @see CSVFieldFormatter#format(String)
53      */

54     public String JavaDoc format(final String JavaDoc value) {
55
56         if (value == null) {
57             return null;
58         }
59         return StringUtils.trim(value);
60     }
61
62 }
63
Popular Tags