View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/TextFormatterUtil.java,v 1.4 2005/11/28 21:10:56 hkollmann Exp $
3    * $Revision: 1.4 $
4    * $Date: 2005/11/28 21:10:56 $
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 org.dbforms.taglib;
25  
26  import org.dbforms.config.Field;
27  
28  import org.dbforms.util.MessageResources;
29  
30  import java.util.Locale;
31  
32  import javax.servlet.http.HttpServletRequest;
33  
34  
35  
36  /***
37   * Special class for TextFormatting
38   *
39   * @author hkk
40   */
41  public class TextFormatterUtil extends AbstractDbBaseHandlerTag {
42     private Locale locale;
43     private Object obj;
44  
45     /***
46      * Creates a new TextFormatter object.
47      *
48      * @param field DOCUMENT ME!
49      * @param locale DOCUMENT ME!
50      * @param pattern DOCUMENT ME!
51      * @param obj DOCUMENT ME!
52      */
53     protected TextFormatterUtil(Field  field,
54                              Locale locale,
55                              String pattern,
56                              Object obj) {
57        this.obj    = obj;
58        this.locale = locale;
59        setPattern(pattern);
60        setField(field);
61     }
62  
63     /***
64      * DOCUMENT ME!
65      *
66      * @param field DOCUMENT ME!
67      * @param locale DOCUMENT ME!
68      * @param pattern DOCUMENT ME!
69      * @param obj DOCUMENT ME!
70      *
71      * @return DOCUMENT ME!
72      */
73     public static String FormatText(Field  field,
74                                     Locale locale,
75                                     String pattern,
76                                     Object obj) {
77        TextFormatterUtil tf = new TextFormatterUtil(field, locale, pattern, obj);
78  
79        return tf.getFormattedFieldValue();
80     }
81  
82  
83     /***
84      * DOCUMENT ME!
85      *
86      * @param field DOCUMENT ME!
87      * @param request DOCUMENT ME!
88      * @param pattern DOCUMENT ME!
89      * @param obj DOCUMENT ME!
90      *
91      * @return DOCUMENT ME!
92      */
93     public static String FormatText(Field              field,
94                                     HttpServletRequest request,
95                                     String             pattern,
96                                     Object             obj) {
97        Locale            locale = MessageResources.getLocale(request);
98        TextFormatterUtil tf = new TextFormatterUtil(field, locale, pattern, obj);
99  
100       return tf.getFormattedFieldValue();
101    }
102 
103 
104    /***
105     * DOCUMENT ME!
106     *
107     * @param parentForm DOCUMENT ME!
108     *
109     * @return DOCUMENT ME!
110     */
111    public String getFormFieldName(DbFormTag parentForm) {
112       setParent(parentForm);
113 
114       return super.getFormFieldName();
115    }
116 
117 
118    /***
119     * DOCUMENT ME!
120     *
121     * @return DOCUMENT ME!
122     */
123    public String getFormattedFieldValue() {
124       return super.getFormattedFieldValue();
125    }
126 
127 
128    /***
129     * DOCUMENT ME!
130     *
131     * @return DOCUMENT ME!
132     */
133    public String renderPatternHtmlInputField() {
134       return super.renderPatternHtmlInputField();
135    }
136 
137 
138    /***
139     * DOCUMENT ME!
140     *
141     * @return DOCUMENT ME!
142     */
143    protected Object getFieldObject() {
144       return obj;
145    }
146 
147 
148    /***
149     * DOCUMENT ME!
150     *
151     * @return DOCUMENT ME!
152     */
153    protected Locale getLocale() {
154       return locale;
155    }
156 }