KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > CmsReport


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsReport.java,v $
3  * Date : $Date: 2006/03/27 14:52:43 $
4  * Version: $Revision: 1.26 $
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.workplace;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsLog;
36 import org.opencms.main.OpenCms;
37 import org.opencms.report.A_CmsReportThread;
38 import org.opencms.report.I_CmsReport;
39 import org.opencms.util.CmsStringUtil;
40 import org.opencms.util.CmsUUID;
41
42 import javax.servlet.http.HttpServletRequest JavaDoc;
43 import javax.servlet.http.HttpServletResponse JavaDoc;
44 import javax.servlet.jsp.PageContext JavaDoc;
45
46 import org.apache.commons.logging.Log;
47
48 /**
49  * Provides an output window for a CmsReport.<p>
50  *
51  * @author Alexander Kandzior
52  *
53  * @version $Revision: 1.26 $
54  *
55  * @since 6.0.0
56  */

57 public class CmsReport extends CmsMultiDialog {
58
59     /** Request parameter key for the type of the report. */
60     public static final String JavaDoc PARAM_REPORT_CONTINUEKEY = "reportcontinuekey";
61
62     /** Request parameter key for the type of the report. */
63     public static final String JavaDoc PARAM_REPORT_TYPE = "reporttype";
64
65     /** Max. byte size of report output on client. */
66     public static final int REPORT_UPDATE_SIZE = 512000;
67
68     /** Update time for report reloading. */
69     public static final int REPORT_UPDATE_TIME = 2000;
70
71     /** The log object for this class. */
72     private static final Log LOG = CmsLog.getLog(CmsReport.class);
73
74     /** Flag for refreching workplace .*/
75     private String JavaDoc m_paramRefreshWorkplace;
76
77     /** The key name which contains the localized message for the continue checkbox. */
78     private String JavaDoc m_paramReportContinueKey;
79
80     /** The type of this report. */
81     private String JavaDoc m_paramReportType;
82
83     /** The thread to display in this report. */
84     private CmsUUID m_paramThread;
85
86     /** The next thread to display after this report. */
87     private String JavaDoc m_paramThreadHasNext;
88
89     /**
90      * Public constructor.<p>
91      *
92      * @param jsp an initialized JSP action element
93      */

94     public CmsReport(CmsJspActionElement jsp) {
95
96         super(jsp);
97     }
98
99     /**
100      * Public constructor with JSP variables.<p>
101      *
102      * @param context the JSP page context
103      * @param req the JSP request
104      * @param res the JSP response
105      */

106     public CmsReport(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
107
108         this(new CmsJspActionElement(context, req, res));
109     }
110
111     /**
112      * Returns an initialized CmsReport instance that is read from the request attributes.<p>
113      *
114      * This method is used by dialog elements.
115      * The dialog elements do not initialize their own workplace class,
116      * but use the initialized instance of the "master" class.
117      * This is required to ensure that parameters of the "master" class
118      * can properly be kept on the dialog elements.<p>
119      *
120      * To prevent null pointer exceptions, an empty dialog is returned if
121      * nothing is found in the request attributes.<p>
122      *
123      * @param context the JSP page context
124      * @param req the JSP request
125      * @param res the JSP response
126      * @return an initialized CmsDialog instance that is read from the request attributes
127      */

128     public static CmsReport initCmsReport(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
129
130         CmsReport wp = (CmsReport)req.getAttribute(CmsWorkplace.SESSION_WORKPLACE_CLASS);
131         if (wp == null) {
132             // ensure that we don't get null pointers if the page is directly called
133
wp = new CmsReport(new CmsJspActionElement(context, req, res));
134         }
135         return wp;
136     }
137
138     /**
139      * Builds a button row with an "Ok", a "Cancel" and a "Details" button.<p>
140      *
141      * This row is displayed when the first report is running.<p>
142      *
143      * @param okAttrs optional attributes for the ok button
144      * @param cancelAttrs optional attributes for the cancel button
145      * @param detailsAttrs optional attributes for the details button
146      * @return the button row
147      */

148     public String JavaDoc dialogButtonsContinue(String JavaDoc okAttrs, String JavaDoc cancelAttrs, String JavaDoc detailsAttrs) {
149
150         if (CmsStringUtil.isEmptyOrWhitespaceOnly(detailsAttrs)) {
151             detailsAttrs = "";
152         } else {
153             detailsAttrs += " ";
154         }
155         return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_DETAILS}, new String JavaDoc[] {
156             okAttrs,
157             cancelAttrs,
158             detailsAttrs + "onclick=\"switchOutputFormat();\""});
159     }
160
161     /**
162      * Builds a button row with an "Ok", a "Cancel" and a "Details" button.<p>
163      *
164      * This row is used when a single report is running or after the first report has finished.<p>
165      *
166      * @param okAttrs optional attributes for the ok button
167      * @param cancelAttrs optional attributes for the cancel button
168      * @param detailsAttrs optional attributes for the details button
169      * @return the button row
170      */

