Coverage Report - org.apache.myfaces.shared_impl.taglib.core.ConvertDateTimeTagBase
 
Classes in this File Line Coverage Branch Coverage Complexity
ConvertDateTimeTagBase
0%
0/81
0%
0/28
2.538
 
 1  
 /*
 2  
  *  Licensed to the Apache Software Foundation (ASF) under one
 3  
  *  or more contributor license agreements.  See the NOTICE file
 4  
  *  distributed with this work for additional information
 5  
  *  regarding copyright ownership.  The ASF licenses this file
 6  
  *  to you under the Apache License, Version 2.0 (the
 7  
  *  "License"); you may not use this file except in compliance
 8  
  *  with the License.  You may obtain a copy of the License at
 9  
  * 
 10  
  *  http://www.apache.org/licenses/LICENSE-2.0
 11  
  * 
 12  
  *  Unless required by applicable law or agreed to in writing,
 13  
  *  software distributed under the License is distributed on an
 14  
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  *  KIND, either express or implied.  See the License for the
 16  
  *  specific language governing permissions and limitations
 17  
  *  under the License.
 18  
  */
 19  
 package org.apache.myfaces.shared_impl.taglib.core;
 20  
 
 21  
 import java.util.Locale;
 22  
 import java.util.TimeZone;
 23  
 
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.convert.Converter;
 26  
 import javax.faces.convert.DateTimeConverter;
 27  
 import javax.faces.webapp.ConverterTag;
 28  
 import javax.faces.webapp.UIComponentTag;
 29  
 import javax.faces.el.ValueBinding;
 30  
 import javax.servlet.jsp.JspException;
 31  
 
 32  
 import org.apache.myfaces.shared_impl.util.LocaleUtils;
 33  
 
 34  
 /**
 35  
  * @author Manfred Geiler (latest modification by $Author: schof $)
 36  
  * @version $Revision: 382015 $ $Date: 2006-03-01 14:47:11 +0100 (Wed, 01 Mar 2006) $
 37  
  */
 38  0
 public class ConvertDateTimeTagBase 
 39  
         extends ConverterTag
 40  
 {
 41  
     private static final long serialVersionUID = -757757296071312897L;
 42  0
     private String _dateStyle = "default"; // the default value as required by the spec (default in this case)
 43  0
     private String _locale = null;
 44  0
     private String _pattern = null;
 45  0
     private String _timeStyle = "default"; // the default value as required by the spec (default in this case)
 46  0
     private String _timeZone = null;
 47  0
     private String _type = null;
 48  
 
 49  
     public void setDateStyle(String dateStyle)
 50  
     {
 51  0
         _dateStyle = dateStyle;
 52  0
     }
 53  
 
 54  
     public void setLocale(String locale)
 55  
     {
 56  0
         _locale = locale;
 57  0
     }
 58  
 
 59  
     public void setPattern(String pattern)
 60  
     {
 61  0
         _pattern = pattern;
 62  0
     }
 63  
 
 64  
     public void setTimeStyle(String timeStyle)
 65  
     {
 66  0
         _timeStyle = timeStyle;
 67  0
     }
 68  
 
 69  
     public void setTimeZone(String timeZone)
 70  
     {
 71  0
         _timeZone = timeZone;
 72  0
     }
 73  
 
 74  
     public void setType(String type)
 75  
     {
 76  0
         _type = type;
 77  0
     }
 78  
 
 79  
     protected Converter createConverter() throws JspException
 80  
     {
 81  0
         DateTimeConverter converter = (DateTimeConverter)super.createConverter();
 82  
 
 83  0
         FacesContext facesContext = FacesContext.getCurrentInstance();
 84  0
         setConverterDateStyle(facesContext, converter, _dateStyle);
 85  0
         setConverterLocale(facesContext, converter, _locale);
 86  0
         setConverterPattern(facesContext, converter, _pattern);
 87  0
         setConverterTimeStyle(facesContext, converter, _timeStyle);
 88  0
         setConverterTimeZone(facesContext, converter, _timeZone);
 89  0
         setConverterType(facesContext, converter, _type);
 90  
 
 91  0
         return converter;
 92  
     }
 93  
 
 94  
     protected static void setConverterLocale(FacesContext facesContext,
 95  
                                              DateTimeConverter converter,
 96  
                                              String value)
 97  
     {
 98  0
        Locale locale = null;
 99  0
        Object _value = null;
 100  
             
 101  0
         if (value == null) return;
 102  0
         if (UIComponentTag.isValueReference(value))
 103  
         {
 104  0
             ValueBinding vb = facesContext.getApplication().createValueBinding(value);
 105  0
             _value = vb.getValue(facesContext);
 106  0
             if(_value instanceof Locale)
 107  
             {
 108  0
                 locale = (Locale) _value;
 109  
             }
 110  
             else
 111  
             {
 112  0
                 locale = LocaleUtils.converterTagLocaleFromString(_value.toString());
 113  
             }
 114  0
         }
 115  
         else
 116  
         {
 117  0
             locale = LocaleUtils.converterTagLocaleFromString(    value);
 118  
         }
 119  0
         converter.setLocale(locale);
 120  0
     }
 121  
 
 122  
 
 123  
     private static void setConverterDateStyle(FacesContext facesContext,
 124  
                                               DateTimeConverter converter,
 125  
                                               String value)
 126  
     {
 127  0
         if (value == null) return;
 128  0
         if (UIComponentTag.isValueReference(value))
 129  
         {
 130  0
             ValueBinding vb = facesContext.getApplication().createValueBinding(value);
 131  0
             converter.setDateStyle((String)vb.getValue(facesContext));
 132  0
         }
 133  
         else
 134  
         {
 135  0
             converter.setDateStyle(value);
 136  
         }
 137  0
     }
 138  
 
 139  
     private static void setConverterPattern(FacesContext facesContext,
 140  
                                             DateTimeConverter converter,
 141  
                                             String value)
 142  
     {
 143  0
         if (value == null) return;
 144  0
         if (UIComponentTag.isValueReference(value))
 145  
         {
 146  0
             ValueBinding vb = facesContext.getApplication().createValueBinding(value);
 147  0
             converter.setPattern((String)vb.getValue(facesContext));
 148  0
         }
 149  
         else
 150  
         {
 151  0
             converter.setPattern(value);
 152  
         }
 153  0
     }
 154  
 
 155  
     private static void setConverterTimeStyle(FacesContext facesContext,
 156  
                                               DateTimeConverter converter,
 157  
                                               String value)
 158  
     {
 159  0
         if (value == null) return;
 160  0
         if (UIComponentTag.isValueReference(value))
 161  
         {
 162  0
             ValueBinding vb = facesContext.getApplication().createValueBinding(value);
 163  0
             converter.setTimeStyle((String)vb.getValue(facesContext));
 164  0
         }
 165  
         else
 166  
         {
 167  0
             converter.setTimeStyle(value);
 168  
         }
 169  0
     }
 170  
 
 171  
     private static void setConverterTimeZone(FacesContext facesContext,
 172  
                                              DateTimeConverter converter,
 173  
                                              String value)
 174  
     {
 175  0
         if (value == null) return;
 176  0
          if (UIComponentTag.isValueReference(value))
 177  
          {
 178  0
             ValueBinding vb = facesContext.getApplication().createValueBinding(value);
 179  0
             TimeZone timeZone = null;
 180  0
             Object _value = vb.getValue(facesContext);
 181  0
             if (_value instanceof TimeZone)
 182  
             {
 183  0
               timeZone = (TimeZone) _value;
 184  
             }
 185  
             else
 186  
             {
 187  0
               timeZone = TimeZone.getTimeZone(_value.toString());
 188  
             }
 189  0
            converter.setTimeZone(timeZone);
 190  0
         }
 191  
         else
 192  
         {
 193  0
             converter.setTimeZone(TimeZone.getTimeZone(value));
 194  
         }
 195  0
     }
 196  
 
 197  
     private static void setConverterType(FacesContext facesContext,
 198  
                                          DateTimeConverter converter,
 199  
                                          String value)
 200  
     {
 201  0
         if (value == null) return;
 202  0
         if (UIComponentTag.isValueReference(value))
 203  
         {
 204  0
             ValueBinding vb = facesContext.getApplication().createValueBinding(value);
 205  0
             converter.setType((String)vb.getValue(facesContext));
 206  0
         }
 207  
         else
 208  
         {
 209  0
             converter.setType(value);
 210  
         }
 211  0
     }
 212  
 
 213  
 }