KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/report/CmsStringBufferReport.java,v $
3  * Date : $Date: 2006/10/04 07:35:21 $
4  * Version: $Revision: 1.15 $
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 java.util.Locale JavaDoc;
35
36 /**
37  * Report class used to write the output of a report to a StringBuffer.<p>
38  *
39  * It stores everything and generates no output.
40  * After the report is finished, you can access to result of the
41  * report using the {@link #toString()} method.<p>
42  *
43  * @author Thomas Weckert
44  * @author Jan Baudisch
45  *
46  * @version $Revision: 1.15 $
47  *
48  * @since 6.0.0
49  */

50 public class CmsStringBufferReport extends A_CmsReport {
51
52     /** The StringBuffer to write to. */
53     private StringBuffer JavaDoc m_strBuf;
54
55     /**
56      * Constructs a new report using the provided locale for the output language.<p>
57      *
58      * @param locale the locale to use for the output language
59      */

60     public CmsStringBufferReport(Locale JavaDoc locale) {
61
62         init(locale, null);
63
64         m_strBuf = new StringBuffer JavaDoc();
65     }
66
67     /**
68      * @see org.opencms.report.I_CmsReport#getReportUpdate()
69      */

70     public String JavaDoc getReportUpdate() {
71
72         return "";
73     }
74
75     /**
76      * @see org.opencms.report.A_CmsReport#print(java.lang.String, int)
77      */

78     public void print(String JavaDoc value, int format) {
79
80         switch (format) {
81             case FORMAT_HEADLINE:
82             case FORMAT_WARNING:
83                 addWarning(value);
84                 m_strBuf.append(value);
85                 break;
86             case FORMAT_ERROR:
87                 addError(value);
88                 m_strBuf.append(value);
89                 break;
90             case FORMAT_NOTE:
91             case FORMAT_OK:
92             case FORMAT_DEFAULT:
93             default:
94                 m_strBuf.append(value);
95         }
96     }
97
98     /**
99      * @see org.opencms.report.I_CmsReport#println()
100      */

101     public void println() {
102
103         m_strBuf.append("\n");
104     }
105
106     /**
107      * @see org.opencms.report.I_CmsReport#println(java.lang.Throwable)
108      */

109     public void println(Throwable JavaDoc t) {
110
111         print(getMessages().key(Messages.RPT_EXCEPTION_0), FORMAT_WARNING);
112         println(t.getMessage(), FORMAT_ERROR);
113
114         StackTraceElement JavaDoc[] stackTrace = t.getStackTrace();
115         for (int i = 0; i < stackTrace.length; i++) {
116             StackTraceElement JavaDoc element = stackTrace[i];
117             println(element.toString());
118         }
119     }
120
121     /**
122      * @see java.lang.Object#toString()
123      */

124     public String JavaDoc toString() {
125
126         return m_strBuf.toString();
127     }
128 }
Popular Tags