litesoft
@ 939
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
package org.litesoft.GWT.client.util.externalization; import org.litesoft.commonfoundation.typeutils.*; import java.util.*; import org.litesoft.core.util.*; import com.google.gwt.i18n.client.Dictionary; public class ExternalizedText implements TemplateSource { private static ExternalizedText instance; private final Dictionary dictionary; private final Set<String> keys; public static ExternalizedText getInstance() { if ( instance == null ) { instance = new ExternalizedText( Dictionary.getDictionary( "ExternalTemplateText" ) ); } return instance; } private ExternalizedText( Dictionary dictionary ) { this.dictionary = dictionary; this.keys = dictionary.keySet(); } private String safeGet( String key ) { return keys.contains( key ) ? dictionary.get( key ) : null; } /** * Get the Template value associated with the key * * @param key Leading and trailing spaces are ignored * * @return null or the Template value associated with the key */ public String get( String key ) { key = Strings.noEmpty( key ); return (key != null) ? Strings.noEmpty( safeGet( key ) ) : null; } /** * Get the Template value associated with the key or the defaultValue if the * key was not found or its value was empty * * @param key Leading and trailing spaces are ignored * * @return The Template value associated with the key or the defaultValue if * the key was not found or its value was empty */ public String get( String key, String defaultValue ) { return Strings.deNull( get( key ), defaultValue ); } } |