171     public String JavaDoc dialogButtonsOkCancelDetails(String JavaDoc okAttrs, String JavaDoc cancelAttrs, String JavaDoc detailsAttrs) {
172
173         if (CmsStringUtil.isEmptyOrWhitespaceOnly(detailsAttrs)) {
174             detailsAttrs = "";
175         } else {
176             detailsAttrs += " ";
177         }
178
179         if (Boolean.valueOf(getParamThreadHasNext()).booleanValue()
180             && CmsStringUtil.isNotEmpty(getParamReportContinueKey())) {
181             return dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_DETAILS}, new String JavaDoc[] {
182                 okAttrs,
183                 cancelAttrs,
184                 detailsAttrs + "onclick=\"switchOutputFormat();\""});
185         }
186         return dialogButtons(new int[] {BUTTON_OK, BUTTON_DETAILS}, new String JavaDoc[] {
187             okAttrs,
188             detailsAttrs + "onclick=\"switchOutputFormat();\""});
189     }
190
191     /**
192      * Returns if the workplace must be refreshed.<p>
193      *
194      * @return <code>"true"</code> if the workplace must be refreshed.
195      */

196     public String JavaDoc getParamRefreshWorkplace() {
197
198         return m_paramRefreshWorkplace;
199     }
200
201     /**
202      * Returns the key name which contains the localized message for the continue checkbox.<p>
203      *
204      * @return the key name which contains the localized message for the continue checkbox
205      */

206     public String JavaDoc getParamReportContinueKey() {
207
208         if (m_paramReportContinueKey == null) {
209             m_paramReportContinueKey = "";
210         }
211         return m_paramReportContinueKey;
212     }
213
214     /**
215      * Returns the type of this report.<p>
216      *
217      * @return the type of this report
218      */

219     public String JavaDoc getParamReportType() {
220
221         if (m_paramReportType == null) {
222             // the default report type is the simple report
223
setParamReportType(getSettings().getUserSettings().getWorkplaceReportType());
224         }
225
226         return m_paramReportType;
227     }
228
229     /**
230      * Returns the Thread id to display in this report.<p>
231      *
232      * @return the Thread id to display in this report
233      */

234     public String JavaDoc getParamThread() {
235
236         if ((m_paramThread != null) && (!m_paramThread.equals(CmsUUID.getNullUUID()))) {
237             return m_paramThread.toString();
238         } else {
239             return null;
240         }
241     }
242
243     /**
244      * Returns if another report is following this report.<p>
245      *
246      * @return <code>"true"</code> if another report is following this report
247      */

248     public String JavaDoc getParamThreadHasNext() {
249
250         if (m_paramThreadHasNext == null) {
251             m_paramThreadHasNext = "";
252         }
253         return m_paramThreadHasNext;
254     }
255
256     /**
257      * Returns the part of the report that is ready for output.<p>
258      *
259      * @return the part of the report that is ready for output
260      */

261     public String JavaDoc getReportUpdate() {
262
263         A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread);
264         if (thread != null) {
265             return thread.getReportUpdate();
266         } else {
267             return "";
268         }
269     }
270
271     /**
272      * Returns if the report generated an error output.<p>
273      *
274      * @return true if the report generated an error, otherwise false
275      */

276     public boolean hasError() {
277
278         A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread);
279         if (thread != null) {
280             return thread.hasError();
281         } else {
282             return false;
283         }
284     }
285
286     /**
287      * Builds the start html of the page, including setting of DOCTYPE and
288      * inserting a header with the content-type.<p>
289      *
290      * This overloads the default method of the parent class.<p>
291      *
292      * @return the start html of the page
293      */

294     public String JavaDoc htmlStart() {
295
296         return pageHtml(HTML_START, true);
297     }
298
299     /**
300      * Builds the start html of the page, including setting of DOCTYPE and
301      * inserting a header with the content-type.<p>
302      *
303      * This overloads the default method of the parent class.<p>
304      *
305      * @param loadStyles if true, the defaul style sheet will be loaded
306      * @return the start html of the page
307      */

