Coverage Report - org.seasar.teeda.core.util.DecodeUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
DecodeUtil
56%
15/27
50%
5/10
3.333
 
 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.util;
 17  
 
 18  
 import java.util.Map;
 19  
 
 20  
 import javax.faces.component.EditableValueHolder;
 21  
 import javax.faces.component.UIComponent;
 22  
 import javax.faces.context.FacesContext;
 23  
 
 24  
 import org.seasar.framework.util.AssertionUtil;
 25  
 import org.seasar.teeda.core.exception.NoEditableValueHolderRuntimeException;
 26  
 
 27  
 /**
 28  
  * @author higa
 29  
  * @author manhole
 30  
  */
 31  
 public class DecodeUtil {
 32  
 
 33  0
     private DecodeUtil() {
 34  0
     }
 35  
 
 36  
     public static void decode(FacesContext context, UIComponent component) {
 37  5
         AssertionUtil.assertNotNull("context is null.", context);
 38  4
         AssertionUtil.assertNotNull("component is null.", component);
 39  3
         if (!(component instanceof EditableValueHolder)) {
 40  1
             throw new NoEditableValueHolderRuntimeException(component
 41  
                     .getClass());
 42  
         }
 43  2
         EditableValueHolder evh = (EditableValueHolder) component;
 44  2
         Map paramMap = context.getExternalContext().getRequestParameterMap();
 45  2
         String clientId = component.getClientId(context);
 46  2
         if (paramMap.containsKey(clientId)) {
 47  1
             Object submittedValue = paramMap.get(clientId);
 48  1
             evh.setSubmittedValue(submittedValue);
 49  
         }
 50  2
     }
 51  
 
 52  
     public static void decodeMany(FacesContext context, UIComponent component) {
 53  3
         AssertionUtil.assertNotNull("context is null.", context);
 54  2
         AssertionUtil.assertNotNull("component is null.", component);
 55  1
         if (!(component instanceof EditableValueHolder)) {
 56  1
             throw new NoEditableValueHolderRuntimeException(component
 57  
                     .getClass());
 58  
         }
 59  0
         EditableValueHolder evh = (EditableValueHolder) component;
 60  0
         Map paramValuesMap = context.getExternalContext()
 61  
                 .getRequestParameterValuesMap();
 62  0
         String clientId = component.getClientId(context);
 63  0
         String[] value = null;
 64  0
         if (paramValuesMap.containsKey(clientId)) {
 65  0
             value = (String[]) paramValuesMap.get(clientId);
 66  
         }
 67  0
         if (value != null) {
 68  0
             evh.setSubmittedValue(value);
 69  
         } else {
 70  0
             evh.setSubmittedValue(new String[0]);
 71  
         }
 72  0
     }
 73  
 
 74  
 }