Coverage Report - javax.faces.convert._ParametrizableFacesMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
_ParametrizableFacesMessage
40%
19/47
32%
9/28
2.778
 
 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 javax.faces.convert;
 20  
 
 21  
 import java.text.MessageFormat;
 22  
 import java.util.Locale;
 23  
 
 24  
 import javax.el.ValueExpression;
 25  
 import javax.faces.application.FacesMessage;
 26  
 import javax.faces.context.FacesContext;
 27  
 import javax.faces.el.ValueBinding;
 28  
 
 29  
 /** 
 30  
  * This class encapsulates a FacesMessage to evaluate the label
 31  
  * expression on render response, where f:loadBundle is available
 32  
  */
 33  
 class _ParametrizableFacesMessage extends FacesMessage
 34  
 {
 35  
     /**
 36  
      * 
 37  
      */
 38  
     private static final long serialVersionUID = 7792947730961657948L;
 39  
 
 40  
     private final Object _args[];
 41  
     private String _evaluatedDetail;
 42  
     private String _evaluatedSummary;
 43  
     private transient Object _evaluatedArgs[];
 44  
     private Locale _locale;
 45  
 
 46  
     public _ParametrizableFacesMessage(
 47  
             String summary, String detail, Object[] args, Locale locale)
 48  
     {
 49  0
         super(summary, detail);
 50  0
         if(locale == null)
 51  
         {
 52  0
             throw new NullPointerException("locale");
 53  
         }
 54  0
         _locale = locale;
 55  0
         _args = args;
 56  0
     }
 57  
 
 58  
     public _ParametrizableFacesMessage(FacesMessage.Severity severity,
 59  
             String summary, String detail, Object[] args, Locale locale)
 60  
     {
 61  22
         super(severity, summary, detail);
 62  22
         if(locale == null)
 63  
         {
 64  0
             throw new NullPointerException("locale");
 65  
         }
 66  22
         _locale = locale;
 67  22
         _args = args;
 68  22
     }
 69  
 
 70  
     @Override
 71  
     public String getDetail()
 72  
     {
 73  0
         if (_evaluatedArgs == null && _args != null)
 74  
         {
 75  0
             evaluateArgs();
 76  
         }
 77  0
         if (_evaluatedDetail == null)
 78  
         {
 79  0
             MessageFormat format = new MessageFormat(super.getDetail(), _locale);
 80  0
             _evaluatedDetail = format.format(_evaluatedArgs);
 81  
         }
 82  0
         return _evaluatedDetail;
 83  
     }
 84  
 
 85  
     @Override
 86  
     public void setDetail(String detail)
 87  
     {
 88  0
         super.setDetail(detail);
 89  0
         _evaluatedDetail = null;
 90  0
     }
 91  
     
 92  
     public String getUnformattedDetail()
 93  
     {
 94  0
         return super.getDetail();
 95  
     }
 96  
 
 97  
     @Override
 98  
     public String getSummary()
 99  
     {
 100  10
         if (_evaluatedArgs == null && _args != null)
 101  
         {
 102  10
             evaluateArgs();
 103  
         }
 104  10
         if (_evaluatedSummary == null)
 105  
         {
 106  10
             MessageFormat format = new MessageFormat(super.getSummary(), _locale);
 107  10
             _evaluatedSummary = format.format(_evaluatedArgs);
 108  
         }
 109  10
         return _evaluatedSummary;
 110  
     }
 111  
 
 112  
     @Override
 113  
     public void setSummary(String summary)
 114  
     {
 115  0
         super.setSummary(summary);
 116  0
         _evaluatedSummary = null;
 117  0
     }
 118  
     
 119  
     public String getUnformattedSummary()
 120  
     {
 121  0
         return super.getSummary();
 122  
     }
 123  
 
 124  
     private void evaluateArgs()
 125  
     {
 126  10
         _evaluatedArgs = new Object[_args.length];
 127  10
         FacesContext facesContext = null;
 128  36
         for (int i = 0; i < _args.length; i++)
 129  
         {
 130  26
             if (_args[i] == null)
 131  
             {
 132  0
                 continue;
 133  
             }
 134  26
             else if (_args[i] instanceof ValueBinding)
 135  
             {
 136  0
                 if (facesContext == null)
 137  
                 {
 138  0
                     facesContext = FacesContext.getCurrentInstance();
 139  
                 }
 140  0
                 _evaluatedArgs[i] = ((ValueBinding)_args[i]).getValue(facesContext);
 141  
             }
 142  26
             else if (_args[i] instanceof ValueExpression)
 143  
             {
 144  0
                 if (facesContext == null)
 145  
                 {
 146  0
                     facesContext = FacesContext.getCurrentInstance();
 147  
                 }
 148  0
                 _evaluatedArgs[i] = ((ValueExpression)_args[i]).getValue(facesContext.getELContext());
 149  
             }
 150  
             else 
 151  
             {
 152  26
                 _evaluatedArgs[i] = _args[i];
 153  
             }
 154  
         }
 155  10
     }
 156  
 }