001// Copyright 2006, 2007, 2012 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
015package org.apache.tapestry5.ioc;
016
017import java.util.Set;
018
019/**
020 * Provides access to a messages catalog, a set of properties files that provide localized messages for a particular
021 * locale. The message catalog consists of keys and values and follows the semantics of a Java {@link
022 * java.util.ResourceBundle} with some changes.
023 */
024public interface Messages
025{
026    /**
027     * Returns true if the bundle contains the named key.
028     */
029    boolean contains(String key);
030
031    /**
032     * Returns the localized message for the given key. If catalog does not contain such a key, then a modified version
033     * of the key is returned (converted to upper case and enclosed in brackets).
034     *
035     * @param key
036     * @return localized message for key, or placeholder
037     */
038    String get(String key);
039
040    /**
041     * Returns a formatter for the message, which can be used to substitute arguments (as per {@link
042     * java.util.Formatter}).
043     *
044     * @param key
045     * @return formattable object
046     */
047    MessageFormatter getFormatter(String key);
048
049    /**
050     * Convenience for accessing a formatter and formatting a localized message with arguments.
051     */
052    String format(String key, Object... args);
053
054    /**
055     * Returns a set of all the keys for which this instance may provide a value.
056     *
057     * @return set of keys
058     * @since 5.4
059     */
060    Set<String> getKeys();
061}