KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > report > A_CmsReport


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/report/A_CmsReport.java,v $
3  * Date : $Date: 2006/10/04 07:35:21 $
4  * Version: $Revision: 1.22 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.report;
33
34 import org.opencms.file.CmsRequestContext;
35 import org.opencms.i18n.CmsMessageContainer;
36 import org.opencms.i18n.CmsMessages;
37 import org.opencms.util.CmsStringUtil;
38
39 import java.util.ArrayList JavaDoc;
40 import java.util.List JavaDoc;
41 import java.util.Locale JavaDoc;
42
43 /**
44  * Base report class.<p>
45  *
46  * @author Alexander Kandzior
47  * @author Thomas Weckert
48  * @author Jan Baudisch
49  * @author Peter Bonrad
50  *
51  * @version $Revision: 1.22 $
52  *
53  * @since 6.0.0
54  */

55 public abstract class A_CmsReport implements I_CmsReport {
56
57     /** Contains all error messages generated by the report. */
58     private List JavaDoc m_errors = new ArrayList JavaDoc();
59
60     /** The locale this report is written in. */
61     private Locale JavaDoc m_locale;
62
63     /** The default report message bundle. */
64     private CmsMessages m_messages;
65
66     /** The original site root of the user who started this report. */
67     private String JavaDoc m_siteRoot;
68
69     /** Runtime of the report. */
70     private long m_starttime;
71
72     /** Contains all warning messages generated by the report. */
73     private List JavaDoc m_warnings = new ArrayList JavaDoc();
74
75     /**
76      * @see org.opencms.report.I_CmsReport#addError(java.lang.Object)
77      */

78     public void addError(Object JavaDoc obj) {
79
80         m_errors.add(obj);
81     }
82
83     /**
84      * @see org.opencms.report.I_CmsReport#addWarning(java.lang.Object)
85      */

86     public void addWarning(Object JavaDoc obj) {
87
88         m_warnings.add(obj);
89     }
90
91     /**
92      * @see org.opencms.report.I_CmsReport#formatRuntime()
93      */

94     public String JavaDoc formatRuntime() {
95
96         return CmsStringUtil.formatRuntime(getRuntime());
97     }
98
99     /**
100      * @see org.opencms.report.I_CmsReport#getErrors()
101      */

102     public List JavaDoc getErrors() {
103
104         return m_errors;
105     }
106
107     /**
108      * @see org.opencms.report.I_CmsReport#getLocale()
109      */

110     public Locale JavaDoc getLocale() {
111
112         return m_locale;
113     }
114
115     /**
116      * @see org.opencms.report.I_CmsReport#getRuntime()
117      */

118     public long getRuntime() {
119
120         return System.currentTimeMillis() - m_starttime;
121     }
122
123     /**
124      * Returns the original site root of the user who started this report,
125      * or <code>null</code> if the original site root has not been set.<p>
126      *
127      * @return the original site root of the user who started this report
128      */

129     public String JavaDoc getSiteRoot() {
130
131         return m_siteRoot;
132     }
133
134     /**
135      * @see org.opencms.report.I_CmsReport#getWarnings()
136      */

137     public List JavaDoc getWarnings() {
138
139         return m_warnings;
140     }
141
142     /**
143      * @see org.opencms.report.I_CmsReport#hasError()
144      */

145     public boolean hasError() {
146
147         return (m_errors.size() > 0);
148     }
149
150     /**
151      * @see org.opencms.report.I_CmsReport#hasWarnings()
152      */

153     public boolean hasWarning() {
154
155         return (m_warnings.size() > 0);
156     }
157
158     /**
159      * @see org.opencms.report.I_CmsReport#print(org.opencms.i18n.CmsMessageContainer)
160      */

161     public void print(CmsMessageContainer container) {
162
163         print(container.key(getLocale()), FORMAT_DEFAULT);
164     }
165
166     /**
167      * @see org.opencms.report.I_CmsReport#print(org.opencms.i18n.CmsMessageContainer, int)
168      */

169     public void print(CmsMessageContainer container, int format) {
170
171         print(container.key(getLocale()), format);
172     }
173
174     /**
175      * @see org.opencms.report.I_CmsReport#println(org.opencms.i18n.CmsMessageContainer)
176      */

177     public void println(CmsMessageContainer container) {
178
179         println(container.key(getLocale()), FORMAT_DEFAULT);
180     }
181
182     /**
183      * @see org.opencms.report.I_CmsReport#println(org.opencms.i18n.CmsMessageContainer, int)
184      */

185     public void println(CmsMessageContainer container, int format) {
186
187         println(container.key(getLocale()), format);
188     }
189
190     /**
191      * @see org.opencms.report.I_CmsReport#printMessageWithParam(org.opencms.i18n.CmsMessageContainer,Object)
192      */

193     public void printMessageWithParam(CmsMessageContainer container, Object JavaDoc param) {
194
195         print(container, I_CmsReport.FORMAT_NOTE);
196         print(Messages.get().container(Messages.RPT_ARGUMENT_1, param));
197         print(Messages.get().container(Messages.RPT_DOTS_0));
198     }
199
200     /**
201      * @see org.opencms.report.I_CmsReport#printMessageWithParam(int,int,org.opencms.i18n.CmsMessageContainer,Object)
202      */

203     public void printMessageWithParam(int m, int n, CmsMessageContainer container, Object JavaDoc param) {
204
205         print(
206             Messages.get().container(Messages.RPT_SUCCESSION_2, String.valueOf(m), String.valueOf(n)),
207             I_CmsReport.FORMAT_NOTE);
208         printMessageWithParam(container, param);
209     }
210
211     /**
212      * Removes the report site root prefix from the absolute path in the resource name,
213      * that is adjusts the resource name for the report site root.<p>
214      *
215      * If the site root for this report has not been set,
216      * or the resource name does not start with the report site root,
217      * the name it is left untouched.<p>
218      *
219      * @param resourcename the resource name (full path)
220      *
221      * @return the resource name adjusted for the report site root
222      *
223      * @see CmsRequestContext#removeSiteRoot(String)
224      */

225     public String JavaDoc removeSiteRoot(String JavaDoc resourcename) {
226
227         if (m_siteRoot == null) {
228             // site root has not been set
229
return resourcename;
230         }
231
232         String JavaDoc siteRoot = CmsRequestContext.getAdjustedSiteRoot(m_siteRoot, resourcename);
233         if ((siteRoot == m_siteRoot) && resourcename.startsWith(siteRoot)) {
234             resourcename = resourcename.substring(siteRoot.length());
235         }
236         return resourcename;
237     }
238
239     /**
240      * @see org.opencms.report.I_CmsReport#resetRuntime()
241      */

242     public void resetRuntime() {
243
244         m_starttime = System.currentTimeMillis();
245     }
246
247     /**
248      * Returns the default report message bundle.<p>
249      *
250      * @return the default report message bundle
251      */

252     protected CmsMessages getMessages() {
253
254         return m_messages;
255     }
256
257     /**
258      * Initializes some member variables for this report.<p>
259      *
260      * @param locale the locale for this report
261      * @param siteRoot the site root of the user who started this report (may be <code>null</code>)
262      */

263     protected void init(Locale JavaDoc locale, String JavaDoc siteRoot) {
264
265         m_starttime = System.currentTimeMillis();
266         m_locale = locale;
267         m_siteRoot = siteRoot;
268         m_messages = Messages.get().getBundle(locale);
269     }
270
271     /**
272      * Prints a String to the report.<p>
273      *
274      * @param value the String to add
275      */

276     protected void print(String JavaDoc value) {
277
278         print(value, FORMAT_DEFAULT);
279     }
280
281     /**
282      * Prints a String to the report, using the indicated formatting.<p>
283      *
284      * Use the contants starting with <code>FORMAT</code> from this interface
285      * to indicate which formatting to use.<p>
286      *
287      * @param value the message container to add
288      * @param format the formatting to use for the output
289      */

290     protected abstract void print(String JavaDoc value, int format);
291
292     /**
293      * Prints a String with line break to the report.<p>
294      *
295      * @param value the message container to add
296      */

297     protected void println(String JavaDoc value) {
298
299         println(value, FORMAT_DEFAULT);
300     }
301
302     /**
303      * Prints a String with line break to the report, using the indicated formatting.<p>
304      *
305      * Use the contants starting with <code>C_FORMAT</code> from this interface
306      * to indicate which formatting to use.<p>
307      *
308      * @param value the String to add
309      * @param format the formatting to use for the output
310      */

311     protected void println(String JavaDoc value, int format) {
312
313         print(value, format);
314         println();
315     }
316 }
Popular Tags