308     public String JavaDoc htmlStart(boolean loadStyles) {
309
310         return pageHtml(HTML_START, loadStyles);
311     }
312
313     /**
314      * Returns true if the report Thread is still alive (i.e. running), false otherwise.<p>
315      *
316      * @return true if the report Thread is still alive
317      */

318     public boolean isAlive() {
319
320         A_CmsReportThread thread = OpenCms.getThreadStore().retrieveThread(m_paramThread);
321         if (thread != null) {
322             return thread.isAlive();
323         } else {
324             return false;
325         }
326     }
327
328     /**
329      * Checks whether this is a simple report.<p>
330      *
331      * @return true, if the type of this report is a "simple"
332      */

333     public boolean isSimpleReport() {
334
335         return getParamReportType().equalsIgnoreCase(I_CmsReport.REPORT_TYPE_SIMPLE);
336     }
337
338     /**
339      * Builds the start html of the page, including setting of DOCTYPE and
340      * inserting a header with the content-type.<p>
341      *
342      * This overloads the default method of the parent class.<p>
343      *
344      * @param segment the HTML segment (START / END)
345      * @param loadStyles if true, the defaul style sheet will be loaded
346      * @return the start html of the page
347      */

348     public String JavaDoc pageHtml(int segment, boolean loadStyles) {
349
350         if (useNewStyle()) {
351             return super.pageHtml(segment, null, getParamTitle());
352         }
353         if (segment == HTML_START) {
354             StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
355             result.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
356             result.append("<html>\n<head>\n");
357             result.append("<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=");
358             result.append(getEncoding());
359             result.append("\">\n");
360             if (loadStyles) {
361                 result.append("<link rel=\"stylesheet\" type=\"text/css\" HREF=\"");
362                 result.append(getStyleUri(getJsp(), "workplace.css"));
363                 result.append("\">\n");
364                 result.append("<script type=\"text/javascript\">\n");
365                 result.append(dialogScriptSubmit());
366                 result.append("</script>\n");
367             }
368             return result.toString();
369         } else {
370             return "</html>";
371         }
372
373     }
374
375     /**
376      * Sets if the workplace must be refreshed.<p>
377      *
378      * @param value <code>"true"</code> (String) if the workplace must be refreshed.
379      */

380     public void setParamRefreshWorkplace(String JavaDoc value) {
381
382         m_paramRefreshWorkplace = value;
383     }
384
385     /**
386      * Sets the key name which contains the localized message for the continue checkbox.<p>
387      *
388      * @param key the key name which contains the localized message for the continue checkbox
389      */

390     public void setParamReportContinueKey(String JavaDoc key) {
391
392         m_paramReportContinueKey = key;
393     }
394
395     /**
396      * Sets the type of this report.<p>
397      *
398      * @param value the type of this report
399      */

400     public void setParamReportType(String JavaDoc value) {
401
402         m_paramReportType = value;
403     }
404
405     /**
406      * Sets the Thread id to display in this report.<p>
407      *
408      * @param value the Thread id to display in this report
409      */

410     public void setParamThread(String JavaDoc value) {
411
412         m_paramThread = CmsUUID.getNullUUID();
413         if (value != null) {
414             try {
415                 m_paramThread = new CmsUUID(value);
416             } catch (Exception JavaDoc e) {
417                 // can usually be ignored
418
if (LOG.isInfoEnabled()) {
419                     LOG.info(
420                         Messages.get().getBundle().key(Messages.LOG_THREAD_CREATION_FAILED_1, new Integer JavaDoc(value)),
421                         e);
422                 }
423             }
424         }
425     }
426
427     /**
428      * Sets if another report is following this report.<p>
429      *
430      * @param value <code>"true"</code> if another report is following this report
431      */

432     public void setParamThreadHasNext(String JavaDoc value) {
433
434         m_paramThreadHasNext = value;
435     }
436
437     /**
438      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
439      */

440     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
441
442         // fill the parameter values in the get/set methods
443
fillParamValues(request);
444         // set the action for the JSP switch
445
if (REPORT_UPDATE.equals(getParamAction())) {
446             setAction(ACTION_REPORT_UPDATE);
447         } else {
448             setAction(ACTION_REPORT_BEGIN);
449         }
450     }
451
452     /**
453      * Returns always true and does nothing else, has to be implemented.<p>
454      *
455      * @see org.opencms.workplace.CmsMultiDialog#performDialogOperation()
456      */

457     protected boolean performDialogOperation() {
458
459         // do nothing, has to be implemented
460
return true;
461     }
462
463 }
Popular Tags