01: /*
02: * TrimWordFormatter.java
03: *
04: * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net)
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * 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 implements CSVFieldFormatter {
37:
38: /**
39: * Constructor for FirstWordFormatter.
40: */
41: public TrimWordFormatter() {
42: super ();
43: }
44:
45: /**
46: * Formats the specified value and returns a trimmed representation. All leading and
47: * trailing white space is trimmed.
48: *
49: * @param value the value to be trimmed
50: * @return the trimmed value
51: * @see CSVFieldFormatter#format(String)
52: */
53: public String format(final String value) {
54:
55: if (value == null) {
56: return null;
57: }
58: return StringUtils.trim(value);
59: }
60:
61: }
|