1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: InternalLogWriter.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import java
.io
.PrintWriter
;
33 import java
.io
.StringWriter
;
36 * Write all logs into a java.io.PrintWriter, i.e. a StringBuffer.
37 * Log is gathered there.
39 public class InternalLogWriter
extends PrintWriter
40 implements share
.LogWriter
{
43 /** write all output to a StringBuffer **/
44 static StringWriter writer
= new StringWriter();
49 public InternalLogWriter() {
50 super(new PrintWriter(writer
));
56 * @param entry The description entry.
57 * @param active Logging is active.
58 * @return True, if initialize worked.
60 public boolean initialize(share
.DescEntry entry
, boolean active
) {
66 * Method to print a line that is added to the StringBuffer.
67 * @param msg The message that is printed.
69 public void println(String msg
) {
75 * Method to print to the StringBuffer.
76 * @param msg The message that is printed.
78 public void print(String msg
) {
85 * Is used to sum up the information.
86 * The summary is also added to the StringBuffer.
87 * @param entry The description entry.
88 * @return True, if a summary could be created.
90 public boolean summary(share
.DescEntry entry
) {
92 String header
= "***** State for "+entry
.longName
+" ******";
94 if (entry
.hasErrorMsg
) {
95 println(entry
.ErrorMsg
);
96 println("Whole "+entry
.EntryType
+": "+entry
.State
);
98 println("Whole "+entry
.EntryType
+": "+entry
.State
);
100 for (int i
=0;i
<header
.length();i
++) {
108 * Return all the written stuff.
109 * @return All that was written to the StringBuffer with the
110 * 'println()', 'print()' and 'summarize()' methods.
111 * The StringBuffer is emptied afterwards.
113 public String
getLog() {
114 String message
= writer
.getBuffer().toString();
115 writer
= new StringWriter();
119 public Object
getWatcher() {
123 public void setWatcher(Object watcher
) {