1 /* 2 * Copyright 2012 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 com.thoughtworks.xstream.converters.basic.StringConverter; 21 22 /** 23 * Converter for String to trim the content of element. 24 */ 25 public final class TrimStringConverter extends StringConverter 26 { 27 // ********************************* Fields ********************************* 28 29 // --- constants ------------------------------------------------------------ 30 31 // --- members -------------------------------------------------------------- 32 33 // ****************************** Initializer ******************************* 34 35 // ****************************** Constructors ****************************** 36 37 /** 38 * Constructor. 39 * 40 * @see com.thoughtworks.xstream.converters.basic.StringConverter#StringConverter() 41 */ 42 public TrimStringConverter() 43 { 44 } 45 46 /** 47 * Constructor. 48 * 49 * @param map the map to use for the instances to reuse (may be null to not 50 * cache at all) 51 * @see com.thoughtworks.xstream.converters.basic.StringConverter#StringConverter(java.util.Map) 52 */ 53 public TrimStringConverter(final Map<?, ?> map) 54 { 55 super(map); 56 } 57 58 /** 59 * Constructor. 60 * 61 * @param lengthLimit maximum string length of a cached string, -1 to cache 62 * all, 0 to turn off the cache 63 * @see com.thoughtworks.xstream.converters.basic.StringConverter#StringConverter(int) 64 */ 65 public TrimStringConverter(final int lengthLimit) 66 { 67 super(lengthLimit); 68 } 69 70 /** 71 * Constructor. 72 * 73 * @param map the map to use for the instances to reuse (may be null to not 74 * cache at all) 75 * @param lengthLimit maximum string length of a cached string, -1 to cache 76 * all, 0 to turn off the cache 77 * @see com.thoughtworks.xstream.converters.basic.StringConverter#StringConverter(java.util.Map, 78 * int) 79 */ 80 public TrimStringConverter(final Map<?, ?> map, final int lengthLimit) 81 { 82 super(map, lengthLimit); 83 } 84 85 // ****************************** Inner Classes ***************************** 86 87 // ********************************* Methods ******************************** 88 89 // --- init ----------------------------------------------------------------- 90 91 // --- get&set -------------------------------------------------------------- 92 93 // --- business ------------------------------------------------------------- 94 95 /** 96 * {@inheritDoc} 97 * <p> 98 * Trims each string. 99 * </p> 100 * 101 * @see com.thoughtworks.xstream.converters.basic.StringConverter#fromString(java.lang.String) 102 */ 103 @Override 104 public Object fromString(final String str) 105 { 106 return ((String) super.fromString(str)).trim(); 107 } 108 109 // --- object basics -------------------------------------------------------- 110 111 }