Clover Coverage Report - SmartWeb
Coverage timestamp: Sun Jun 8 2008 21:20:12 CEST
../../../../img/srcFileCovDistChart5.png 13% of files have more coverage
12   88   18   3
8   33   1,5   4
4     4,5  
1    
 
  BooleanConverter       Line # 32 12 18 50% 0.5
 
  (2)
 
1    /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10    * This library is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this library; if not, write to the Free Software
17    * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18    *
19    * For further informations on the SmartWeb Framework please visit
20    *
21    * http://smartweb.sourceforge.net
22    */
23    package net.smartlab.web.bean;
24   
25    import java.util.Locale;
26   
27    /**
28    * TODO documentation
29    *
30    * @author rlogiacco
31    */
 
32    public class BooleanConverter extends Converter {
33   
34    private boolean value;
35   
36   
37    /**
38    * TODO documentation
39    *
40    * @param value
41    */
 
42  2 toggle public BooleanConverter(boolean value) {
43  2 this.value = value;
44    }
45   
46    /**
47    * @see net.smartlab.web.bean.Converter#convert(java.lang.Class,
48    * java.lang.Object, java.util.Locale)
49    */
 
50  2 toggle public Object convert(Class type, Object value, Locale locale) throws ConversionException {
51  2 if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
52  1 if (value == null || value.toString().trim().length() == 0) {
53  0 value = "off";
54    }
55  1 if (value.toString().equalsIgnoreCase("on") || value.toString().equalsIgnoreCase("y")
56    || value.toString().equalsIgnoreCase("yes") || value.toString().equalsIgnoreCase("1")
57    || value.toString().equalsIgnoreCase("true")) {
58  1 return Boolean.TRUE;
59  0 } else if (value.toString().equalsIgnoreCase("off") || value.toString().equalsIgnoreCase("n")
60    || value.toString().equalsIgnoreCase("no") || value.toString().equalsIgnoreCase("0")
61    || value.toString().equalsIgnoreCase("false")) {
62  0 return Boolean.FALSE;
63    } else {
64  0 throw new ConversionException("Unable to convert to boolean `" + value + "`");
65    }
66    } else {
67  1 return value.toString();
68    }
69    }
70   
71    /**
72    * TODO documentation
73    *
74    * @return
75    */
 
76  0 toggle protected boolean hasDefault() {
77  0 return true;
78    }
79   
80    /**
81    * TODO documentation
82    *
83    * @return
84    */
 
85  0 toggle protected boolean getDefault() {
86  0 return value;
87    }
88    }