176b6b121SAndrew Rist /**************************************************************
2*1fbfd7a2Smseidel  *
376b6b121SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
476b6b121SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
576b6b121SAndrew Rist  * distributed with this work for additional information
676b6b121SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
776b6b121SAndrew Rist  * to you under the Apache License, Version 2.0 (the
876b6b121SAndrew Rist  * "License"); you may not use this file except in compliance
976b6b121SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1fbfd7a2Smseidel  *
1176b6b121SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1fbfd7a2Smseidel  *
1376b6b121SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1476b6b121SAndrew Rist  * software distributed under the License is distributed on an
1576b6b121SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1676b6b121SAndrew Rist  * KIND, either express or implied.  See the License for the
1776b6b121SAndrew Rist  * specific language governing permissions and limitations
1876b6b121SAndrew Rist  * under the License.
19*1fbfd7a2Smseidel  *
2076b6b121SAndrew Rist  *************************************************************/
2176b6b121SAndrew Rist 
2276b6b121SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package complex.framework.autosave;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir // __________ Imports __________
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // structs, const, ...
29cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
30cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // exceptions
33cdf0e10cSrcweir import com.sun.star.container.NoSuchElementException;
34cdf0e10cSrcweir import com.sun.star.uno.Exception;
35cdf0e10cSrcweir import com.sun.star.uno.RuntimeException;
36cdf0e10cSrcweir import java.io.IOException;
37cdf0e10cSrcweir import java.lang.InterruptedException;
38cdf0e10cSrcweir import java.net.ConnectException;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // interfaces
41cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
42cdf0e10cSrcweir import com.sun.star.uno.Any;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir // helper
45cdf0e10cSrcweir import com.sun.star.uno.IBridge;
46cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // others
49cdf0e10cSrcweir import javax.swing.*;
50cdf0e10cSrcweir import javax.swing.border.*;
51cdf0e10cSrcweir import java.awt.*;
52cdf0e10cSrcweir import java.lang.*;
53cdf0e10cSrcweir import java.io.*;
54cdf0e10cSrcweir import java.util.*;
55cdf0e10cSrcweir import java.sql.*;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir // __________ Implementation __________
58cdf0e10cSrcweir 
59cdf0e10cSrcweir /**
60cdf0e10cSrcweir  * Implements a log mechanism to create a protocol of all steps of e.g. an api test
61*1fbfd7a2Smseidel  * It provides the possibility to write the logged messages to a file and/or
6207a3d7f1SPedro Giffuni  * to stdout/stderr (if necessary at the same time!).
63cdf0e10cSrcweir  *
64cdf0e10cSrcweir  *  TODO
6507a3d7f1SPedro Giffuni  *      - implement filter, which e.g. suppress showing of INFO data
66cdf0e10cSrcweir  */
67cdf0e10cSrcweir public class Protocol extends JComponent
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     // ____________________
70cdf0e10cSrcweir     /**
71cdf0e10cSrcweir      * Note: Following values can be combined - they are interpreted as flags.
72cdf0e10cSrcweir      *
73cdf0e10cSrcweir      * @const   MODE_STDOUT             messages are logged to stdout
74cdf0e10cSrcweir      * @const   MODE_STDERR             messages are logged to stderr
75cdf0e10cSrcweir      * @const   MODE_ASCII              messages are logged to an ascii file
76cdf0e10cSrcweir      * @const   MODE_HTML               messages are logged to a html file
77cdf0e10cSrcweir      *
78cdf0e10cSrcweir      * @const   TYPE_SCOPE_OPEN         open, mark or count a new scope for following log statements
79cdf0e10cSrcweir      * @const   TYPE_SCOPE_CLOSE        close, mark or count the current scope
80cdf0e10cSrcweir      * @const   TYPE_TESTMARK           it marks the beginning of a (sub)test, can be used for statistic purposes
81cdf0e10cSrcweir      * @const   TYPE_OK                 this protocol line is marked as a OK message
82cdf0e10cSrcweir      * @const   TYPE_ERROR              this protocol line is marked as an error
83cdf0e10cSrcweir      * @const   TYPE_WARNING            this protocol line is marked as a warning
84cdf0e10cSrcweir      * @const   TYPE_INFO               this protocol line represent some debug data for analyzing
85cdf0e10cSrcweir      */
86cdf0e10cSrcweir     public  static final int    MODE_STDOUT             = 1;
87cdf0e10cSrcweir     public  static final int    MODE_STDERR             = 2;
88cdf0e10cSrcweir     public  static final int    MODE_ASCII              = 4;
89cdf0e10cSrcweir     public  static final int    MODE_HTML               = 8;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     public  static final int    TYPE_OK                 =    1;
92cdf0e10cSrcweir     public  static final int    TYPE_ERROR              =    2;
93cdf0e10cSrcweir     public  static final int    TYPE_WARNING            =    4;
94cdf0e10cSrcweir     public  static final int    TYPE_INFO               =    8;
95cdf0e10cSrcweir     public  static final int    TYPE_SCOPE_OPEN         =   16;
96cdf0e10cSrcweir     public  static final int    TYPE_SCOPE_CLOSE        =   32;
97cdf0e10cSrcweir     public  static final int    TYPE_TESTMARK           =   64;
98cdf0e10cSrcweir     public  static final int    TYPE_ERROR_INFO         =  128;
99cdf0e10cSrcweir     public  static final int    TYPE_WARNING_INFO       =  256;
100cdf0e10cSrcweir     public  static final int    TYPE_STATISTIC          =  512;
101cdf0e10cSrcweir     public  static final int    TYPE_LINK               = 1024;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     public  static final int    FILTER_NONE             = 0;
104cdf0e10cSrcweir     public  static final int    FILTER_OK               = TYPE_OK;
105cdf0e10cSrcweir     public  static final int    FILTER_ERROR            = TYPE_ERROR;
106cdf0e10cSrcweir     public  static final int    FILTER_WARNING          = TYPE_WARNING;
107cdf0e10cSrcweir     public  static final int    FILTER_INFO             = TYPE_INFO;
108cdf0e10cSrcweir     public  static final int    FILTER_SCOPES           = TYPE_SCOPE_OPEN | TYPE_SCOPE_CLOSE;
109cdf0e10cSrcweir     public  static final int    FILTER_TESTMARK         = TYPE_TESTMARK;
110cdf0e10cSrcweir     public  static final int    FILTER_ERROR_INFO       = TYPE_ERROR_INFO;
111cdf0e10cSrcweir     public  static final int    FILTER_WARNING_INFO     = TYPE_WARNING_INFO;
112cdf0e10cSrcweir     public  static final int    FILTER_STATISTIC        = TYPE_STATISTIC;
113cdf0e10cSrcweir     public  static final int    FILTER_LINK             = TYPE_LINK;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     // ____________________
116cdf0e10cSrcweir     /**
117cdf0e10cSrcweir      */
118cdf0e10cSrcweir     private static final int    MARK_DIFF               = 5;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     private static final String BGCOLOR_LINECOL         = "#95CC77";
121cdf0e10cSrcweir     private static final String FGCOLOR_LINECOL_NORMAL  = "#ffffbd";
122cdf0e10cSrcweir     private static final String FGCOLOR_LINECOL_MARKED  = "#000088";
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     private static final String BGCOLOR_STANDARD        = "#ffffff";
125cdf0e10cSrcweir     private static final String FGCOLOR_STANDARD        = "#000000";
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     private static final String BGCOLOR_SCOPE           = "#eeeeee";
128cdf0e10cSrcweir     private static final String FGCOLOR_SCOPE           = "#000000";
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     private static final String BGCOLOR_TIMESTAMP       = "#e0e0e0";
131cdf0e10cSrcweir     private static final String FGCOLOR_TIMESTAMP       = "#000000";
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     private static final String BGCOLOR_TESTMARK        = "#0000ff";
134cdf0e10cSrcweir     private static final String FGCOLOR_TESTMARK        = "#ffffff";
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     private static final String BGCOLOR_OK              = "#88dd88";
137cdf0e10cSrcweir     private static final String FGCOLOR_OK              = "#ffffff";
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     private static final String BGCOLOR_WARNING         = "#ffff00";
140cdf0e10cSrcweir     private static final String FGCOLOR_WARNING         = "#000000";
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     private static final String BGCOLOR_WARNING_INFO    = "#ffffcc";
143cdf0e10cSrcweir     private static final String FGCOLOR_WARNING_INFO    = "#000000";
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     private static final String BGCOLOR_ERROR           = "#ff0000";
146cdf0e10cSrcweir     private static final String FGCOLOR_ERROR           = "#ffff00";
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     private static final String BGCOLOR_ERROR_INFO      = "#ffbbbb";
149cdf0e10cSrcweir     private static final String FGCOLOR_ERROR_INFO      = "#000000";
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     private static final String BGCOLOR_INFO            = "#eeeeee";
152cdf0e10cSrcweir     private static final String FGCOLOR_INFO            = "#000000";
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     private static final String BGCOLOR_STATISTIC       = "#0000ff";
155cdf0e10cSrcweir     private static final String FGCOLOR_STATISTIC       = "#ffffff";
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     private static final String BGCOLOR_LINK            = BGCOLOR_INFO;
158cdf0e10cSrcweir     private static final String FGCOLOR_LINK            = FGCOLOR_INFO;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     // ____________________
161cdf0e10cSrcweir     /**
162cdf0e10cSrcweir      * @member  m_nMode         the mode, in which this protocol object runs
163cdf0e10cSrcweir      * @member  m_nFilter       can be used to filter log messages by type
164cdf0e10cSrcweir      * @member  m_sFileName     we need it to open the log file on demand (if nMode require such log file)
165cdf0e10cSrcweir      * @member  m_nLine         used as line number for the protocol
166cdf0e10cSrcweir      * @member  m_nScope        used to format scopes
167cdf0e10cSrcweir      * @member  m_nErrors       count errors in protocol
168cdf0e10cSrcweir      * @member  m_nWarnings     count warnings in protocol
169cdf0e10cSrcweir      * @member  m_nTestMarks    count test marker in protocol
170cdf0e10cSrcweir      */
171cdf0e10cSrcweir     private int                 m_nMode     ;
172cdf0e10cSrcweir     private int                 m_nFilter   ;
173cdf0e10cSrcweir     private String              m_sFileName ;
174cdf0e10cSrcweir     private long                m_nLine     ;
175cdf0e10cSrcweir     private long                m_nScope    ;
176cdf0e10cSrcweir     private long                m_nErrors   ;
177cdf0e10cSrcweir     private long                m_nWarnings ;
178cdf0e10cSrcweir     private long                m_nTestMarks;
179cdf0e10cSrcweir     private Timestamp           m_aStartTime;
180cdf0e10cSrcweir     private Timestamp           m_aEndTime  ;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     // ____________________
183cdf0e10cSrcweir     /**
184cdf0e10cSrcweir      * special helper class to represent one line of a protocol.
185cdf0e10cSrcweir      * Such line can be specified as a special one (ERROR, WARNING ...).
186cdf0e10cSrcweir      * That makes it possible to analyze the whole protocol using tools.
187cdf0e10cSrcweir      */
188cdf0e10cSrcweir     class ProtocolLine
189cdf0e10cSrcweir     {
190cdf0e10cSrcweir         /// the line number of this protocol line (size of the vector of all protocol lines cn be used to count such lines!)
191cdf0e10cSrcweir         private long m_nLine;
192cdf0e10cSrcweir         /// deepness of the current scope
193cdf0e10cSrcweir         private long m_nScope;
194cdf0e10cSrcweir         /// mark line as an error, warning, data entry ... (see const definitions before)
195cdf0e10cSrcweir         private int m_nType;
196cdf0e10cSrcweir         /// of course, we have to know the logged message too :-)
197cdf0e10cSrcweir         private String m_sMessage;
19807a3d7f1SPedro Giffuni         /// and it can be useful to know the current time, when this line was created
199cdf0e10cSrcweir         private Timestamp m_aStamp;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         /** ctor for fast initializing of such line */
ProtocolLine( long nLine , long nScope , int nType , String sMessage )202cdf0e10cSrcweir         public ProtocolLine( long   nLine    ,
203cdf0e10cSrcweir                              long   nScope   ,
204cdf0e10cSrcweir                              int    nType    ,
205cdf0e10cSrcweir                              String sMessage )
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             m_aStamp   = new Timestamp(System.currentTimeMillis());
208cdf0e10cSrcweir             m_nLine    = nLine   ;
209cdf0e10cSrcweir             m_nScope   = nScope  ;
210cdf0e10cSrcweir             m_nType    = nType   ;
211cdf0e10cSrcweir             m_sMessage = sMessage;
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         /** format this line as an ascii string for writing log files */
toString()215cdf0e10cSrcweir         public synchronized String toString()
216cdf0e10cSrcweir         {
217cdf0e10cSrcweir             StringBuffer sLine = new StringBuffer(1000);
218cdf0e10cSrcweir 
219cdf0e10cSrcweir             // insert line number
220cdf0e10cSrcweir             // Use right bound notation and format 6 digits!
221cdf0e10cSrcweir             sLine.append("["    );
222cdf0e10cSrcweir             if (m_nLine<10)
223cdf0e10cSrcweir                 sLine.append("     ");
224cdf0e10cSrcweir             else
225cdf0e10cSrcweir             if (m_nLine<100)
226cdf0e10cSrcweir                 sLine.append("    ");
227cdf0e10cSrcweir             else
228cdf0e10cSrcweir             if (m_nLine<1000)
229cdf0e10cSrcweir                 sLine.append("   ");
230cdf0e10cSrcweir             else
231cdf0e10cSrcweir             if (m_nLine<10000)
232cdf0e10cSrcweir                 sLine.append("  ");
233cdf0e10cSrcweir             else
234cdf0e10cSrcweir             if (m_nLine<100000)
235cdf0e10cSrcweir                 sLine.append(" ");
236cdf0e10cSrcweir             sLine.append(m_nLine);
237cdf0e10cSrcweir             sLine.append("] "   );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir             // add time stamp
240cdf0e10cSrcweir             // close with a "TAB" ... because some time stamps are not normalized to
241cdf0e10cSrcweir             // a well defined string length .-)
242cdf0e10cSrcweir             sLine.append(m_aStamp.toString()+" \t");
243cdf0e10cSrcweir 
244cdf0e10cSrcweir             // add special line type
245cdf0e10cSrcweir             if ((m_nType & TYPE_OK) == TYPE_OK)
246cdf0e10cSrcweir                 sLine.append(" OK           ");
247cdf0e10cSrcweir             else
248cdf0e10cSrcweir             if ((m_nType & TYPE_ERROR) == TYPE_ERROR)
249cdf0e10cSrcweir                 sLine.append(" ERROR        ");
250cdf0e10cSrcweir             else
251cdf0e10cSrcweir             if ((m_nType & TYPE_ERROR_INFO) == TYPE_ERROR_INFO)
252cdf0e10cSrcweir                 sLine.append(" ERROR INFO   ");
253cdf0e10cSrcweir             else
254cdf0e10cSrcweir             if ((m_nType & TYPE_WARNING) == TYPE_WARNING)
255cdf0e10cSrcweir                 sLine.append(" WARNING      ");
256cdf0e10cSrcweir             else
257cdf0e10cSrcweir             if ((m_nType & TYPE_WARNING_INFO) == TYPE_WARNING_INFO)
258cdf0e10cSrcweir                 sLine.append(" WARNING INFO ");
259cdf0e10cSrcweir             else
260cdf0e10cSrcweir             if ((m_nType & TYPE_INFO) == TYPE_INFO)
261cdf0e10cSrcweir                 sLine.append(" INFO         ");
262cdf0e10cSrcweir             else
263cdf0e10cSrcweir             if ((m_nType & TYPE_TESTMARK) == TYPE_TESTMARK)
264cdf0e10cSrcweir                 sLine.append(" TEST         ");
265cdf0e10cSrcweir             else
266cdf0e10cSrcweir             if ((m_nType & TYPE_LINK) == TYPE_LINK)
267cdf0e10cSrcweir                 sLine.append(" LINK         ");
268cdf0e10cSrcweir             else
269cdf0e10cSrcweir             if ((m_nType & TYPE_STATISTIC) == TYPE_STATISTIC)
270cdf0e10cSrcweir                 sLine.append(" STATISTIC    ");
271cdf0e10cSrcweir             else
272cdf0e10cSrcweir             if (
273cdf0e10cSrcweir                 ((m_nType & TYPE_SCOPE_OPEN ) == TYPE_SCOPE_OPEN ) ||
274cdf0e10cSrcweir                 ((m_nType & TYPE_SCOPE_CLOSE) == TYPE_SCOPE_CLOSE)
275cdf0e10cSrcweir                )
276cdf0e10cSrcweir                 sLine.append(" SCOPE        ");
277cdf0e10cSrcweir             else
278cdf0e10cSrcweir                 sLine.append("              ");
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             // add scope information
281cdf0e10cSrcweir             for (int s=0; s<m_nScope; ++s)
282cdf0e10cSrcweir                 sLine.append(" ");
283cdf0e10cSrcweir 
284cdf0e10cSrcweir             if ((m_nType & TYPE_SCOPE_OPEN) == TYPE_SCOPE_OPEN)
285cdf0e10cSrcweir                 sLine.append(" { ");
286cdf0e10cSrcweir             else
287cdf0e10cSrcweir             if ((m_nType & TYPE_SCOPE_CLOSE) == TYPE_SCOPE_CLOSE)
288cdf0e10cSrcweir                 sLine.append(" } ");
289cdf0e10cSrcweir             else
290cdf0e10cSrcweir                 sLine.append("   ");
291cdf0e10cSrcweir 
292cdf0e10cSrcweir             // add message
293cdf0e10cSrcweir             sLine.append(m_sMessage);
294cdf0e10cSrcweir             sLine.append("\n"      );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir             return sLine.toString();
297cdf0e10cSrcweir         }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir         /**
300cdf0e10cSrcweir          * format this line as a string for writing log files
301cdf0e10cSrcweir          * using the html format
302cdf0e10cSrcweir          */
toHTML()303cdf0e10cSrcweir         public synchronized String toHTML()
304cdf0e10cSrcweir         {
305cdf0e10cSrcweir             StringBuffer sLine = new StringBuffer(1000);
306cdf0e10cSrcweir             sLine.append("<tr>");
307cdf0e10cSrcweir 
308cdf0e10cSrcweir             // insert line number
309cdf0e10cSrcweir             if (m_nLine % MARK_DIFF == 0)
310cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, new Long(m_nLine).toString(), BGCOLOR_LINECOL, FGCOLOR_LINECOL_MARKED, true);
311cdf0e10cSrcweir             else
312cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, new Long(m_nLine).toString(), BGCOLOR_LINECOL, FGCOLOR_LINECOL_NORMAL, false);
313cdf0e10cSrcweir 
314cdf0e10cSrcweir             // add time stamp
315cdf0e10cSrcweir             impl_generateColoredHTMLCell(sLine, m_aStamp.toString()+" ", BGCOLOR_TIMESTAMP, FGCOLOR_TIMESTAMP, false);
316cdf0e10cSrcweir 
317cdf0e10cSrcweir             // add log type info
318cdf0e10cSrcweir             boolean bTypeCellFilled = false;
319cdf0e10cSrcweir             if ((m_nType & TYPE_ERROR_INFO) == TYPE_ERROR_INFO)
320cdf0e10cSrcweir             {
321cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "ERROR INFO", BGCOLOR_ERROR_INFO, FGCOLOR_ERROR_INFO, false);
322cdf0e10cSrcweir                 bTypeCellFilled = true;
323cdf0e10cSrcweir             }
324cdf0e10cSrcweir             else
325cdf0e10cSrcweir             if ((m_nType & TYPE_ERROR) == TYPE_ERROR)
326cdf0e10cSrcweir             {
327cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "ERROR", BGCOLOR_ERROR, FGCOLOR_ERROR, true);
328cdf0e10cSrcweir                 bTypeCellFilled = true;
329cdf0e10cSrcweir             }
330cdf0e10cSrcweir             else
331cdf0e10cSrcweir             if ((m_nType & TYPE_WARNING_INFO) == TYPE_WARNING_INFO)
332cdf0e10cSrcweir             {
333cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "WARNING INFO", BGCOLOR_WARNING_INFO, FGCOLOR_WARNING_INFO, false);
334cdf0e10cSrcweir                 bTypeCellFilled = true;
335cdf0e10cSrcweir             }
336cdf0e10cSrcweir             else
337cdf0e10cSrcweir             if ((m_nType & TYPE_WARNING) == TYPE_WARNING)
338cdf0e10cSrcweir             {
339cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "WARNING", BGCOLOR_WARNING, FGCOLOR_WARNING, true);
340cdf0e10cSrcweir                 bTypeCellFilled = true;
341cdf0e10cSrcweir             }
342cdf0e10cSrcweir             else
343cdf0e10cSrcweir             if ((m_nType & TYPE_OK) == TYPE_OK)
344cdf0e10cSrcweir             {
345cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "OK", BGCOLOR_OK, FGCOLOR_OK, true);
346cdf0e10cSrcweir                 bTypeCellFilled = true;
347cdf0e10cSrcweir             }
348cdf0e10cSrcweir             else
349cdf0e10cSrcweir             if ((m_nType & TYPE_INFO) == TYPE_INFO)
350cdf0e10cSrcweir             {
351cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "INFO", BGCOLOR_INFO, FGCOLOR_INFO, false);
352cdf0e10cSrcweir                 bTypeCellFilled = true;
353cdf0e10cSrcweir             }
354cdf0e10cSrcweir             else
355cdf0e10cSrcweir             if ((m_nType & TYPE_TESTMARK) == TYPE_TESTMARK)
356cdf0e10cSrcweir             {
357cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "TEST", BGCOLOR_TESTMARK, FGCOLOR_TESTMARK, true);
358cdf0e10cSrcweir                 bTypeCellFilled = true;
359cdf0e10cSrcweir             }
360cdf0e10cSrcweir             else
361cdf0e10cSrcweir             if ((m_nType & TYPE_STATISTIC) == TYPE_STATISTIC)
362cdf0e10cSrcweir             {
363cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "STATISTIC", BGCOLOR_STATISTIC, FGCOLOR_STATISTIC, false);
364cdf0e10cSrcweir                 bTypeCellFilled = true;
365cdf0e10cSrcweir             }
366cdf0e10cSrcweir             else
367cdf0e10cSrcweir             if ((m_nType & TYPE_LINK) == TYPE_LINK)
368cdf0e10cSrcweir             {
369cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "LINK", BGCOLOR_LINK, FGCOLOR_LINK, false);
370cdf0e10cSrcweir                 bTypeCellFilled = true;
371cdf0e10cSrcweir             }
372cdf0e10cSrcweir             else
373cdf0e10cSrcweir             if (
374cdf0e10cSrcweir                 ((m_nType & TYPE_SCOPE_OPEN ) == TYPE_SCOPE_OPEN ) ||
375cdf0e10cSrcweir                 ((m_nType & TYPE_SCOPE_CLOSE) == TYPE_SCOPE_CLOSE)
376cdf0e10cSrcweir                )
377cdf0e10cSrcweir             {
378cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, "SCOPE", BGCOLOR_SCOPE, FGCOLOR_SCOPE, false);
379cdf0e10cSrcweir                 bTypeCellFilled = true;
380cdf0e10cSrcweir             }
381cdf0e10cSrcweir 
382*1fbfd7a2Smseidel             // if no type information was added to the current column, we must
383cdf0e10cSrcweir             // write any content into this cell. Otherwise some browser
384cdf0e10cSrcweir             // shows a strange layout!
385cdf0e10cSrcweir             if (! bTypeCellFilled)
386cdf0e10cSrcweir                 impl_generateColoredHTMLCell(sLine, " ", BGCOLOR_STANDARD, FGCOLOR_STANDARD, false);
387cdf0e10cSrcweir 
388cdf0e10cSrcweir             // add scope information
389cdf0e10cSrcweir             sLine.append("<td>");
390cdf0e10cSrcweir             for (int s=0; s<m_nScope; ++s)
391cdf0e10cSrcweir                 sLine.append("&nbsp;&nbsp;&nbsp;");
392cdf0e10cSrcweir             String sColor = "#000000";
393cdf0e10cSrcweir             if ((m_nScope % 2) == 0)
394cdf0e10cSrcweir                 sColor = "#808080";
395cdf0e10cSrcweir             if ((m_nType & TYPE_SCOPE_OPEN) == TYPE_SCOPE_OPEN)
396cdf0e10cSrcweir                 sLine.append("<font color=\""+sColor+"\">{ "+m_nScope+"</font>");
397cdf0e10cSrcweir             else
398cdf0e10cSrcweir             if ((m_nType & TYPE_SCOPE_CLOSE) == TYPE_SCOPE_CLOSE)
399cdf0e10cSrcweir                 sLine.append("<font color=\""+sColor+"\">"+m_nScope+" }</font>");
400cdf0e10cSrcweir             sLine.append("</td>\n");
401cdf0e10cSrcweir 
402cdf0e10cSrcweir             // add message
403cdf0e10cSrcweir             sLine.append("<td>"    );
404cdf0e10cSrcweir             sLine.append(m_sMessage);
405cdf0e10cSrcweir             sLine.append("</td>\n" );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir             sLine.append("</tr>\n" );
408cdf0e10cSrcweir 
409cdf0e10cSrcweir             return sLine.toString();
410cdf0e10cSrcweir         }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir         /** detect, if this line object represent an error */
isError()413cdf0e10cSrcweir         public synchronized boolean isError()
414cdf0e10cSrcweir         {
415cdf0e10cSrcweir             return (
416cdf0e10cSrcweir                     ((m_nType & TYPE_ERROR) == TYPE_ERROR) &&
417cdf0e10cSrcweir                     ((m_nType & TYPE_INFO ) != TYPE_INFO )
418cdf0e10cSrcweir                    );
419cdf0e10cSrcweir         }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir         /** detect, if this line object represent a warning */
isWarning()422cdf0e10cSrcweir         public synchronized boolean isWarning()
423cdf0e10cSrcweir         {
424cdf0e10cSrcweir             return (
425cdf0e10cSrcweir                     ((m_nType & TYPE_WARNING) == TYPE_WARNING) &&
426cdf0e10cSrcweir                     ((m_nType & TYPE_INFO   ) != TYPE_INFO   )
427cdf0e10cSrcweir                    );
428cdf0e10cSrcweir         }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir         /** detect, if this line object represent a marked position */
isTestMark()431cdf0e10cSrcweir         public synchronized boolean isTestMark()
432cdf0e10cSrcweir         {
433cdf0e10cSrcweir             return ((m_nType & TYPE_TESTMARK) == TYPE_TESTMARK);
434cdf0e10cSrcweir         }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir         /**
43730acf5e8Spfg          * create a colored table cell formatted as HTML.
438cdf0e10cSrcweir          *
439cdf0e10cSrcweir          * @param   sCell
440cdf0e10cSrcweir          *          an outside string buffer, which can be
441cdf0e10cSrcweir          *          used to generate the
442cdf0e10cSrcweir          *          needed HTML code there.
443cdf0e10cSrcweir          *
444cdf0e10cSrcweir          * @param   sContent
445cdf0e10cSrcweir          *          the text content of this cell.
446cdf0e10cSrcweir          *
447cdf0e10cSrcweir          * @param   sBGColor
448cdf0e10cSrcweir          *          a string, which represent the background color
449cdf0e10cSrcweir          *          coded in HTML.
450cdf0e10cSrcweir          *
451cdf0e10cSrcweir          * @param   sFGColor
452cdf0e10cSrcweir          *          a string, which represent the foreground color
453cdf0e10cSrcweir          *          coded in HTML.
454cdf0e10cSrcweir          *
455cdf0e10cSrcweir          * @param   bBold
456cdf0e10cSrcweir          *          enable/disable bold state for the text content.
457cdf0e10cSrcweir          */
impl_generateColoredHTMLCell(StringBuffer sCell , String sContent, String sBGColor, String sFGColor, boolean bBold )458cdf0e10cSrcweir         private void impl_generateColoredHTMLCell(StringBuffer sCell   ,
459cdf0e10cSrcweir                                                   String       sContent,
460cdf0e10cSrcweir                                                   String       sBGColor,
461cdf0e10cSrcweir                                                   String       sFGColor,
462cdf0e10cSrcweir                                                   boolean      bBold   )
463cdf0e10cSrcweir         {
464cdf0e10cSrcweir             sCell.append("<td bgcolor=\""+sBGColor+"\">");
465cdf0e10cSrcweir             sCell.append("<font color=\""+sFGColor+"\">");
466cdf0e10cSrcweir             if (bBold)
467cdf0e10cSrcweir                 sCell.append("<b>");
468cdf0e10cSrcweir             sCell.append(sContent);
469cdf0e10cSrcweir             if (bBold)
470cdf0e10cSrcweir                 sCell.append("</b>");
471cdf0e10cSrcweir             sCell.append("</font></td>\n");
472cdf0e10cSrcweir         }
473cdf0e10cSrcweir     }
474cdf0e10cSrcweir 
475cdf0e10cSrcweir     // ____________________
476cdf0e10cSrcweir     /**
477cdf0e10cSrcweir      * ctor
478*1fbfd7a2Smseidel      * It creates a new instance of this class and initialize it in the right mode.
479cdf0e10cSrcweir      *
480cdf0e10cSrcweir      * @param nMode
481cdf0e10cSrcweir      *          specify how the log should be generated.
482cdf0e10cSrcweir      *
483cdf0e10cSrcweir      * @param nFilter
484cdf0e10cSrcweir      *          can be used to filter log messages by it's type.
485cdf0e10cSrcweir      *
486cdf0e10cSrcweir      * @param sFileName
487cdf0e10cSrcweir      *          the name of the log file (if nMode requires a log file)
488cdf0e10cSrcweir      */
Protocol(int nMode , int nFilter , String sFileName)489cdf0e10cSrcweir     public Protocol(int    nMode    ,
490cdf0e10cSrcweir                     int    nFilter  ,
491cdf0e10cSrcweir                     String sFileName)
492cdf0e10cSrcweir     {
493cdf0e10cSrcweir         m_nMode      = nMode;
494cdf0e10cSrcweir         m_nFilter    = nFilter;
495cdf0e10cSrcweir         m_sFileName  = sFileName;
496cdf0e10cSrcweir         m_nLine      = 0;
497cdf0e10cSrcweir         m_nScope     = 1;
498cdf0e10cSrcweir         m_nWarnings  = 0;
499cdf0e10cSrcweir         m_nErrors    = 0;
500cdf0e10cSrcweir         m_aStartTime = new Timestamp(System.currentTimeMillis());
501cdf0e10cSrcweir     }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     // ____________________
504cdf0e10cSrcweir     /**
50507a3d7f1SPedro Giffuni      * For some modes it's necessary, that we write some additional
506cdf0e10cSrcweir      * informations to the log. E.g. for html we must generate close targets.
507cdf0e10cSrcweir      */
finish()508cdf0e10cSrcweir     public synchronized void finish()
509cdf0e10cSrcweir     {
510*1fbfd7a2Smseidel         // Prefer HTML ... because we can't write ASCII and HTML contents to the same log file!
511cdf0e10cSrcweir         String sContent;
512cdf0e10cSrcweir         if ((m_nMode & MODE_HTML) == MODE_HTML)
513cdf0e10cSrcweir             sContent = impl_generateHTMLFooter();
514cdf0e10cSrcweir         else
515cdf0e10cSrcweir         if ((m_nMode & MODE_ASCII) == MODE_ASCII)
516cdf0e10cSrcweir             sContent = impl_generateAsciiFooter();
517cdf0e10cSrcweir         else
518cdf0e10cSrcweir             return;
519cdf0e10cSrcweir 
520cdf0e10cSrcweir         impl_writeToLogFile(m_sFileName, true, sContent);
521cdf0e10cSrcweir     }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     // ____________________
524cdf0e10cSrcweir     /**
525cdf0e10cSrcweir      * log an unspecified message.
526cdf0e10cSrcweir      *
527cfd52e18Smseidel      * Sometimes it's not necessary to set a special type for a message.
528cfd52e18Smseidel      * The pure message seems to be enough. The type of such "pure messages"
529cdf0e10cSrcweir      * will be set to INFO.
530cdf0e10cSrcweir      *
531cdf0e10cSrcweir      * @param   sMessage
532cdf0e10cSrcweir      *              the pure message
533cdf0e10cSrcweir      *
534e6b649b5SPedro Giffuni      * @see     #log(int, String)
535cdf0e10cSrcweir      */
log( String sMessage )536cdf0e10cSrcweir     public synchronized void log( /*IN*/ String sMessage )
537cdf0e10cSrcweir     {
538cdf0e10cSrcweir         log(TYPE_INFO, sMessage);
539cdf0e10cSrcweir     }
540cdf0e10cSrcweir 
541cdf0e10cSrcweir     // ____________________
542cdf0e10cSrcweir     /**
543cdf0e10cSrcweir      * log an exception.
544cdf0e10cSrcweir      *
545cdf0e10cSrcweir      * It uses all informations available by this exception object
546cdf0e10cSrcweir      * to generate the log. So exceptions are printed out using a
547cdf0e10cSrcweir      * standard format.
548cdf0e10cSrcweir      *
549cdf0e10cSrcweir      * @param   exThrowable
550cdf0e10cSrcweir      *              the exception
551cdf0e10cSrcweir      */
log( Throwable exThrowable )552cdf0e10cSrcweir     public synchronized void log( /*IN*/ Throwable exThrowable )
553cdf0e10cSrcweir     {
554cdf0e10cSrcweir         log(TYPE_SCOPE_OPEN | TYPE_ERROR, "exception \""+exThrowable.getMessage()+"\"");
555cdf0e10cSrcweir 
556cdf0e10cSrcweir         StackTraceElement[] lStack = exThrowable.getStackTrace();
557cdf0e10cSrcweir         for (int i=0; i<lStack.length; ++i)
558cdf0e10cSrcweir            log(TYPE_ERROR_INFO, lStack[i].toString());
559cdf0e10cSrcweir 
560cdf0e10cSrcweir         log(TYPE_SCOPE_CLOSE | TYPE_ERROR_INFO, "");
561cdf0e10cSrcweir     }
562cdf0e10cSrcweir 
563cdf0e10cSrcweir     // ____________________
564cdf0e10cSrcweir     /**
565cdf0e10cSrcweir      * log different property arrays.
566cdf0e10cSrcweir      *
567cdf0e10cSrcweir      * @param   lProps
568cdf0e10cSrcweir      *              the array of properties
569cdf0e10cSrcweir      */
log( com.sun.star.beans.NamedValue[] lProps )570cdf0e10cSrcweir     public synchronized void log( /*IN*/ com.sun.star.beans.NamedValue[] lProps )
571cdf0e10cSrcweir     {
572cdf0e10cSrcweir         StringBuffer sValues = new StringBuffer(1000);
573cdf0e10cSrcweir         impl_logPropertyArray(sValues, lProps);
574cdf0e10cSrcweir 
575cdf0e10cSrcweir         log(TYPE_SCOPE_OPEN  | TYPE_INFO, "property array ["+lProps.length+"]:");
576cdf0e10cSrcweir         log(TYPE_SCOPE_CLOSE | TYPE_INFO, sValues.toString()                   );
577cdf0e10cSrcweir     }
578cdf0e10cSrcweir 
log( com.sun.star.beans.PropertyValue[] lProps )579cdf0e10cSrcweir     public synchronized void log( /*IN*/ com.sun.star.beans.PropertyValue[] lProps )
580cdf0e10cSrcweir     {
581cdf0e10cSrcweir         StringBuffer sValues = new StringBuffer(1000);
582cdf0e10cSrcweir         impl_logPropertyArray(sValues, lProps);
583cdf0e10cSrcweir 
584cdf0e10cSrcweir         log(TYPE_SCOPE_OPEN  | TYPE_INFO, "property array ["+lProps.length+"]:");
585cdf0e10cSrcweir         log(TYPE_SCOPE_CLOSE | TYPE_INFO, sValues.toString()                   );
586cdf0e10cSrcweir     }
587cdf0e10cSrcweir 
log( com.sun.star.beans.NamedValue aProp )588cdf0e10cSrcweir     public synchronized void log( /*IN*/ com.sun.star.beans.NamedValue aProp )
589cdf0e10cSrcweir     {
590cdf0e10cSrcweir         StringBuffer sValue = new StringBuffer(1000);
591cdf0e10cSrcweir         impl_logProperty(sValue, aProp);
592cdf0e10cSrcweir 
593cdf0e10cSrcweir         log(TYPE_SCOPE_OPEN  | TYPE_INFO, "property:"      );
594cdf0e10cSrcweir         log(TYPE_SCOPE_CLOSE | TYPE_INFO, sValue.toString());
595cdf0e10cSrcweir     }
596cdf0e10cSrcweir 
log( com.sun.star.beans.PropertyValue aProp )597cdf0e10cSrcweir     public synchronized void log( /*IN*/ com.sun.star.beans.PropertyValue aProp )
598cdf0e10cSrcweir     {
599cdf0e10cSrcweir         StringBuffer sValue = new StringBuffer(1000);
600cdf0e10cSrcweir         impl_logProperty(sValue, aProp);
601cdf0e10cSrcweir 
602cdf0e10cSrcweir         log(TYPE_SCOPE_OPEN  | TYPE_INFO, "property:"      );
603cdf0e10cSrcweir         log(TYPE_SCOPE_CLOSE | TYPE_INFO, sValue.toString());
604cdf0e10cSrcweir     }
605cdf0e10cSrcweir 
log( Object aAny )606cdf0e10cSrcweir     public synchronized void log( /*IN*/ Object aAny )
607cdf0e10cSrcweir     {
608cdf0e10cSrcweir         StringBuffer sValue = new StringBuffer(1000);
609cdf0e10cSrcweir         impl_logAny(sValue, aAny);
610cdf0e10cSrcweir 
611cdf0e10cSrcweir         log(TYPE_SCOPE_OPEN  | TYPE_INFO, "any:"           );
612cdf0e10cSrcweir         log(TYPE_SCOPE_CLOSE | TYPE_INFO, sValue.toString());
613cdf0e10cSrcweir     }
614cdf0e10cSrcweir 
615cdf0e10cSrcweir     // ____________________
616cdf0e10cSrcweir     /**
617cdf0e10cSrcweir      * log a message.
618cdf0e10cSrcweir      *
619cdf0e10cSrcweir      * It looks for the internal set mode and decide, how this message
620cdf0e10cSrcweir      * will be handled. Then it generates a special object which represent
621cdf0e10cSrcweir      * one protocol line, format it and print it out.
622cdf0e10cSrcweir      *
623cdf0e10cSrcweir      * @param nType
624cdf0e10cSrcweir      *          mark a line as a special one or open/close scopes
625cdf0e10cSrcweir      *
626cdf0e10cSrcweir      * @param sMessage
627cdf0e10cSrcweir      *          the message, which the outside code wish to be written into the log
628cdf0e10cSrcweir      */
log( int nType , String sMessage )629cdf0e10cSrcweir     public synchronized void log( /*IN*/ int    nType    ,
630cdf0e10cSrcweir                                   /*IN*/ String sMessage )
631cdf0e10cSrcweir     {
632cdf0e10cSrcweir         nType = (nType & ~m_nFilter);
633cdf0e10cSrcweir         if (nType == 0)
634cdf0e10cSrcweir             return;
635cdf0e10cSrcweir 
636cdf0e10cSrcweir         ++m_nLine;
637cdf0e10cSrcweir 
638*1fbfd7a2Smseidel         // it's necessary to open scopes before creating the protocol line
639cdf0e10cSrcweir         // to guarantee right tab handling for new scope value!
640cdf0e10cSrcweir         if ((nType & TYPE_SCOPE_OPEN) == TYPE_SCOPE_OPEN)
641cdf0e10cSrcweir             ++m_nScope;
642cdf0e10cSrcweir 
643cdf0e10cSrcweir         // create the protocol line
644cdf0e10cSrcweir         ProtocolLine aLine     = new ProtocolLine(m_nLine, m_nScope, nType, sMessage);
645cdf0e10cSrcweir         String       sAsciiLog = aLine.toString();
646cdf0e10cSrcweir         String       sHTMLLog  = aLine.toHTML();
647cdf0e10cSrcweir 
648*1fbfd7a2Smseidel         // it's necessary to close scope after creating the protocol line
649cdf0e10cSrcweir         // to guarantee right tab handling for old scope value!
650cdf0e10cSrcweir         if (
651cdf0e10cSrcweir             ( m_nScope                  >  0               ) &&
652cdf0e10cSrcweir             ((nType & TYPE_SCOPE_CLOSE) == TYPE_SCOPE_CLOSE)
653cdf0e10cSrcweir            )
654cdf0e10cSrcweir         {
655cdf0e10cSrcweir             --m_nScope;
656cdf0e10cSrcweir         }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir         // update statistic values
659cdf0e10cSrcweir         if (aLine.isTestMark())
660cdf0e10cSrcweir             ++m_nTestMarks;
661cdf0e10cSrcweir         if (aLine.isWarning())
662cdf0e10cSrcweir             ++m_nWarnings;
663cdf0e10cSrcweir         if (aLine.isError())
664cdf0e10cSrcweir             ++m_nErrors;
665cdf0e10cSrcweir 
666cdf0e10cSrcweir         // no else - it's a bit field of possible reactions!
667cdf0e10cSrcweir         if ((m_nMode & MODE_STDOUT) == MODE_STDOUT)
668cdf0e10cSrcweir             System.out.print(sAsciiLog);
669cdf0e10cSrcweir         // no else - it's a bit field of possible reactions!
670cdf0e10cSrcweir         if ((m_nMode & MODE_STDERR) == MODE_STDERR)
671cdf0e10cSrcweir             System.err.print(sAsciiLog);
672cdf0e10cSrcweir         // no else - it's a bit field of possible reactions!
673cdf0e10cSrcweir         // But these both conditions must be handled together.
67407a3d7f1SPedro Giffuni         // Because we can't generate different types of log contents to the same log file.
675*1fbfd7a2Smseidel         // We prefer HTML if both types are set.
676cdf0e10cSrcweir         if (
677cdf0e10cSrcweir             ((m_nMode & MODE_HTML ) == MODE_HTML ) ||
678cdf0e10cSrcweir             ((m_nMode & MODE_ASCII) == MODE_ASCII)
679cdf0e10cSrcweir            )
680cdf0e10cSrcweir         {
681cdf0e10cSrcweir             boolean bAppend = (m_nLine>1);
682cdf0e10cSrcweir             String  sContent;
683cdf0e10cSrcweir             if ((m_nMode & MODE_HTML) == MODE_HTML)
684cdf0e10cSrcweir             {
685cdf0e10cSrcweir                 if (! bAppend)
686cdf0e10cSrcweir                     sContent = impl_generateHTMLHeader()+sHTMLLog;
687cdf0e10cSrcweir                 else
688cdf0e10cSrcweir                     sContent = sHTMLLog;
689cdf0e10cSrcweir             }
690cdf0e10cSrcweir             else
691cdf0e10cSrcweir             {
692cdf0e10cSrcweir                 if (! bAppend)
693cdf0e10cSrcweir                     sContent = impl_generateAsciiHeader()+sAsciiLog;
694cdf0e10cSrcweir                 else
695cdf0e10cSrcweir                     sContent = sAsciiLog;
696cdf0e10cSrcweir             }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir             impl_writeToLogFile(m_sFileName, bAppend, sContent);
699cdf0e10cSrcweir         }
700cdf0e10cSrcweir     }
701cdf0e10cSrcweir 
702cdf0e10cSrcweir     // ____________________
defineHyperlink( String sTarget , String sDescription)703cdf0e10cSrcweir     public synchronized void defineHyperlink( /*IN*/ String sTarget     ,
704cdf0e10cSrcweir                                               /*IN*/ String sDescription)
705cdf0e10cSrcweir     {
706cdf0e10cSrcweir         if ((m_nMode & MODE_HTML) != MODE_HTML)
707cdf0e10cSrcweir             return;
708cdf0e10cSrcweir 
709cdf0e10cSrcweir         StringBuffer sLog = new StringBuffer(1000);
710cdf0e10cSrcweir         sLog.append("<a href=\"");
711cdf0e10cSrcweir         sLog.append(sTarget     );
712cdf0e10cSrcweir         sLog.append("\">"       );
713cdf0e10cSrcweir         sLog.append(sDescription);
714cdf0e10cSrcweir         sLog.append("</a>"      );
715cdf0e10cSrcweir 
716cdf0e10cSrcweir         log(TYPE_LINK, sLog.toString());
717cdf0e10cSrcweir     }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir     // ____________________
720cdf0e10cSrcweir     /**
721cdf0e10cSrcweir      * log the current statistic values
722cdf0e10cSrcweir      * We write it into our protocol buffer and
723cdf0e10cSrcweir      * reset it.
724cdf0e10cSrcweir      */
logStatistics()725cdf0e10cSrcweir     public synchronized void logStatistics()
726cdf0e10cSrcweir     {
727cdf0e10cSrcweir                   m_aEndTime = new Timestamp(System.currentTimeMillis());
728cdf0e10cSrcweir         Timestamp aDiff      = new Timestamp(m_aEndTime.getTime()-m_aStartTime.getTime());
729cdf0e10cSrcweir 
730cdf0e10cSrcweir         int nLogType = TYPE_STATISTIC;
731cdf0e10cSrcweir         if (m_nErrors > 0)
732cdf0e10cSrcweir             nLogType = TYPE_ERROR_INFO;
733cdf0e10cSrcweir         else
734cdf0e10cSrcweir         if (m_nWarnings > 0)
735cdf0e10cSrcweir             nLogType = TYPE_WARNING_INFO;
736cdf0e10cSrcweir 
737cdf0e10cSrcweir         log(nLogType | TYPE_SCOPE_OPEN , "statistic:"                      );
738cdf0e10cSrcweir         log(nLogType                   , "tests        = "+m_nTestMarks    );
739cdf0e10cSrcweir         log(nLogType                   , "errors       = "+m_nErrors       );
740cdf0e10cSrcweir         log(nLogType                   , "warnings     = "+m_nWarnings     );
741cdf0e10cSrcweir         log(nLogType                   , "elapsed time = "+aDiff.toString());
742cdf0e10cSrcweir         log(nLogType | TYPE_SCOPE_CLOSE, ""                                );
743cdf0e10cSrcweir 
744cdf0e10cSrcweir         resetStatistics();
745cdf0e10cSrcweir     }
746cdf0e10cSrcweir 
resetStatistics()747cdf0e10cSrcweir     public synchronized void resetStatistics()
748cdf0e10cSrcweir     {
749cdf0e10cSrcweir         m_nTestMarks = 0;
750cdf0e10cSrcweir         m_nWarnings  = 0;
751cdf0e10cSrcweir         m_nErrors    = 0;
752cdf0e10cSrcweir         m_aStartTime = new Timestamp(System.currentTimeMillis());
753cdf0e10cSrcweir     }
754cdf0e10cSrcweir 
755cdf0e10cSrcweir     // ____________________
756cdf0e10cSrcweir     /**
757cdf0e10cSrcweir      * returns a generic html header for generating html log files
758cdf0e10cSrcweir      *
75930acf5e8Spfg      * It's used from the method finish() to generate a valid html formatted file.
760*1fbfd7a2Smseidel      * For that it's necessary to open some special html targets like e.g. <html>.
761cdf0e10cSrcweir      *
762cdf0e10cSrcweir      * @return  A string, which includes the whole header.
763cdf0e10cSrcweir      *
764e6b649b5SPedro Giffuni      * @see     #finish()
765e6b649b5SPedro Giffuni      * @see     #impl_generateHTMLFooter()
766cdf0e10cSrcweir      */
impl_generateHTMLHeader()767cdf0e10cSrcweir     private String impl_generateHTMLHeader()
768cdf0e10cSrcweir     {
769cdf0e10cSrcweir         return "<html>\n<head>\n<title>"+m_sFileName+"</title>\n</head>\n<body>\n<table>\n";
770cdf0e10cSrcweir     }
771cdf0e10cSrcweir 
impl_generateAsciiHeader()772cdf0e10cSrcweir     private String impl_generateAsciiHeader()
773cdf0e10cSrcweir     {
774cdf0e10cSrcweir         return "********************************************************************************\n";
775cdf0e10cSrcweir     }
776cdf0e10cSrcweir 
impl_generateHTMLFooter()777cdf0e10cSrcweir     private String impl_generateHTMLFooter()
778cdf0e10cSrcweir     {
779cdf0e10cSrcweir         return "\n</table>\n</body>\n</html>\n";
780cdf0e10cSrcweir     }
781cdf0e10cSrcweir 
impl_generateAsciiFooter()782cdf0e10cSrcweir     private String impl_generateAsciiFooter()
783cdf0e10cSrcweir     {
784cdf0e10cSrcweir         return "\n\n";
785cdf0e10cSrcweir     }
786cdf0e10cSrcweir 
787cdf0e10cSrcweir     // ____________________
788cdf0e10cSrcweir     /**
789cdf0e10cSrcweir      * helper to log different representations of a property(array)
790cdf0e10cSrcweir      *
791cdf0e10cSrcweir      * @param   sOut
792cdf0e10cSrcweir      *              used to generate the log output there.
793cdf0e10cSrcweir      *
794e6b649b5SPedro Giffuni      * @param   lProps
795cdf0e10cSrcweir      *              represent the property(array) to be logged.
796cdf0e10cSrcweir      */
impl_logPropertyArray( StringBuffer sOut , com.sun.star.beans.PropertyValue[] lProps )797cdf0e10cSrcweir     private void impl_logPropertyArray( /*OUT*/ StringBuffer                       sOut   ,
798cdf0e10cSrcweir                                         /*IN */ com.sun.star.beans.PropertyValue[] lProps )
799cdf0e10cSrcweir     {
800cdf0e10cSrcweir         int i = 0;
801cdf0e10cSrcweir         int c = lProps.length;
802cdf0e10cSrcweir 
803cdf0e10cSrcweir         for (i=0; i<c; ++i)
804cdf0e10cSrcweir             impl_logProperty(sOut, lProps[i]);
805cdf0e10cSrcweir     }
806cdf0e10cSrcweir 
impl_logPropertyArray( StringBuffer sOut , com.sun.star.beans.NamedValue[] lProps )807cdf0e10cSrcweir     private void impl_logPropertyArray( /*OUT*/ StringBuffer                    sOut   ,
808cdf0e10cSrcweir                                         /*IN */ com.sun.star.beans.NamedValue[] lProps )
809cdf0e10cSrcweir     {
810cdf0e10cSrcweir         int i = 0;
811cdf0e10cSrcweir         int c = lProps.length;
812cdf0e10cSrcweir 
813cdf0e10cSrcweir         for (i=0; i<c; ++i)
814cdf0e10cSrcweir             impl_logProperty(sOut, lProps[i]);
815cdf0e10cSrcweir     }
816cdf0e10cSrcweir 
impl_logProperty( StringBuffer sOut , com.sun.star.beans.NamedValue aProp )817cdf0e10cSrcweir     private void impl_logProperty( /*OUT*/ StringBuffer                  sOut  ,
818cdf0e10cSrcweir                                    /*IN*/  com.sun.star.beans.NamedValue aProp )
819cdf0e10cSrcweir     {
820cdf0e10cSrcweir         sOut.append("\""+aProp.Name+"\" = ");
821cdf0e10cSrcweir         impl_logAny(sOut, aProp.Value);
822cdf0e10cSrcweir     }
823cdf0e10cSrcweir 
impl_logProperty( StringBuffer sOut , com.sun.star.beans.PropertyValue aProp )824cdf0e10cSrcweir     private void impl_logProperty( /*OUT*/ StringBuffer                     sOut  ,
825cdf0e10cSrcweir                                    /*IN*/  com.sun.star.beans.PropertyValue aProp )
826cdf0e10cSrcweir     {
827cdf0e10cSrcweir         sOut.append("\""+aProp.Name+"\" = ");
828cdf0e10cSrcweir         impl_logAny(sOut, aProp.Value);
829cdf0e10cSrcweir     }
830cdf0e10cSrcweir 
831cdf0e10cSrcweir     // ____________________
832cdf0e10cSrcweir     /**
833*1fbfd7a2Smseidel      * it tries to convert the given any into a suitable string notation .-)
834cdf0e10cSrcweir     */
impl_logAny( StringBuffer sOut , Object aAny )835cdf0e10cSrcweir     private synchronized void impl_logAny( /*OUT*/ StringBuffer sOut ,
836cdf0e10cSrcweir                                            /*IN */ Object       aAny )
837cdf0e10cSrcweir     {
838cdf0e10cSrcweir         try
839cdf0e10cSrcweir         {
840cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isVoid(aAny))
841cdf0e10cSrcweir             {
842cdf0e10cSrcweir                 sOut.append("[void] {");
843cdf0e10cSrcweir             }
844cdf0e10cSrcweir             else
845cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isChar(aAny))
846cdf0e10cSrcweir             {
847cdf0e10cSrcweir                 sOut.append("[char] {");
848cdf0e10cSrcweir                 sOut.append(com.sun.star.uno.AnyConverter.toChar(aAny));
849cdf0e10cSrcweir                 sOut.append("}");
850cdf0e10cSrcweir             }
851cdf0e10cSrcweir             else
852cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isBoolean(aAny))
853cdf0e10cSrcweir             {
854cdf0e10cSrcweir                 sOut.append("[boolean] {");
855cdf0e10cSrcweir                 if (com.sun.star.uno.AnyConverter.toBoolean(aAny))
856cdf0e10cSrcweir                     sOut.append("TRUE");
857cdf0e10cSrcweir                 else
858cdf0e10cSrcweir                     sOut.append("FALSE");
859cdf0e10cSrcweir                 sOut.append("}");
860cdf0e10cSrcweir             }
861cdf0e10cSrcweir             else
862cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isByte(aAny))
863cdf0e10cSrcweir             {
864cdf0e10cSrcweir                 sOut.append("[byte] {");
865cdf0e10cSrcweir                 sOut.append(com.sun.star.uno.AnyConverter.toByte(aAny));
866cdf0e10cSrcweir                 sOut.append("}");
867cdf0e10cSrcweir             }
868cdf0e10cSrcweir             else
869cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isShort(aAny))
870cdf0e10cSrcweir             {
871cdf0e10cSrcweir                 sOut.append("[short] {");
872cdf0e10cSrcweir                 sOut.append(com.sun.star.uno.AnyConverter.toShort(aAny));
873cdf0e10cSrcweir                 sOut.append("}");
874cdf0e10cSrcweir             }
875cdf0e10cSrcweir             else
876cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isInt(aAny))
877cdf0e10cSrcweir             {
878cdf0e10cSrcweir                 sOut.append("[int] {");
879cdf0e10cSrcweir                 sOut.append(com.sun.star.uno.AnyConverter.toInt(aAny));
880cdf0e10cSrcweir                 sOut.append("}");
881cdf0e10cSrcweir             }
882cdf0e10cSrcweir             else
883cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isLong(aAny))
884cdf0e10cSrcweir             {
885cdf0e10cSrcweir                 sOut.append("[long] {");
886cdf0e10cSrcweir                 sOut.append(com.sun.star.uno.AnyConverter.toLong(aAny));
887cdf0e10cSrcweir                 sOut.append("}");
888cdf0e10cSrcweir             }
889cdf0e10cSrcweir             else
890cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isFloat(aAny))
891cdf0e10cSrcweir             {
892cdf0e10cSrcweir                 sOut.append("[float] {");
893cdf0e10cSrcweir                 sOut.append(com.sun.star.uno.AnyConverter.toFloat(aAny));
894cdf0e10cSrcweir                 sOut.append("}");
895cdf0e10cSrcweir             }
896cdf0e10cSrcweir             else
897cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isDouble(aAny))
898cdf0e10cSrcweir             {
899cdf0e10cSrcweir                 sOut.append("[double] {");
900cdf0e10cSrcweir                 sOut.append(com.sun.star.uno.AnyConverter.toDouble(aAny));
901cdf0e10cSrcweir                 sOut.append("}");
902cdf0e10cSrcweir             }
903cdf0e10cSrcweir             else
904cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isString(aAny))
905cdf0e10cSrcweir             {
906cdf0e10cSrcweir                 sOut.append("[string] {");
907cdf0e10cSrcweir                 sOut.append(com.sun.star.uno.AnyConverter.toString(aAny));
908cdf0e10cSrcweir                 sOut.append("}");
909cdf0e10cSrcweir             }
910cdf0e10cSrcweir             else
911cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isEnum(aAny))
912cdf0e10cSrcweir             {
913cdf0e10cSrcweir                 sOut.append("[enum] {");
914cdf0e10cSrcweir                 sOut.append("}");
915cdf0e10cSrcweir             }
916cdf0e10cSrcweir             else
917cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isType(aAny))
918cdf0e10cSrcweir             {
919cdf0e10cSrcweir                 sOut.append("[type] {");
920cdf0e10cSrcweir                 sOut.append("}");
921cdf0e10cSrcweir             }
922cdf0e10cSrcweir             else
923cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isArray(aAny))
924cdf0e10cSrcweir             {
925cdf0e10cSrcweir                 if (aAny instanceof java.lang.String[])
926cdf0e10cSrcweir                 {
927cdf0e10cSrcweir                     sOut.append("[sequence< string >] {");
928cdf0e10cSrcweir                     sOut.append("}");
929cdf0e10cSrcweir                 }
930cdf0e10cSrcweir                 else
931cdf0e10cSrcweir                 if (aAny instanceof com.sun.star.beans.PropertyValue[])
932cdf0e10cSrcweir                 {
933cdf0e10cSrcweir                     sOut.append("[sequence< PropertyValue >] {");
934cdf0e10cSrcweir                     com.sun.star.beans.PropertyValue[] lSubProps = (com.sun.star.beans.PropertyValue[])com.sun.star.uno.AnyConverter.toArray(aAny);
935cdf0e10cSrcweir                     impl_logPropertyArray(sOut, lSubProps);
936cdf0e10cSrcweir                     sOut.append("}");
937cdf0e10cSrcweir                 }
938cdf0e10cSrcweir                 else
939cdf0e10cSrcweir                 if (aAny instanceof com.sun.star.beans.NamedValue[])
940cdf0e10cSrcweir                 {
941cdf0e10cSrcweir                     sOut.append("[sequence< NamedValue >] {");
942cdf0e10cSrcweir                     com.sun.star.beans.NamedValue[] lSubProps = (com.sun.star.beans.NamedValue[])com.sun.star.uno.AnyConverter.toArray(aAny);
943cdf0e10cSrcweir                     impl_logPropertyArray(sOut, lSubProps);
944cdf0e10cSrcweir                     sOut.append("}");
945cdf0e10cSrcweir                 }
946cdf0e10cSrcweir                 else
947cdf0e10cSrcweir                 {
948cdf0e10cSrcweir                     sOut.append("[unknown array] {-}");
949cdf0e10cSrcweir                 }
950cdf0e10cSrcweir             }
951cdf0e10cSrcweir             else
952cdf0e10cSrcweir             if (com.sun.star.uno.AnyConverter.isObject(aAny))
953cdf0e10cSrcweir             {
954cdf0e10cSrcweir                 sOut.append("[object] {");
955cdf0e10cSrcweir                 // TODO
956cdf0e10cSrcweir                 sOut.append("}");
957cdf0e10cSrcweir             }
958cdf0e10cSrcweir 
959cdf0e10cSrcweir             if ((m_nMode & MODE_HTML) == MODE_HTML)
960cdf0e10cSrcweir                 sOut.append("<br>");
961cdf0e10cSrcweir             else
962cdf0e10cSrcweir                 sOut.append("\n");
963cdf0e10cSrcweir         }
964cdf0e10cSrcweir         catch(com.sun.star.lang.IllegalArgumentException exIll)
965cdf0e10cSrcweir         {
966cdf0e10cSrcweir             sOut.append("Got exception during property conversion.\n");
967cdf0e10cSrcweir             sOut.append(exIll.getMessage());
968cdf0e10cSrcweir             sOut.append("\n");
969cdf0e10cSrcweir         }
970cdf0e10cSrcweir     }
971cdf0e10cSrcweir 
972cdf0e10cSrcweir     // ____________________
973cdf0e10cSrcweir     /**
974cdf0e10cSrcweir      * Writes the given content to the specified log file.
975cdf0e10cSrcweir      */
impl_writeToLogFile(String sFileName, boolean bAppend , String sContent )976cdf0e10cSrcweir     private void impl_writeToLogFile(String  sFileName,
977cdf0e10cSrcweir                                      boolean bAppend  ,
978cdf0e10cSrcweir                                      String  sContent )
979cdf0e10cSrcweir     {
980cdf0e10cSrcweir         try
981cdf0e10cSrcweir         {
982cdf0e10cSrcweir             FileWriter aLogFile = new FileWriter(sFileName, bAppend);
983cdf0e10cSrcweir             aLogFile.write(sContent);
984cdf0e10cSrcweir             aLogFile.flush();
985cdf0e10cSrcweir             aLogFile.close();
986cdf0e10cSrcweir             aLogFile = null;
987cdf0e10cSrcweir         }
988cdf0e10cSrcweir         catch (java.io.IOException exIO)
989cdf0e10cSrcweir         {
990cdf0e10cSrcweir             System.err.println("Can't dump protocol into log file.");
991cdf0e10cSrcweir             System.err.println(exIO);
992cdf0e10cSrcweir             exIO.printStackTrace();
993cdf0e10cSrcweir         }
994cdf0e10cSrcweir     }
995cdf0e10cSrcweir }
996*1fbfd7a2Smseidel 
997