1 18 package net.sf.drftpd.util; 19 20 import java.util.ResourceBundle ; 21 22 import org.apache.log4j.Logger; 23 import org.tanesha.replacer.FormatterException; 24 import org.tanesha.replacer.ReplacerEnvironment; 25 import org.tanesha.replacer.ReplacerFormat; 26 import org.tanesha.replacer.SimplePrintf; 27 28 32 public class ReplacerUtils { 33 private static final Logger logger = Logger.getLogger(ReplacerUtils.class); 34 35 public static ReplacerFormat finalFormat(Class baseName, String key) 36 throws FormatterException { 37 return finalFormat(baseName.getName(), key); 38 } 39 40 public static ReplacerFormat finalFormat(String baseName, String key) 41 throws FormatterException { 42 ResourceBundle bundle = ResourceBundle.getBundle(baseName); 43 String str = bundle.getString(key); 44 return ReplacerFormat.createFormat(str); 45 } 46 47 public static String finalJprintf( 48 ReplacerFormat str, 49 ReplacerEnvironment env) throws FormatterException { 50 return SimplePrintf.jprintf(str, env); 51 } 52 53 public static String jprintf( 54 String key, 55 ReplacerEnvironment env, 56 Class baseName) { 57 return jprintf(key, env, baseName.getName()); 58 } 59 60 public static String jprintf( 61 String key, 62 ReplacerEnvironment env, 63 String baseName) { 64 ReplacerFormat str; 65 try { 66 str = finalFormat(baseName, key); 67 return finalJprintf(str, env); 68 } catch (FormatterException e) { 69 logger.warn("basename: "+baseName, e); 70 return key; 71 } 72 } 73 74 private ReplacerUtils() { 75 super(); 76 } 77 78 } 79 | Popular Tags |