KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > drftpd > util > ReplacerUtils


1 /*
2  * This file is part of DrFTPD, Distributed FTP Daemon.
3  *
4  * DrFTPD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * DrFTPD is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with DrFTPD; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package net.sf.drftpd.util;
19
20 import java.util.ResourceBundle JavaDoc;
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 /**
29  * @author mog
30  * @version $Id: ReplacerUtils.java,v 1.3 2004/02/10 00:03:32 mog Exp $
31  */

32 public class ReplacerUtils {
33     private static final Logger logger = Logger.getLogger(ReplacerUtils.class);
34
35     public static ReplacerFormat finalFormat(Class JavaDoc baseName, String JavaDoc key)
36         throws FormatterException {
37         return finalFormat(baseName.getName(), key);
38     }
39
40     public static ReplacerFormat finalFormat(String JavaDoc baseName, String JavaDoc key)
41         throws FormatterException {
42         ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(baseName);
43         String JavaDoc str = bundle.getString(key);
44         return ReplacerFormat.createFormat(str);
45     }
46
47     public static String JavaDoc finalJprintf(
48         ReplacerFormat str,
49         ReplacerEnvironment env) throws FormatterException {
50         return SimplePrintf.jprintf(str, env);
51     }
52
53     public static String JavaDoc jprintf(
54         String JavaDoc key,
55         ReplacerEnvironment env,
56         Class JavaDoc baseName) {
57         return jprintf(key, env, baseName.getName());
58     }
59
60     public static String JavaDoc jprintf(
61         String JavaDoc key,
62         ReplacerEnvironment env,
63         String JavaDoc 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