litesoft
@ 948
litesoft / trunk / GWT_Sandbox / FormEngine / src / com / temp / client / foundation / util / ExternalizedText.java
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 |
package com.temp.client.foundation.util; import org.litesoft.core.util.*; import com.google.gwt.i18n.client.Dictionary; import com.temp.shared.utils.*; import java.util.*; 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 = StringUtils.noEmpty( key ); return (key != null) ? StringUtils.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 StringUtils.deNull( get( key ), defaultValue ); } } |