merged tag ooo/DEV300_m102
[LibreOffice.git] / qadevOOo / runner / stats / InternalLogWriter.java
blobb3c71217fb6451ede3856a5b8cd1123cf9a4cad4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package stats;
29 import java.io.PrintWriter;
30 import java.io.StringWriter;
32 /**
33 * Write all logs into a java.io.PrintWriter, i.e. a StringBuffer.
34 * Log is gathered there.
36 public class InternalLogWriter extends PrintWriter
37 implements share.LogWriter {
38 /** log active **/
39 boolean active;
40 /** write all output to a StringBuffer **/
41 static StringWriter writer = new StringWriter();
43 /**
44 * c'*tor
46 public InternalLogWriter() {
47 super(new PrintWriter(writer));
48 active = true;
51 /**
52 * Initialization.
53 * @param entry The description entry.
54 * @param active Logging is active.
55 * @return True, if initialize worked.
57 public boolean initialize(share.DescEntry entry, boolean active) {
58 this.active = active;
59 return true;
62 /**
63 * Method to print a line that is added to the StringBuffer.
64 * @param msg The message that is printed.
66 public void println(String msg) {
67 if (active)
68 super.println(msg);
71 /**
72 * Method to print to the StringBuffer.
73 * @param msg The message that is printed.
75 public void print(String msg) {
76 if (active)
77 super.print(msg);
81 /**
82 * Is used to sum up the information.
83 * The summary is also added to the StringBuffer.
84 * @param entry The description entry.
85 * @return True, if a summary could be created.
87 public boolean summary(share.DescEntry entry) {
88 // linePrefix = "";
89 String header = "***** State for "+entry.longName+" ******";
90 println(header);
91 if (entry.hasErrorMsg) {
92 println(entry.ErrorMsg);
93 println("Whole "+entry.EntryType+": "+entry.State);
94 } else {
95 println("Whole "+entry.EntryType+": "+entry.State);
97 for (int i=0;i<header.length();i++) {
98 print("*");
100 println("");
101 return true;
105 * Return all the written stuff.
106 * @return All that was written to the StringBuffer with the
107 * 'println()', 'print()' and 'summarize()' methods.
108 * The StringBuffer is emptied afterwards.
110 public String getLog() {
111 String message = writer.getBuffer().toString();
112 writer = new StringWriter();
113 return message;
116 public Object getWatcher() {
117 return null;
120 public void setWatcher(Object watcher) {