KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > customFormatters > DashifyFormatter


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/examples/bookstore/WEB-INF/src/customFormatters/DashifyFormatter.java,v 1.1 2004/10/12 15:48:52 hkollmann Exp $
3  * $Revision: 1.1 $
4  * $Date: 2004/10/12 15:48:52 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package customFormatters;
25
26 import java.util.Locale JavaDoc;
27 import org.dbforms.util.ICustomFormat;
28
29
30
31 /**
32  * @author Neal Katz
33  *
34  * the fmtArg is a string. the string will be inserted between every digit in
35  * the input when used any # is replaced by input. ex. string="--" ,
36  * input="1234", output="1--2--3--4--5"
37  */

38 public class DashifyFormatter implements ICustomFormat {
39    Locale JavaDoc locale = null;
40    String JavaDoc dashStr = null;
41
42    public void setArg(String JavaDoc fmtArg) throws IllegalArgumentException JavaDoc {
43       dashStr = fmtArg;
44    }
45
46
47    public void setLocale(Locale JavaDoc locale) {
48       this.locale = locale;
49    }
50
51
52    public Locale JavaDoc getLocale() {
53       return locale;
54    }
55
56
57    public String JavaDoc sprintf(String JavaDoc s) {
58       String JavaDoc r = "";
59       if (s != null) {
60          for (int i = 0; i != s.length(); i++) {
61             if (i > 0) {
62                r += this.dashStr;
63             }
64             r += s.charAt(i);
65          }
66       }
67       return r;
68    }
69 }
70
Popular Tags