View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.maven.issue.config;
17  
18  import java.util.Map;
19  
20  import org.apache.commons.lang.StringUtils;
21  
22  import com.thoughtworks.xstream.converters.basic.StringConverter;
23  
24  /**
25   * Converter for String to strip whitespace from the content of element.
26   */
27  public final class NormalizeWhitespaceStringConverter extends StringConverter
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    // --- members --------------------------------------------------------------
34  
35    // ****************************** Initializer *******************************
36  
37    // ****************************** Constructors ******************************
38  
39    /**
40     * Constructor.
41     *
42     * @see com.thoughtworks.xstream.converters.basic.StringConverter#StringConverter()
43     */
44    public NormalizeWhitespaceStringConverter()
45    {
46    }
47  
48    /**
49     * Constructor.
50     *
51     * @param map the map to use for the instances to reuse (may be null to not
52     *          cache at all)
53     * @see com.thoughtworks.xstream.converters.basic.StringConverter#StringConverter(java.util.Map)
54     */
55    public NormalizeWhitespaceStringConverter(final Map<?, ?> map)
56    {
57      super(map);
58    }
59  
60    /**
61     * Constructor.
62     *
63     * @param lengthLimit maximum string length of a cached string, -1 to cache
64     *          all, 0 to turn off the cache
65     * @see com.thoughtworks.xstream.converters.basic.StringConverter#StringConverter(int)
66     */
67    public NormalizeWhitespaceStringConverter(final int lengthLimit)
68    {
69      super(lengthLimit);
70    }
71  
72    /**
73     * Constructor.
74     *
75     * @param map the map to use for the instances to reuse (may be null to not
76     *          cache at all)
77     * @param lengthLimit maximum string length of a cached string, -1 to cache
78     *          all, 0 to turn off the cache
79     * @see com.thoughtworks.xstream.converters.basic.StringConverter#StringConverter(java.util.Map,
80     *      int)
81     */
82    public NormalizeWhitespaceStringConverter(final Map<?, ?> map,
83        final int lengthLimit)
84    {
85      super(map, lengthLimit);
86    }
87  
88    // ****************************** Inner Classes *****************************
89  
90    // ********************************* Methods ********************************
91  
92    // --- init -----------------------------------------------------------------
93  
94    // --- get&set --------------------------------------------------------------
95  
96    // --- business -------------------------------------------------------------
97  
98    /**
99     * {@inheritDoc}
100    * <p>
101    * Trims each string.
102    * </p>
103    *
104    * @see com.thoughtworks.xstream.converters.basic.StringConverter#fromString(java.lang.String)
105    */
106   @Override
107   public Object fromString(final String str)
108   {
109     final String value = (String) super.fromString(str);
110     final String normalized = StringUtils.normalizeSpace(value);
111     return normalized;
112   }
113 
114   // --- object basics --------------------------------------------------------
115 
116 }