Coverage Report - org.seasar.teeda.core.taglib.core.ConvertDateTimeTag
 
Classes in this File Line Coverage Branch Coverage Complexity
ConvertDateTimeTag
100%
76/76
79%
11/14
1.304
 
 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  
 import java.util.TimeZone;
 20  
 
 21  
 import javax.faces.context.FacesContext;
 22  
 import javax.faces.convert.Converter;
 23  
 import javax.faces.convert.DateTimeConverter;
 24  
 import javax.faces.internal.ValueBindingUtil;
 25  
 import javax.faces.webapp.ConverterTag;
 26  
 import javax.servlet.jsp.JspException;
 27  
 import javax.servlet.jsp.PageContext;
 28  
 
 29  
 import org.seasar.framework.util.LocaleUtil;
 30  
 import org.seasar.teeda.core.JsfConstants;
 31  
 
 32  
 /**
 33  
  * @author shot
 34  
  * @author yone
 35  
  */
 36  
 public class ConvertDateTimeTag extends ConverterTag {
 37  
 
 38  
     private static final long serialVersionUID = 1L;
 39  
 
 40  9
     private String dateStyle = JsfConstants.DEFAULT_CONVERTDATETIME_DATE_STYLE;
 41  
 
 42  
     private String locale;
 43  
 
 44  
     private String pattern;
 45  
 
 46  9
     private String timeStyle = JsfConstants.DEFAULT_CONVERTDATETIME_TIME_STYLE;
 47  
 
 48  
     private String timeZone;
 49  
 
 50  9
     private String type = JsfConstants.DEFAULT_CONVERTDATETIME_TYPE;
 51  
 
 52  9
     public ConvertDateTimeTag() {
 53  9
     }
 54  
 
 55  
     public void setDateStyle(String dateStyle) {
 56  3
         this.dateStyle = dateStyle;
 57  3
     }
 58  
 
 59  
     public void setLocale(String locale) {
 60  4
         this.locale = locale;
 61  4
     }
 62  
 
 63  
     public void setPattern(String pattern) {
 64  2
         this.pattern = pattern;
 65  2
     }
 66  
 
 67  
     public void setTimeStyle(String timeStyle) {
 68  2
         this.timeStyle = timeStyle;
 69  2
     }
 70  
 
 71  
     public void setTimeZone(String timeZone) {
 72  4
         this.timeZone = timeZone;
 73  4
     }
 74  
 
 75  
     public void setType(String type) {
 76  2
         this.type = type;
 77  2
     }
 78  
 
 79  
     public String getDateStyle() {
 80  1
         return dateStyle;
 81  
     }
 82  
 
 83  
     public String getLocale() {
 84  8
         return locale;
 85  
     }
 86  
 
 87  
     public String getPattern() {
 88  4
         return pattern;
 89  
     }
 90  
 
 91  
     public String getTimeStyle() {
 92  5
         return timeStyle;
 93  
     }
 94  
 
 95  
     public String getTimeZone() {
 96  10
         return timeZone;
 97  
     }
 98  
 
 99  
     public String getType() {
 100  5
         return type;
 101  
     }
 102  
 
 103  
     public void setPageContext(PageContext context) {
 104  2
         super.setPageContext(context);
 105  2
         setConverterId(DateTimeConverter.CONVERTER_ID);
 106  2
     }
 107  
 
 108  
     protected Converter createConverter() throws JspException {
 109  2
         DateTimeConverter converter = (DateTimeConverter) super
 110  
                 .createConverter();
 111  2
         FacesContext context = getFacesContext();
 112  2
         setConverterDateStyle(context, converter);
 113  2
         setConverterLocale(context, converter);
 114  2
         setConverterPattern(context, converter);
 115  2
         setConverterTimeStyle(context, converter);
 116  2
         setConverterTimeZone(context, converter);
 117  2
         setConverterType(context, converter);
 118  2
         return converter;
 119  
     }
 120  
 
 121  
     protected void setConverterDateStyle(FacesContext context,
 122  
             DateTimeConverter converter) {
 123  4
         String dateStyle = (String) ValueBindingUtil.getValue(context,
 124  
                 this.dateStyle);
 125  4
         if (dateStyle == null) {
 126  3
             dateStyle = this.dateStyle;
 127  
         }
 128  4
         converter.setDateStyle(dateStyle);
 129  4
     }
 130  
 
 131  
     protected void setConverterLocale(FacesContext context,
 132  
             DateTimeConverter converter) {
 133  4
         Locale locale = (Locale) ValueBindingUtil
 134  
                 .getValue(context, getLocale());
 135  4
         if (locale == null) {
 136  3
             locale = LocaleUtil.getLocale(getLocale());
 137  
         }
 138  4
         converter.setLocale(locale);
 139  4
     }
 140  
 
 141  
     protected void setConverterPattern(FacesContext context,
 142  
             DateTimeConverter converter) {
 143  2
         String pattern = (String) ValueBindingUtil.getValue(context,
 144  
                 getPattern());
 145  2
         if (pattern == null) {
 146  2
             pattern = getPattern();
 147  
         }
 148  2
         converter.setPattern(pattern);
 149  2
     }
 150  
 
 151  
     protected void setConverterTimeStyle(FacesContext context,
 152  
             DateTimeConverter converter) {
 153  2
         String timeStyle = (String) ValueBindingUtil.getValue(context,
 154  
                 getTimeStyle());
 155  2
         if (timeStyle == null) {
 156  2
             timeStyle = getTimeStyle();
 157  
         }
 158  2
         converter.setTimeStyle(timeStyle);
 159  2
     }
 160  
 
 161  
     protected void setConverterTimeZone(FacesContext context,
 162  
             DateTimeConverter converter) {
 163  4
         TimeZone timeZone = (TimeZone) ValueBindingUtil.getValue(context,
 164  
                 getTimeZone());
 165  4
         if (timeZone == null) {
 166  3
             if (getTimeZone() != null) {
 167  2
                 timeZone = TimeZone.getTimeZone(getTimeZone());
 168  
             } else {
 169  1
                 timeZone = TimeZone.getDefault();
 170  
             }
 171  
         }
 172  4
         converter.setTimeZone(timeZone);
 173  4
     }
 174  
 
 175  
     protected void setConverterType(FacesContext context,
 176  
             DateTimeConverter converter) {
 177  2
         String type = (String) ValueBindingUtil.getValue(context, getType());
 178  2
         if (type == null) {
 179  2
             type = getType();
 180  
         }
 181  2
         converter.setType(type);
 182  2
     }
 183  
 
 184  
     public void release() {
 185  1
         super.release();
 186  1
         dateStyle = JsfConstants.DEFAULT_CONVERTDATETIME_DATE_STYLE;
 187  1
         locale = null;
 188  1
         pattern = null;
 189  1
         timeStyle = JsfConstants.DEFAULT_CONVERTDATETIME_TIME_STYLE;
 190  1
         timeZone = null;
 191  1
         type = JsfConstants.DEFAULT_CONVERTDATETIME_TYPE;
 192  1
     }
 193  
 
 194  
     private static FacesContext getFacesContext() {
 195  2
         return FacesContext.getCurrentInstance();
 196  
     }
 197  
 
 198  
 }