1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 package stats; 28 29 import java.io.PrintWriter; 30 import java.io.StringWriter; 31 32 /** 33 * Write all logs into a java.io.PrintWriter, i.e. a StringBuffer. 34 * Log is gathered there. 35 */ 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(); 42 43 /** 44 * c'*tor 45 */ 46 public InternalLogWriter() { 47 super(new PrintWriter(writer)); 48 active = true; 49 } 50 51 /** 52 * Initialization. 53 * @param entry The description entry. 54 * @param active Logging is active. 55 * @return True, if initialize worked. 56 */ 57 public boolean initialize(share.DescEntry entry, boolean active) { 58 this.active = active; 59 return true; 60 } 61 62 /** 63 * Method to print a line that is added to the StringBuffer. 64 * @param msg The message that is printed. 65 */ 66 public void println(String msg) { 67 if (active) 68 super.println(msg); 69 } 70 71 /** 72 * Method to print to the StringBuffer. 73 * @param msg The message that is printed. 74 */ 75 public void print(String msg) { 76 if (active) 77 super.print(msg); 78 79 } 80 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. 86 */ 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); 96 } 97 for (int i=0;i<header.length();i++) { 98 print("*"); 99 } 100 println(""); 101 return true; 102 } 103 104 /** 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. 109 **/ 110 public String getLog() { 111 String message = writer.getBuffer().toString(); 112 writer = new StringWriter(); 113 return message; 114 } 115 116 public Object getWatcher() { 117 return null; 118 } 119 120 public void setWatcher(Object watcher) { 121 } 122 123 } 124 125