merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / convwatch / HTMLOutputter.java
blob7d6119b64bd03ddc94bbe6f2b6f308fb68ebc5dc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: HTMLOutputter.java,v $
10 * $Revision: 1.9.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package convwatch;
33 import java.io.File;
34 import java.io.FileWriter;
35 import helper.OSHelper;
37 public class HTMLOutputter
39 FileWriter m_aOut;
40 String m_sFilename;
41 String m_sNamePrefix; // the HTML files used a suffix to build it's right name
43 /**
44 * ls is the current line separator (carridge return)
46 String ls;
48 HTMLOutputter() {}
49 public static HTMLOutputter create( String _sOutputPath, String _sHTMLFilename, String _sNamePrefix, String _sTitle )
51 FileHelper.makeDirectories("", _sOutputPath);
52 HTMLOutputter a = new HTMLOutputter();
53 String fs = System.getProperty("file.separator");
54 String sFilename = _sOutputPath + fs + _sHTMLFilename;
56 try
58 File outputFile = new File(sFilename);
59 a.m_aOut = new FileWriter(outputFile.toString());
60 a.ls = System.getProperty("line.separator");
62 catch (java.io.IOException e)
64 e.printStackTrace();
65 GlobalLogWriter.get().println("ERROR: Can't create HTML Outputter");
66 return null;
68 a.m_sFilename = sFilename;
69 a.m_sNamePrefix = _sNamePrefix;
70 return a;
72 public String getFilename() {return m_sFilename;}
74 public void header(String _sTitle)
76 try
78 m_aOut.write( "<html>" + ls);
79 m_aOut.write( "<head>" + ls);
80 m_aOut.write( "<title>" + _sTitle + "</title>" + ls);
81 m_aOut.write( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/gfxcmp_ui/xmloff.css\" media=\"screen\" />" + ls);
82 m_aOut.write( "<link rel=\"stylesheet\" type=\"text/css\" href=\"/gfxcmp_ui/style.css\" media=\"screen\" />" + ls);
83 m_aOut.write( "</head>" + ls);
84 m_aOut.write( "<body bgcolor=white>" + ls);
85 m_aOut.flush();
87 catch (java.io.IOException e)
92 final static String TEST_TABLETITLE = "Test";
93 final static String VISUAL_STATUS_TABLETITLE = "Visual status";
94 final static String VISUAL_STATUS_MESSAGE_TABLETITLE = "Message";
96 public void indexSection(String _sOfficeInfo)
98 try
100 m_aOut.write( "<h2>Results for " + _sOfficeInfo + "</h2>" + ls);
101 m_aOut.write( "<p>Legend:<br>");
102 m_aOut.write( stronghtml(FIRSTGFX_TABLETITLE) + " contains the output printed via 'ghostscript' as a jpeg picture.<br>");
104 m_aOut.write( "<table class=\"infotable\">" + ls);
105 m_aOut.write( "<TR>");
106 m_aOut.write( tableHeaderCell(TEST_TABLETITLE));
107 m_aOut.write( tableHeaderCell(TEST_TABLETITLE));
108 m_aOut.write( tableHeaderCell(VISUAL_STATUS_TABLETITLE));
109 m_aOut.write( tableHeaderCell(VISUAL_STATUS_MESSAGE_TABLETITLE));
110 m_aOut.write( "</TR>" + ls);
111 m_aOut.flush();
113 catch (java.io.IOException e)
118 String getHREF(String _sHREF, String _sPathInfo)
120 StringBuffer a = new StringBuffer();
121 if (! OSHelper.isWindows())
123 // System.out.println("Tu'nix system.");
124 a.append("<A HREF=\"");
125 a.append(_sHREF);
126 a.append("\">");
127 a.append(_sPathInfo);
128 a.append("</A>");
130 else
132 // System.out.println("Windows system.");
133 //! this should be replaced by a better method
134 //! name(WIN|UNIX)
135 a.append("<A HREF=\"");
136 a.append(_sHREF);
137 a.append("\">");
138 a.append(_sPathInfo);
139 // a.append("(first)");
140 a.append("</A>");
141 // if (_sHREF.charAt(1) == ':' && (_sHREF.charAt(0) == 'x' || _sHREF.charAt(0) == 'X'))
142 // int index = 0;
143 // index = _sHREF.indexOf("X:");
144 // if (index == -1)
145 // {
146 // index = _sHREF.indexOf("x:");
147 // }
148 // if (index >= 0)
149 // {
150 // // int index = 0;
151 // // remove "X:" and insert "/tausch"
152 // StringBuffer sbUNIXPath = new StringBuffer( _sHREF.substring(0, index) );
153 // sbUNIXPath.append("/tausch");
154 // sbUNIXPath.append(_sHREF.substring(index + 2));
155 // String sUNIXPath = sbUNIXPath.toString();
156 // sUNIXPath = utils.replaceAll13(sUNIXPath, "\\", "/");
158 // a.append("<A HREF=\"");
159 // a.append(sUNIXPath);
160 // a.append("\">");
161 // a.append("(second)");
162 // a.append("</A>");
163 // }
164 // else
165 // {
166 // System.out.println("Path is '" + _sHREF + "'");
167 // }
170 return a.toString();
173 String tableDataCell(String _sValue)
175 StringBuffer a = new StringBuffer();
176 a.append("<TD>");
177 a.append(_sValue);
178 a.append("</TD>");
179 return a.toString();
182 String tableHeaderCell(String _sValue)
184 StringBuffer a = new StringBuffer();
185 a.append("<TH>");
186 a.append(_sValue);
187 a.append("</TH>");
188 return a.toString();
191 public void indexLine(String _sHTMLFile, String _sHTMLName, String _sHTMLFile2, String _sHTMLName2, String _sStatusRunThrough, String _sStatusMessage)
195 m_aOut.write( "<TR>");
196 m_aOut.write(tableDataCell( getHREF(_sHTMLFile, _sHTMLName) ) );
197 if (_sHTMLFile2.length() > 0)
199 m_aOut.write(tableDataCell( getHREF(_sHTMLFile2, _sHTMLName2) ) );
201 else
203 m_aOut.write(tableDataCell( "" ) );
206 m_aOut.write( tableDataCell(_sStatusRunThrough) );
207 m_aOut.write( tableDataCell(_sStatusMessage) );
208 m_aOut.write( "</TR>" + ls);
210 m_aOut.flush();
212 catch (java.io.IOException e)
217 public void close()
221 m_aOut.write( "</TABLE>" + ls);
222 m_aOut.write( "</BODY></HTML>" + ls);
223 m_aOut.flush();
224 m_aOut.close();
226 catch (java.io.IOException e)
231 // -----------------------------------------------------------------------------
232 String stronghtml(String _sValue)
234 StringBuffer a = new StringBuffer();
235 a.append("<STRONG>");
236 a.append(_sValue);
237 a.append("</STRONG>");
238 return a.toString();
241 final static String FIRSTGFX_TABLETITLE = "Original print file as jpeg";
242 final static String SECONDGFX_TABLETITLE = "New print file as jpeg";
243 final static String DIFFER_TABLETITLE = "Difference file";
244 final static String STATUS_TABLETITLE = "Status";
245 final static String PIXELDIFF_TABLETITLE = "Pixel difference in %";
247 final static String PIXELDIFF_BM_TABLETITLE = "P.diff. in % after remove border";
248 final static String DIFFER_BM_TABLETITLE = "Diff file (RB)";
250 final static String OK_TABLETITLE = "OK?";
251 public void checkSection(String _sDocumentName)
255 m_aOut.write( "<H2>Results for the document " + _sDocumentName + "</H2>" + ls);
257 m_aOut.write( "<p>Legend:<br>");
258 m_aOut.write( stronghtml(FIRSTGFX_TABLETITLE) + " contains the output printed via 'ghostscript' as a jpeg picture.<br>");
259 m_aOut.write( stronghtml(SECONDGFX_TABLETITLE) + " contains the same document opened within OpenOffice.org also printed via ghostscript as jpeg.<br>");
260 m_aOut.write( stronghtml(DIFFER_TABLETITLE)+" is build via composite from original and new picture. The result should be a whole black picture, if there are no differences.<br>At the moment "+stronghtml(STATUS_TABLETITLE)+" is only ok, if the difference file contains only one color (black).</p>" );
261 m_aOut.write( stronghtml(DIFFER_BM_TABLETITLE) + " is build via composite from original and new picture after the border of both pictures are removed, so differences based on center problems may solved here");
262 m_aOut.write( "</p>");
263 m_aOut.write( "<p>Some words about the percentage value<br>");
264 m_aOut.write( "If a character is on the original page (a) and on the new page this character is moved to an other position only (b) , this means the difference is 100%.<br>");
265 m_aOut.write( "If character (b) is also bigger than character (a) the percentage is grow over the 100% mark.<br>");
266 m_aOut.write( "This tool count only the pixels which are differ to it's background color. It makes no sense to count all pixels, or the difference percentage will most the time in a very low percentage range.");
267 m_aOut.write( "</p>");
269 m_aOut.write( "<table class=\"infotable\">" + ls);
271 m_aOut.write( "<TR>" + ls);
272 m_aOut.write( tableHeaderCell( FIRSTGFX_TABLETITLE) );
273 m_aOut.write( tableHeaderCell( SECONDGFX_TABLETITLE ) );
274 m_aOut.write( tableHeaderCell(DIFFER_TABLETITLE ) );
275 m_aOut.write( tableHeaderCell(PIXELDIFF_TABLETITLE ) );
277 m_aOut.write( tableHeaderCell(DIFFER_BM_TABLETITLE) );
278 m_aOut.write( tableHeaderCell(PIXELDIFF_BM_TABLETITLE ) );
280 m_aOut.write( tableHeaderCell( OK_TABLETITLE) );
282 m_aOut.write( "</TR>" + ls);
283 m_aOut.flush();
285 catch (java.io.IOException e)
290 public void checkLine(StatusHelper _aStatus, boolean _bCurrentResult)
294 m_aOut.write( "<TR>" + ls);
295 String sLink = getHREF(FileHelper.getBasename(_aStatus.m_sOldGfx), FileHelper.getBasename(_aStatus.m_sOldGfx));
296 m_aOut.write( tableDataCell(sLink) );
298 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sNewGfx), FileHelper.getBasename(_aStatus.m_sNewGfx));
299 m_aOut.write( tableDataCell(sLink) );
301 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sDiffGfx), FileHelper.getBasename(_aStatus.m_sDiffGfx));
302 m_aOut.write( tableDataCell(sLink) );
304 String sPercent = String.valueOf(_aStatus.nPercent) + "%";
305 if (_aStatus.nPercent > 0 && _aStatus.nPercent < 5)
307 sPercent += " (less 5% is ok)";
309 m_aOut.write(tableDataCell( sPercent ) );
311 if (_aStatus.m_sDiff_BM_Gfx == null)
313 sLink = "No diffs, therefore no moves";
314 m_aOut.write( tableDataCell(sLink) );
315 m_aOut.write(tableDataCell( "" ) );
317 else
319 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sDiff_BM_Gfx), FileHelper.getBasename(_aStatus.m_sDiff_BM_Gfx));
320 m_aOut.write( tableDataCell(sLink) );
322 String sPercent2 = String.valueOf(_aStatus.nPercent2) + "%";
323 if (_aStatus.nPercent2 > 0 && _aStatus.nPercent2 < 5)
325 sPercent2 += " (less 5% is ok)";
327 m_aOut.write(tableDataCell( sPercent2 ) );
330 // is the check positiv, in a defined range
331 if (_bCurrentResult)
333 m_aOut.write(tableDataCell( "YES" ) );
335 else
337 m_aOut.write(tableDataCell( "NO" ) );
340 m_aOut.write( "</TR>" + ls);
342 catch (java.io.IOException e)
347 // -----------------------------------------------------------------------------
348 public void checkDiffDiffSection(String _sDocumentName)
352 m_aOut.write( "<H2>Results for the document " + _sDocumentName + "</H2>" + ls);
354 m_aOut.write( "<p>Legend:<br>");
355 m_aOut.write( "</p>");
357 m_aOut.write( "<table class=\"infotable\">" + ls);
359 m_aOut.write( "<TR>" + ls);
360 m_aOut.write( tableHeaderCell( "Source to actual difference" ) );
361 m_aOut.write( tableHeaderCell( "Actual difference" ) );
362 m_aOut.write( tableHeaderCell(DIFFER_TABLETITLE ) );
363 m_aOut.write( tableHeaderCell(PIXELDIFF_TABLETITLE ) );
365 m_aOut.write( tableHeaderCell( OK_TABLETITLE) );
367 m_aOut.write( "</TR>" + ls);
368 m_aOut.flush();
370 catch (java.io.IOException e)
375 public void checkDiffDiffLine(StatusHelper _aStatus, boolean _bCurrentResult)
379 m_aOut.write( "<TR>" + ls);
380 // the link to the old difference can't offer here
381 // String sLink = getHREF(FileHelper.getBasename(_aStatus.m_sOldGfx), FileHelper.getBasename(_aStatus.m_sOldGfx));
382 // m_aOut.write( tableDataCell(sLink) );
384 String sBasename = FileHelper.getBasename(m_sFilename);
385 String sNew = sBasename.substring(m_sNamePrefix.length());
387 String sLink;
388 sLink = getHREF(sNew, sNew);
389 m_aOut.write( tableDataCell(sLink) );
391 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sNewGfx), FileHelper.getBasename(_aStatus.m_sNewGfx));
392 m_aOut.write( tableDataCell(sLink) );
394 sLink = getHREF(FileHelper.getBasename(_aStatus.m_sDiffGfx), FileHelper.getBasename(_aStatus.m_sDiffGfx));
395 m_aOut.write( tableDataCell(sLink) );
397 String sPercent = String.valueOf(_aStatus.nPercent) + "%";
398 // if (_aStatus.nPercent > 0 && _aStatus.nPercent < 5)
399 // {
400 // sPercent += " (less 5% is ok)";
401 // }
402 m_aOut.write(tableDataCell( sPercent ) );
404 // is the check positiv, in a defined range
405 if (_bCurrentResult)
407 m_aOut.write(tableDataCell( "YES" ) );
409 else
411 m_aOut.write(tableDataCell( "NO" ) );
414 m_aOut.write( "</TR>" + ls);
416 catch (java.io.IOException e)