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 convwatch;
29 
30 import java.io.File;
31 import java.io.FileWriter;
32 
33 public class INIOutputter
34 {
35     FileWriter m_aOut;
36     String m_sFilename;
37     String m_sNamePrefix;              // the HTML files used a suffix to build it's right name
38 
39     /**
40      * ls is the current line separator (carridge return)
41      */
42     String ls;
43 
44     public static INIOutputter create( String _sOutputPath, String _sHTMLFilename, String _sNamePrefix, String _sTitle )
45         {
46             FileHelper.makeDirectories("", _sOutputPath);
47             INIOutputter a = new INIOutputter();
48             String fs = System.getProperty("file.separator");
49             String sFilename = _sOutputPath + fs + _sHTMLFilename;
50 
51             try
52             {
53                 File outputFile = new File(sFilename);
54                 a.m_aOut = new FileWriter(outputFile.toString());
55                 a.ls = System.getProperty("line.separator");
56             }
57             catch (java.io.IOException e)
58             {
59                 e.printStackTrace();
60                 GlobalLogWriter.get().println("ERROR: Can't create INI Outputter");
61                 return null;
62             }
63             a.m_sFilename = sFilename;
64             a.m_sNamePrefix = _sNamePrefix;
65 
66             return a;
67         }
68     public String getFilename() {return m_sFilename;}
69 
70     public void createHeader()
71         {
72             try
73             {
74                 m_aOut.write("; This file is automatically created by a convwatch run" + ls);
75                 m_aOut.write("; " + ls);
76                 m_aOut.write("; If you see this file in a browser you may have forgotten to set the follows in the property file" + ls);
77                 m_aOut.write("; " + PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX + "=http://lla-1.germany/gfxcmp/cw.php?inifile=" + ls);
78                 m_aOut.write("; Please check the documentation if you got confused." + ls);
79                 m_aOut.write("; " + ls);
80                 m_aOut.write("; " + ls);
81             }
82             catch (java.io.IOException e)
83             {
84             }
85         }
86 
87     public void writeSection(String _sSectionName)
88         {
89             try
90             {
91                 m_aOut.write("[" + _sSectionName + "]" + ls);
92                 m_aOut.flush();
93             }
94             catch (java.io.IOException e)
95             {
96             }
97         }
98 
99     public void writeValue(String _sName, String _sValue)
100         {
101             try
102             {
103                 m_aOut.write(_sName + "=" + _sValue + ls);
104                 m_aOut.flush();
105             }
106             catch (java.io.IOException e)
107             {
108             }
109         }
110 
111     public void startSection(int _nNumber)
112         {
113             writeSection( "page" + String.valueOf(_nNumber));
114         }
115 
116     public void close()
117         {
118             try
119             {
120                 m_aOut.flush();
121                 m_aOut.close();
122             }
123             catch (java.io.IOException e)
124             {
125             }
126         }
127 
128     public void checkLine(StatusHelper _aStatus, boolean _bCurrentResult)
129         {
130             try
131             {
132                 m_aOut.write( "oldgfx=" + _aStatus.m_sOldGfx + ls);
133                 m_aOut.write( "newgfx=" + _aStatus.m_sNewGfx + ls);
134                 m_aOut.write( "diffgfx=" + _aStatus.m_sDiffGfx + ls);
135 
136                 String sPercent = String.valueOf(_aStatus.nPercent) + "%";
137                 if (_aStatus.nPercent > 0 && _aStatus.nPercent < 5)
138                 {
139                     sPercent += " (less 5% is ok)";
140                 }
141                 m_aOut.write("percent=" +  sPercent + ls);
142 
143                 if (_aStatus.m_sDiff_BM_Gfx == null)
144                 {
145                     m_aOut.write("BM=false" + ls);
146                 }
147                 else
148                 {
149                     m_aOut.write("BM=true" + ls);
150                     m_aOut.write( "old_BM_gfx=" + _aStatus.m_sOld_BM_Gfx + ls);
151                     m_aOut.write( "new_BM_gfx=" + _aStatus.m_sNew_BM_Gfx + ls);
152                     m_aOut.write( "diff_BM_gfx=" + _aStatus.m_sDiff_BM_Gfx + ls);
153 
154                     String sPercent2 = String.valueOf(_aStatus.nPercent2) + "%";
155                     if (_aStatus.nPercent2 > 0 && _aStatus.nPercent2 < 5)
156                     {
157                         sPercent2 += " (less 5% is ok)";
158                     }
159                     m_aOut.write("percent2=" +  sPercent2 + ls);
160                 }
161 
162                 writeResult(_bCurrentResult);
163                 m_aOut.flush();
164             }
165             catch (java.io.IOException e)
166             {
167             }
168         }
169 
170     void writeResult(boolean _bCurrentResult) throws java.io.IOException
171         {
172             // is the check positiv, in a defined range
173             if (_bCurrentResult)
174             {
175                 m_aOut.write("result=YES" + ls);
176             }
177             else
178             {
179                 m_aOut.write("result=NO" + ls);
180             }
181         }
182 
183     public void checkDiffDiffLine(StatusHelper _aStatus, boolean _bCurrentResult)
184         {
185             try
186             {
187                 m_aOut.write( "oldgfx=" + _aStatus.m_sOldGfx + ls);
188                 m_aOut.write( "newgfx=" + _aStatus.m_sNewGfx + ls);
189                 m_aOut.write( "diffgfx=" + _aStatus.m_sDiffGfx + ls);
190 
191                 String sPercent = String.valueOf(_aStatus.nPercent) + "%";
192                 // if (_aStatus.nPercent > 0 && _aStatus.nPercent < 5)
193                 // {
194                 //     sPercent += " (less 5% is ok)";
195                 // }
196                 m_aOut.write("percent=" + sPercent + ls);
197 
198                 // is the check positiv, in a defined range
199                 writeResult(_bCurrentResult);
200                 m_aOut.flush();
201             }
202             catch (java.io.IOException e)
203             {
204             }
205         }
206 
207 }
208