1 /* 2 * Copyright (c) 2023 the original author or authors. 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, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.networknt.schema.i18n; 17 18 import java.util.Locale; 19 import java.util.function.Supplier; 20 21 /** 22 * Resolves locale specific messages. 23 */ 24 @FunctionalInterface 25 public interface MessageSource { 26 /** 27 * Gets the message. 28 * 29 * @param key to look up the message 30 * @param defaultMessageSupplier the default message 31 * @param locale the locale to use 32 * @param args the message arguments 33 * @return the message 34 */ getMessage(String key, Supplier<String> defaultMessageSupplier, Locale locale, Object... args)35 String getMessage(String key, Supplier<String> defaultMessageSupplier, Locale locale, Object... args); 36 37 /** 38 * Gets the message. 39 * 40 * @param key to look up the message 41 * @param defaultMessage the default message 42 * @param locale the locale to use 43 * @param args the message arguments 44 * @return the message 45 */ getMessage(String key, String defaultMessage, Locale locale, Object... args)46 default String getMessage(String key, String defaultMessage, Locale locale, Object... args) { 47 return getMessage(key, defaultMessage::toString, locale, args); 48 } 49 50 /** 51 * Gets the message. 52 * 53 * @param key to look up the message 54 * @param locale the locale to use 55 * @param args the message arguments 56 * @return the message 57 */ getMessage(String key, Locale locale, Object... args)58 default String getMessage(String key, Locale locale, Object... args) { 59 return getMessage(key, (Supplier<String>) null, locale, args); 60 } 61 } 62