Coverage Report - org.seasar.teeda.core.taglib.core.ConvertNumberTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ConvertNumberTag
99%
153/155
89%
34/38
1.73
 
 1  
 /*
 2  
  * Copyright 2004-2011 the Seasar Foundation and the Others.
 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,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.teeda.core.taglib.core;
 17  
 
 18  
 import java.util.Locale;
 19  
 
 20  
 import javax.faces.context.FacesContext;
 21  
 import javax.faces.convert.Converter;
 22  
 import javax.faces.convert.NumberConverter;
 23  
 import javax.faces.internal.ValueBindingUtil;
 24  
 import javax.faces.webapp.ConverterTag;
 25  
 import javax.servlet.jsp.JspException;
 26  
 import javax.servlet.jsp.PageContext;
 27  
 
 28  
 import org.seasar.framework.util.LocaleUtil;
 29  
 import org.seasar.teeda.core.JsfConstants;
 30  
 
 31  
 /**
 32  
  * @author shot
 33  
  * @author yone
 34  
  */
 35  
 public class ConvertNumberTag extends ConverterTag {
 36  
 
 37  
     private static final long serialVersionUID = 1L;
 38  
 
 39  21
     private String currencyCode_ = null;
 40  
 
 41  21
     private String currencySymbol_ = null;
 42  
 
 43  21
     private String groupingUsed_ = JsfConstants.DEFAULT_CONVERTNUMBER_GROUPING_USED;
 44  
 
 45  21
     private String integerOnly_ = JsfConstants.DEFAULT_CONVERTNUMBER_INTEGER_ONLY;
 46  
 
 47  21
     private String locale_ = null;
 48  
 
 49  21
     private String maxFractionDigits_ = null;
 50  
 
 51  21
     private String maxIntegerDigits_ = null;
 52  
 
 53  21
     private String minFractionDigits_ = null;
 54  
 
 55  21
     private String minIntegerDigits_ = null;
 56  
 
 57  21
     private String pattern_ = null;
 58  
 
 59  21
     private String type_ = JsfConstants.DEFAULT_CONVERTNUMBER_TYPE;
 60  
 
 61  21
     public ConvertNumberTag() {
 62  21
     }
 63  
 
 64  
     public void setPageContext(PageContext context) {
 65  2
         super.setPageContext(context);
 66  2
         setConverterId(NumberConverter.CONVERTER_ID);
 67  2
     }
 68  
 
 69  
     protected Converter createConverter() throws JspException {
 70  2
         NumberConverter converter = (NumberConverter) super.createConverter();
 71  
 
 72  2
         FacesContext facesContext = FacesContext.getCurrentInstance();
 73  2
         setConverterCurrencyCode(facesContext, converter);
 74  2
         setConverterCurrencySymbol(facesContext, converter);
 75  2
         setConverterGroupingUsed(facesContext, converter);
 76  2
         setConverterIntegerOnly(facesContext, converter);
 77  2
         setConverterLocale(facesContext, converter);
 78  2
         setConverterMaxFractionDigits(facesContext, converter);
 79  2
         setConverterMaxIntegerDigits(facesContext, converter);
 80  2
         setConverterMinFractionDigits(facesContext, converter);
 81  2
         setConverterMinIntegerDigits(facesContext, converter);
 82  2
         setConverterPattern(facesContext, converter);
 83  2
         setConverterType(facesContext, converter);
 84  
 
 85  2
         return converter;
 86  
     }
 87  
 
 88  
     protected void setConverterCurrencyCode(FacesContext context,
 89  
             NumberConverter converter) {
 90  4
         String currencyCode = getCurrencyCode();
 91  4
         if (currencyCode == null) {
 92  1
             return;
 93  
         }
 94  3
         String cCode = (String) ValueBindingUtil
 95  
                 .getValue(context, currencyCode);
 96  3
         if (cCode == null) {
 97  2
             cCode = currencyCode;
 98  
         }
 99  3
         converter.setCurrencyCode(cCode);
 100  3
     }
 101  
 
 102  
     protected void setConverterCurrencySymbol(FacesContext context,
 103  
             NumberConverter converter) {
 104  3
         String currencySymbol = getCurrencySymbol();
 105  3
         if (currencySymbol == null) {
 106  1
             return;
 107  
         }
 108  2
         String symbol = (String) ValueBindingUtil.getValue(context,
 109  
                 currencySymbol);
 110  2
         if (symbol == null) {
 111  1
             symbol = currencySymbol;
 112  
         }
 113  2
         converter.setCurrencySymbol(symbol);
 114  2
     }
 115  
 
 116  
     protected void setConverterGroupingUsed(FacesContext context,
 117  
             NumberConverter converter) {
 118  6
         final String groupingUsed = getGroupingUsed();
 119  6
         if (groupingUsed == null) {
 120  0
             return;
 121  
         }
 122  6
         Boolean b = (Boolean) ValueBindingUtil.getValue(context, groupingUsed);
 123  6
         if (b == null) {
 124  5
             b = new Boolean(groupingUsed);
 125  
         }
 126  6
         converter.setGroupingUsed(b.booleanValue());
 127  6
     }
 128  
 
 129  
     protected void setConverterIntegerOnly(FacesContext context,
 130  
             NumberConverter converter) {
 131  3
         final String integerOnly = getIntegerOnly();
 132  3
         if (integerOnly == null) {
 133  0
             return;
 134  
         }
 135  3
         Boolean b = (Boolean) ValueBindingUtil.getValue(context, integerOnly);
 136  3
         if (b == null) {
 137  2
             b = new Boolean(integerOnly);
 138  
         }
 139  3
         converter.setIntegerOnly(b.booleanValue());
 140  3
     }
 141  
 
 142  
     protected void setConverterLocale(FacesContext context,
 143  
             NumberConverter converter) {
 144  4
         Locale locale = (Locale) ValueBindingUtil
 145  
                 .getValue(context, getLocale());
 146  4
         if (locale == null) {
 147  3
             locale = LocaleUtil.getLocale(getLocale());
 148  
         }
 149  4
         converter.setLocale(locale);
 150  4
     }
 151  
 
 152  
     protected void setConverterMaxFractionDigits(FacesContext context,
 153  
             NumberConverter converter) {
 154  4
         final String maxFractionDigits = getMaxFractionDigits();
 155  4
         if (maxFractionDigits == null) {
 156  1
             return;
 157  
         }
 158  3
         Integer i = (Integer) ValueBindingUtil.getValue(context,
 159  
                 maxFractionDigits);
 160  3
         if (i == null) {
 161  2
             i = new Integer(maxFractionDigits);
 162  
         }
 163  3
         converter.setMaxFractionDigits(i.intValue());
 164  3
     }
 165  
 
 166  
     protected void setConverterMaxIntegerDigits(FacesContext context,
 167  
             NumberConverter converter) {
 168  4
         final String maxIntegerDigits = getMaxIntegerDigits();
 169  4
         if (maxIntegerDigits == null) {
 170  1
             return;
 171  
         }
 172  3
         Integer i = (Integer) ValueBindingUtil.getValue(context,
 173  
                 maxIntegerDigits);
 174  3
         if (i == null) {
 175  2
             i = new Integer(maxIntegerDigits);
 176  
         }
 177  3
         converter.setMaxIntegerDigits(i.intValue());
 178  3
     }
 179  
 
 180  
     protected void setConverterMinFractionDigits(FacesContext context,
 181  
             NumberConverter converter) {
 182  4
         final String minFractionDigits = getMinFractionDigits();
 183  4
         if (minFractionDigits == null) {
 184  1
             return;
 185  
         }
 186  3
         Integer i = (Integer) ValueBindingUtil.getValue(context,
 187  
                 minFractionDigits);
 188  3
         if (i == null) {
 189  2
             i = new Integer(minFractionDigits);
 190  
         }
 191  3
         converter.setMinFractionDigits(i.intValue());
 192  3
     }
 193  
 
 194  
     protected void setConverterMinIntegerDigits(FacesContext context,
 195  
             NumberConverter converter) {
 196  4
         final String minIntegerDigits = getMinIntegerDigits();
 197  4
         if (minIntegerDigits == null) {
 198  1
             return;
 199  
         }
 200  3
         Integer i = (Integer) ValueBindingUtil.getValue(context,
 201  
                 minIntegerDigits);
 202  3
         if (i == null) {
 203  2
             i = new Integer(minIntegerDigits);
 204  
         }
 205  3
         converter.setMinIntegerDigits(i.intValue());
 206  3
     }
 207  
 
 208  
     protected void setConverterPattern(FacesContext context,
 209  
             NumberConverter converter) {
 210  2
         String pattern = (String) ValueBindingUtil.getValue(context,
 211  
                 getPattern());
 212  2
         if (pattern == null) {
 213  2
             pattern = getPattern();
 214  
         }
 215  2
         converter.setPattern(pattern);
 216  2
     }
 217  
 
 218  
     protected void setConverterType(FacesContext context,
 219  
             NumberConverter converter) {
 220  2
         String type = (String) ValueBindingUtil.getValue(context, getType());
 221  2
         if (type == null) {
 222  2
             type = getType();
 223  
         }
 224  2
         converter.setType(type);
 225  2
     }
 226  
 
 227  
     public void release() {
 228  1
         super.release();
 229  1
         currencyCode_ = null;
 230  1
         currencySymbol_ = null;
 231  1
         groupingUsed_ = JsfConstants.DEFAULT_CONVERTNUMBER_GROUPING_USED;
 232  1
         integerOnly_ = JsfConstants.DEFAULT_CONVERTNUMBER_INTEGER_ONLY;
 233  1
         locale_ = null;
 234  1
         maxFractionDigits_ = null;
 235  1
         maxIntegerDigits_ = null;
 236  1
         minFractionDigits_ = null;
 237  1
         minIntegerDigits_ = null;
 238  1
         pattern_ = null;
 239  1
         type_ = JsfConstants.DEFAULT_CONVERTNUMBER_TYPE;
 240  1
     }
 241  
 
 242  
     public void setCurrencyCode(String currencyCode) {
 243  4
         this.currencyCode_ = currencyCode;
 244  4
     }
 245  
 
 246  
     public void setCurrencySymbol(String currencySymbol) {
 247  3
         this.currencySymbol_ = currencySymbol;
 248  3
     }
 249  
 
 250  
     public void setGroupingUsed(String groupingUsed) {
 251  3
         this.groupingUsed_ = groupingUsed;
 252  3
     }
 253  
 
 254  
     public void setIntegerOnly(String integerOnly) {
 255  3
         this.integerOnly_ = integerOnly;
 256  3
     }
 257  
 
 258  
     public void setLocale(String locale) {
 259  2
         this.locale_ = locale;
 260  2
     }
 261  
 
 262  
     public void setMaxFractionDigits(String maxFractionDigits) {
 263  4
         this.maxFractionDigits_ = maxFractionDigits;
 264  4
     }
 265  
 
 266  
     public void setMaxIntegerDigits(String maxIntegerDigits) {
 267  4
         this.maxIntegerDigits_ = maxIntegerDigits;
 268  4
     }
 269  
 
 270  
     public void setMinFractionDigits(String minFractionDigits) {
 271  4
         this.minFractionDigits_ = minFractionDigits;
 272  4
     }
 273  
 
 274  
     public void setMinIntegerDigits(String minIntegerDigits) {
 275  4
         this.minIntegerDigits_ = minIntegerDigits;
 276  4
     }
 277  
 
 278  
     public void setPattern(String pattern) {
 279  2
         this.pattern_ = pattern;
 280  2
     }
 281  
 
 282  
     public void setType(String type) {
 283  2
         this.type_ = type;
 284  2
     }
 285  
 
 286  
     public String getCurrencyCode() {
 287  5
         return currencyCode_;
 288  
     }
 289  
 
 290  
     public String getCurrencySymbol() {
 291  4
         return currencySymbol_;
 292  
     }
 293  
 
 294  
     public String getGroupingUsed() {
 295  7
         return groupingUsed_;
 296  
     }
 297  
 
 298  
     public String getIntegerOnly() {
 299  4
         return integerOnly_;
 300  
     }
 301  
 
 302  
     public String getLocale() {
 303  8
         return locale_;
 304  
     }
 305  
 
 306  
     public String getMaxFractionDigits() {
 307  5
         return maxFractionDigits_;
 308  
     }
 309  
 
 310  
     public String getMaxIntegerDigits() {
 311  5
         return maxIntegerDigits_;
 312  
     }
 313  
 
 314  
     public String getMinFractionDigits() {
 315  5
         return minFractionDigits_;
 316  
     }
 317  
 
 318  
     public String getMinIntegerDigits() {
 319  5
         return minIntegerDigits_;
 320  
     }
 321  
 
 322  
     public String getPattern() {
 323  5
         return pattern_;
 324  
     }
 325  
 
 326  
     public String getType() {
 327  5
         return type_;
 328  
     }
 329  
 
 330  
 }