KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > servlets > reports > ReportParameter


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/servlets/reports/ReportParameter.java,v 1.20 2004/12/16 10:50:36 hkollmann Exp $
3  * $Revision: 1.20 $
4  * $Date: 2004/12/16 10:50:36 $
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.servlets.reports;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.config.Field;
30
31
32 import org.dbforms.taglib.TextFormatterUtil;
33 import org.dbforms.util.MessageResources;
34 import org.dbforms.util.ParseUtil;
35 import org.dbforms.util.Util;
36
37 import java.io.File JavaDoc;
38 import java.util.Map JavaDoc;
39
40 /**
41  * Helper class send as parameter to JasperReports. So it is not neccesary to
42  * send all the stuff in different parameters
43  */

44 import java.sql.Connection JavaDoc;
45
46 import java.util.Locale JavaDoc;
47
48 import javax.servlet.ServletContext JavaDoc;
49 import javax.servlet.http.HttpServletRequest JavaDoc;
50
51
52
53 /**
54  * DOCUMENT ME!
55  *
56  * @author $author$
57  * @version $Revision: 1.20 $
58  */

59 public class ReportParameter {
60    private static Log logCat = LogFactory.getLog(ReportParameter.class);
61    private Connection JavaDoc connection;
62    private HttpServletRequest JavaDoc request;
63    private Locale JavaDoc locale;
64    private ServletContext JavaDoc context;
65    private String JavaDoc reportPath;
66    private Map JavaDoc attributes;
67
68    /**
69     * Creates a new ReportParameter object.
70     *
71     * @param context DOCUMENT ME!
72     * @param request DOCUMENT ME!
73     * @param connection DOCUMENT ME!
74     * @param reportPath DOCUMENT ME!
75     */

76    public ReportParameter(ServletContext JavaDoc context,
77                           HttpServletRequest JavaDoc request,
78                           Map JavaDoc attributes,
79                           Connection JavaDoc connection,
80                           String JavaDoc reportPath) {
81       this.context = context;
82       this.request = request;
83       this.connection = connection;
84       this.reportPath = reportPath;
85       this.attributes = attributes;
86       this.locale = MessageResources.getLocale(request);
87    }
88
89    /**
90     * Returns the connection.
91     *
92     * @return Connection
93     */

94    public Connection JavaDoc getConnection() {
95       return connection;
96    }
97
98
99    /**
100     * DOCUMENT ME!
101     *
102     * @return
103     */

104    public String JavaDoc getContextPath() {
105       return context.getRealPath("") + File.separator;
106    }
107
108    public String JavaDoc getBaseURL() {
109        return Util.getBaseURL(request);
110    }
111
112    /**
113     * Returns a message
114     *
115     * @param msg DOCUMENT ME!
116     *
117     * @return String
118     */

119    public String JavaDoc getMessage(String JavaDoc msg) {
120       return MessageResources.getMessage(request, msg);
121    }
122
123
124    /**
125     * Returns a request parameter
126     *
127     * @param param DOCUMENT ME!
128     *
129     * @return String
130     */

131    public String JavaDoc getParameter(String JavaDoc param) {
132       return ParseUtil.getParameter(request, param);
133    }
134
135    /**
136     * Returns a request parameter
137     *
138     * @param param DOCUMENT ME!
139     *
140     * @return String
141     */

142    public Object JavaDoc getAttribute(String JavaDoc key) {
143       return attributes.get(key);
144    }
145
146    /**
147     * Returns the reportPath.
148     *
149     * @return String
150     */

151    public String JavaDoc getReportPath() {
152       return reportPath;
153    }
154
155
156    /**
157     * Returns a formatted string with the same formatting as used inside
158     * dbforms
159     *
160     * @param obj The object to format
161     * @param pattern to use as pattern for numeric and date fields
162     *
163     * @return The string representation
164     */

165    public String JavaDoc getStringValue(Object JavaDoc obj,
166                                 String JavaDoc pattern) {
167       try {
168          Field field = new Field();
169          field.setTypeByObject(obj);
170          return TextFormatterUtil.FormatText(field, locale, pattern, obj);
171       } catch (Exception JavaDoc e) {
172          logCat.error(e);
173
174          return e.getMessage();
175       }
176    }
177
178
179    /**
180     * Returns a formatted string with the same formatting as used inside
181     * dbforms
182     *
183     * @param obj The object to format
184     *
185     * @return The string representation
186     */

187    public String JavaDoc getStringValue(Object JavaDoc obj) {
188       return getStringValue(obj, null);
189    }
190 }
191
Popular Tags