01 /*
02 * Copyright 2008-2015 the original author or authors.
03 *
04 * Licensed under the Apache License, Version 2.0 (the "License");
05 * you may not use this file except in compliance with the License.
06 * You may obtain a copy of the License at
07 *
08 * http://www.apache.org/licenses/LICENSE-2.0
09 *
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.codehaus.griffon.runtime.groovy.i18n;
17
18 import griffon.core.i18n.GroovyAwareMessageSource;
19 import griffon.core.i18n.MessageSource;
20 import griffon.core.i18n.NoSuchMessageException;
21 import org.codehaus.griffon.runtime.core.i18n.MessageSourceDecorator;
22
23 import javax.annotation.Nonnull;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import static griffon.util.GriffonClassUtils.requireNonEmpty;
28
29 /**
30 * @author Andres Almiray
31 * @since 2.4.0
32 */
33 public class DefaultGroovyAwareMessageSource extends MessageSourceDecorator implements GroovyAwareMessageSource {
34 public DefaultGroovyAwareMessageSource(@Nonnull MessageSource delegate) {
35 super(delegate);
36 }
37
38 @Nonnull
39 @Override
40 public String getAt(@Nonnull String key) throws NoSuchMessageException {
41 return getDelegate().getMessage(key);
42 }
43
44 @Nonnull
45 public String getAt(@Nonnull List<?> keyAndArgs) throws NoSuchMessageException {
46 requireNonEmpty(keyAndArgs, "Argument 'keyAndArgs' must not be null");
47 String key = String.valueOf(keyAndArgs.get(0));
48 List<Object> args = new ArrayList<>();
49 if (keyAndArgs.size() > 1) {
50 args.addAll(keyAndArgs.subList(1, keyAndArgs.size()));
51 }
52 return getMessage(key, args);
53 }
54 }
|