Coverage Report - net.sf.beanform.validator.ValidatorMessages
 
Classes in this File Line Coverage Branch Coverage Complexity
ValidatorMessages
100% 
N/A 
1
 
 1  
 // Copyright 2006 Daniel Gredler
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package net.sf.beanform.validator;
 16  
 
 17  
 import java.text.MessageFormat;
 18  
 import java.util.Locale;
 19  
 import java.util.ResourceBundle;
 20  
 
 21  
 import org.apache.tapestry.form.IFormComponent;
 22  
 
 23  
 /**
 24  
  * Internationalized messages for the validators.
 25  
  *
 26  
  * @author Daniel Gredler
 27  
  */
 28  1
 class ValidatorMessages {
 29  
 
 30  1
     private static final String RESOURCE_BUNDLE = ValidatorMessages.class.getName();
 31  
 
 32  
     static String mustBeNumber( IFormComponent field, Locale locale ) {
 33  4
         return getMessage( "must-be-number", field, locale );
 34  
     }
 35  
 
 36  
     static String mustBeWholeNumber( IFormComponent field, Locale locale ) {
 37  4
         return getMessage( "must-be-whole-number", field, locale );
 38  
     }
 39  
 
 40  
     private static String getMessage( String key, IFormComponent field, Locale locale ) {
 41  8
         String message = ResourceBundle.getBundle( RESOURCE_BUNDLE, locale ).getString( key );
 42  8
         return MessageFormat.format( message, field.getDisplayName() );
 43  
     }
 44  
 
 45  
 }