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 
28 package stats;
29 
30 import share.LogWriter;
31 import java.io.File;
32 import java.io.FileWriter;
33 
34 public class SimpleFileOutProducer implements LogWriter {
35 
36 
37     /** initialization, here a filename might be given
38      * or a dbUrL
39      */
40     public boolean initialize(share.DescEntry entry, boolean active) {
41         return true;
42     }
43 
44     /** Method to print
45      */
46     public void println(String msg) {
47 
48     }
49 
50     /** will mostly be used by outproducers to sum up
51      * the information, maybe write them to a db
52      */
53     public boolean summary(share.DescEntry entry) {
54         try {
55             String outpath = (String) entry.UserDefinedParams.get("OutputPath");
56             if (outpath==null) {
57                 System.out.println("## Parameter OutputPath isn't defined using default");
58                 return summary_default(entry);
59             }
60             String FileName = entry.longName + ".out";
61             if (!entry.EntryType.equals("component")) {
62                 FileName = entry.longName.substring(0,
63                                 entry.longName.indexOf(":")) + ".out";
64             }
65             util.utils.make_Directories("",outpath);
66             File outputFile = new File(outpath, FileName);
67             FileWriter out = new FileWriter(outputFile.toString(),true);
68             String ls = System.getProperty("line.separator");
69             String date = new java.util.Date().toString();
70             String header = "***** State for "+entry.longName+"( "+ date +" ) ******";
71             out.write(header+ls);
72             if (entry.hasErrorMsg) {
73                 out.write(entry.ErrorMsg+ls);
74                 out.write("Whole "+entry.EntryType+": "+entry.State+ls);
75             } else {
76                 out.write("Whole "+entry.EntryType+": "+entry.State+ls);
77             }
78             String bottom="";
79             for (int i=0;i<header.length();i++) {
80                 bottom += "*";
81             }
82             out.write(bottom+ls);
83             out.write(""+ls);
84             out.close();
85         } catch (java.io.IOException e) {
86 
87         }
88         return true;
89     }
90 
91     public boolean summary_default(share.DescEntry entry) {
92         String header = "***** State for "+entry.longName+" ******";
93         System.out.println(header);
94         if (entry.hasErrorMsg) {
95             System.out.println(entry.ErrorMsg);
96             System.out.println("Whole "+entry.EntryType+": "+entry.State);
97         } else {
98             System.out.println("Whole "+entry.EntryType+": "+entry.State);
99         }
100         for (int i=0;i<header.length();i++) {
101             System.out.print("*");
102         }
103         System.out.println("");
104         return true;
105     }
106 
107     public Object getWatcher() {
108         return null;
109     }
110 
111     public void setWatcher(Object watcher) {
112     }
113 
114 }
115