001 // Copyright 2009 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 package org.apache.tapestry5.internal.beanvalidator; 015 016 import java.util.Locale; 017 018 import javax.validation.MessageInterpolator; 019 020 import org.apache.tapestry5.ioc.services.ThreadLocale; 021 /** 022 * The default message interpolation algorithm uses {@link Locale#getDefault()}. This behavior is not appropriate for Tapestry applications, 023 * thus we need a {@link Locale} aware message interpolator. 024 */ 025 public class MessageInterpolatorImpl implements MessageInterpolator 026 { 027 private final MessageInterpolator delegate; 028 private final ThreadLocale threadLocale; 029 030 public MessageInterpolatorImpl(MessageInterpolator delegate, ThreadLocale threadLocale) 031 { 032 this.delegate = delegate; 033 this.threadLocale = threadLocale; 034 } 035 036 /** 037 * @see javax.validation.MessageInterpolator#interpolate(java.lang.String, javax.validation.MessageInterpolator.Context) 038 */ 039 public String interpolate(String messageTemplate, Context context) 040 { 041 return interpolate(messageTemplate, context, threadLocale.getLocale()); 042 } 043 044 /** 045 * @see javax.validation.MessageInterpolator#interpolate(java.lang.String, javax.validation.MessageInterpolator.Context, java.util.Locale) 046 */ 047 public String interpolate(String messageTemplate, Context context, Locale locale) 048 { 049 return this.delegate.interpolate(messageTemplate, context, locale); 050 } 051 052 }