Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / qadevOOo / runner / stats / InternalLogWriter.java
bloba39e372a61cced99be8181542d1534528ad23246
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package stats;
20 import java.io.PrintWriter;
21 import java.io.StringWriter;
23 /**
24 * Write all logs into a java.io.PrintWriter, i.e. a StringBuffer.
25 * Log is gathered there.
27 public class InternalLogWriter implements share.LogWriter {
28 /** log active **/
29 private boolean active;
30 /** write all output to a StringBuffer **/
31 private StringWriter writer = new StringWriter();
32 private PrintWriter printWriter;
34 /**
35 * c'*tor
37 public InternalLogWriter() {
38 printWriter = new PrintWriter(writer);
39 active = true;
42 /**
43 * Initialization.
44 * @param entry The description entry.
45 * @param active Logging is active.
46 * @return True, if initialize worked.
48 public boolean initialize(share.DescEntry entry, boolean active) {
49 this.active = active;
50 return true;
53 /**
54 * Method to print a line that is added to the StringBuffer.
55 * @param msg The message that is printed.
57 public void println(String msg) {
58 if (active)
59 printWriter.println(msg);
62 /**
63 * Is used to sum up the information.
64 * The summary is also added to the StringBuffer.
65 * @param entry The description entry.
66 * @return True, if a summary could be created.
68 public boolean summary(share.DescEntry entry) {
69 // linePrefix = "";
70 String header = "***** State for "+entry.longName+" ******";
71 printWriter.println(header);
72 if (entry.hasErrorMsg) {
73 printWriter.println(entry.ErrorMsg);
74 printWriter.println("Whole "+entry.EntryType+": "+entry.State);
75 } else {
76 printWriter.println("Whole "+entry.EntryType+": "+entry.State);
78 for (int i=0;i<header.length();i++) {
79 printWriter.print("*");
81 printWriter.println("");
82 return true;
85 /**
86 * Return all the written stuff.
87 * @return All that was written to the StringBuffer with the
88 * 'println()', 'print()' and 'summarize()' methods.
89 * The StringBuffer is emptied afterwards.
90 **/
91 public String getLog() {
92 String message = writer.getBuffer().toString();
93 writer = new StringWriter();
94 return message;
97 public void setWatcher(Object watcher) {