1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 ************************************************************************/
34 import java
.io
.FileWriter
;
35 import helper
.OSHelper
;
37 public class HTMLOutputter
41 String m_sNamePrefix
; // the HTML files used a suffix to build it's right name
44 * ls is the current line separator (carridge return)
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
;
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
)
65 GlobalLogWriter
.get().println("ERROR: Can't create HTML Outputter");
68 a
.m_sFilename
= sFilename
;
69 a
.m_sNamePrefix
= _sNamePrefix
;
72 public String
getFilename() {return m_sFilename
;}
74 public void header(String _sTitle
)
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
);
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
)
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
);
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=\"");
127 a
.append(_sPathInfo
);
132 // System.out.println("Windows system.");
133 //! this should be replaced by a better method
135 a
.append("<A HREF=\"");
138 a
.append(_sPathInfo
);
139 // a.append("(first)");
141 // if (_sHREF.charAt(1) == ':' && (_sHREF.charAt(0) == 'x' || _sHREF.charAt(0) == 'X'))
143 // index = _sHREF.indexOf("X:");
146 // index = _sHREF.indexOf("x:");
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);
161 // a.append("(second)");
166 // System.out.println("Path is '" + _sHREF + "'");
173 String
tableDataCell(String _sValue
)
175 StringBuffer a
= new StringBuffer();
182 String
tableHeaderCell(String _sValue
)
184 StringBuffer a
= new StringBuffer();
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
) ) );
203 m_aOut
.write(tableDataCell( "" ) );
206 m_aOut
.write( tableDataCell(_sStatusRunThrough
) );
207 m_aOut
.write( tableDataCell(_sStatusMessage
) );
208 m_aOut
.write( "</TR>" + ls
);
212 catch (java
.io
.IOException e
)
221 m_aOut
.write( "</TABLE>" + ls
);
222 m_aOut
.write( "</BODY></HTML>" + ls
);
226 catch (java
.io
.IOException e
)
231 // -----------------------------------------------------------------------------
232 String
stronghtml(String _sValue
)
234 StringBuffer a
= new StringBuffer();
235 a
.append("<STRONG>");
237 a
.append("</STRONG>");
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
);
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( "" ) );
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
333 m_aOut
.write(tableDataCell( "YES" ) );
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
);
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());
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)
400 // sPercent += " (less 5% is ok)";
402 m_aOut
.write(tableDataCell( sPercent
) );
404 // is the check positiv, in a defined range
407 m_aOut
.write(tableDataCell( "YES" ) );
411 m_aOut
.write(tableDataCell( "NO" ) );
414 m_aOut
.write( "</TR>" + ls
);
416 catch (java
.io
.IOException e
)