1 /* 2 * Copyright 2015-2015 Hippo B.V. (http://www.onehippo.com) 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 org.onehippo.forge.hst.spring.support; 17 18 import java.text.MessageFormat; 19 import java.util.Locale; 20 import java.util.ResourceBundle; 21 22 /** 23 * Repository based ResourceBundle MessageFormat Provider. 24 * <p> 25 * This interface is responsible for creating and caching the resolved <code>MessageFormat</code> instances 26 * and refreshing outdated <code>MessageFormat</code> instances. 27 * </p> 28 */ 29 public interface RepositoryResourceBundleMessageFormatProvider { 30 31 /** 32 * Register the live {@code bundle} by the {@code basename} and {@code locale} 33 * in order to be able to determine that the {@code bundle} was originated from repository. 34 * <p> 35 * Note: Whenever retrieve a resource bundle from repository, this method should be invoked. 36 * Then this implementation should register it if not yet done or clear any outdated 37 * cache associated with the {@code basename} and {@code locale} for a refreshed bundle. 38 * </p> 39 * @param basename resource bundle basename 40 * @param locale resource bundle locale 41 * @param bundle resource bundle 42 */ 43 public void registerBundle(String basename, Locale locale, ResourceBundle bundle); 44 45 /** 46 * Register the preview {@code bundle} by the {@code basename} and {@code locale} 47 * in order to be able to determine that the {@code bundle} was originated from repository. 48 * <p> 49 * Note: Whenever retrieve a resource bundle from repository, this method should be invoked. 50 * Then this implementation should register it if not yet done or clear any outdated 51 * cache associated with the {@code basename} and {@code locale} for a refreshed bundle. 52 * </p> 53 * @param basename resource bundle basename 54 * @param locale resource bundle locale 55 * @param bundle resource bundle 56 */ 57 public void registerPreviewBundle(String basename, Locale locale, ResourceBundle bundle); 58 59 /** 60 * Return a MessageFormat for the given bundle and code, 61 * fetching already generated MessageFormats from the cache. 62 * @param bundle the ResourceBundle to work on 63 * @param code the message code to retrieve 64 * @param locale the Locale to use to build the MessageFormat 65 * @return the resulting MessageFormat, or {@code null} if no message 66 * defined for the given code 67 */ 68 public MessageFormat getMessageFormat(ResourceBundle bundle, String code, Locale locale); 69 70 }